2 NNCP -- Node to Node copy, utilities for store-and-forward data exchange
3 Copyright (C) 2016-2022 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 TestMTHSeqSymmetric(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 := MTHSeqNew(int64(size), 0)
40 if _, err := io.Copy(mth, bytes.NewReader(data)); err != nil {
45 mth = MTHSeqNew(int64(size), int64(offset))
46 if _, err := io.Copy(mth, bytes.NewReader(data[int(offset):])); err != nil {
49 if _, err := mth.PreaddFrom(bytes.NewReader(data), "", false); 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 = MTHSeqNew(int64(size)+1, 0)
64 if _, err := io.Copy(mth, bytes.NewReader(data)); err != nil {
68 if bytes.Compare(hsh0, hsh00) == 0 {
72 mth = MTHSeqNew(int64(size)+1, int64(offset))
73 if _, err := io.Copy(mth, bytes.NewReader(data[int(offset):])); err != nil {
76 if _, err := mth.PreaddFrom(bytes.NewReader(data), "", false); 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 TestMTHSeqAndFatEqual(t *testing.T) {
97 xof := blake3.New(32, nil).XOF()
98 f := func(size uint32, offset uint32) bool {
99 size %= 10 * 1024 * 1024
100 data := make([]byte, int(size), int(size)+1)
101 if _, err := io.ReadFull(xof, data); err != nil {
105 if _, err := io.Copy(fat, bytes.NewReader(data)); err != nil {
108 hshFat := fat.Sum(nil)
109 seq := MTHSeqNew(int64(size), 0)
110 if _, err := io.Copy(seq, bytes.NewReader(data)); err != nil {
113 return bytes.Compare(hshFat, seq.Sum(nil)) == 0
115 if err := quick.Check(f, nil); err != nil {
120 func TestMTHNull(t *testing.T) {
122 if _, err := fat.Write(nil); err != nil {
125 hshFat := fat.Sum(nil)
127 seq := MTHSeqNew(0, 0)
128 if _, err := seq.Write(nil); err != nil {
131 if bytes.Compare(hshFat, seq.Sum(nil)) != 0 {