2 NNCP -- Node to Node copy, utilities for store-and-forward data exchange
3 Copyright (C) 2016-2021 Sergey Matveev <stargrave@stargrave.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, version 3 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 "lukechampine.com/blake3"
29 func TestMTHSymmetric(t *testing.T) {
30 xof := blake3.New(32, nil).XOF()
31 f := func(size uint32, offset uint32) bool {
32 size %= 2 * 1024 * 1024
33 data := make([]byte, int(size), int(size)+1)
34 if _, err := io.ReadFull(xof, data); err != nil {
37 offset = offset % size
39 mth := MTHNew(int64(size), 0)
40 if _, err := io.Copy(mth, bytes.NewReader(data)); err != nil {
45 mth = MTHNew(int64(size), int64(offset))
46 if _, err := io.Copy(mth, bytes.NewReader(data[int(offset):])); err != nil {
49 if _, err := mth.PrependFrom(bytes.NewReader(data)); err != nil {
52 if bytes.Compare(hsh0, mth.Sum(nil)) != 0 {
58 if bytes.Compare(hsh0, mth.Sum(nil)) != 0 {
62 data = append(data, 0)
63 mth = MTHNew(int64(size)+1, 0)
64 if _, err := io.Copy(mth, bytes.NewReader(data)); err != nil {
68 if bytes.Compare(hsh0, hsh00) == 0 {
72 mth = MTHNew(int64(size)+1, int64(offset))
73 if _, err := io.Copy(mth, bytes.NewReader(data[int(offset):])); err != nil {
76 if _, err := mth.PrependFrom(bytes.NewReader(data)); err != nil {
79 if bytes.Compare(hsh00, mth.Sum(nil)) != 0 {
85 if bytes.Compare(hsh00, mth.Sum(nil)) != 0 {
91 if err := quick.Check(f, nil); err != nil {
96 func TestMTHNull(t *testing.T) {
98 if _, err := mth.Write(nil); err != nil {