@@ -24,6 +24,26 @@ func TestLeafOp(t *testing.T) {
24
24
// echo -n foobar | sha256sum
25
25
expected : fromHex ("c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2" ),
26
26
},
27
+ "hash foobaz, sha-512" : {
28
+ op : & LeafOp {
29
+ Hash : HashOp_SHA512 ,
30
+ // no prehash, no length prefix
31
+ },
32
+ key : []byte ("foo" ),
33
+ value : []byte ("baz" ),
34
+ // echo -n foobaz | sha512sum
35
+ expected : fromHex ("4f79f191298ec7461d60136c60f77c2ae8ddd85dbf6168bb925092d51bfb39b559219b39ae5385ba04946c87f64741385bef90578ea6fe6dac85dbf7ad3f79e1" ),
36
+ },
37
+ "hash foobar (different break)" : {
38
+ op : & LeafOp {
39
+ Hash : HashOp_SHA256 ,
40
+ // no prehash, no length prefix
41
+ },
42
+ key : []byte ("f" ),
43
+ value : []byte ("oobar" ),
44
+ // echo -n foobar | sha256sum
45
+ expected : fromHex ("c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2" ),
46
+ },
27
47
"requires key" : {
28
48
op : & LeafOp {
29
49
Hash : HashOp_SHA256 ,
@@ -40,6 +60,33 @@ func TestLeafOp(t *testing.T) {
40
60
value : []byte ("bar" ),
41
61
isErr : true ,
42
62
},
63
+ "hash with length prefix" : {
64
+ op : & LeafOp {
65
+ Hash : HashOp_SHA256 ,
66
+ Length : LengthOp_VAR_PROTO ,
67
+ // no prehash, no length prefix
68
+ },
69
+ // echo -n food | xxs -ps
70
+ // and manually compute length byte
71
+ key : []byte ("food" ), // 04666f6f64
72
+ value : []byte ("some longer text" ), // 10736f6d65206c6f6e6765722074657874
73
+ // echo -n 04666f6f6410736f6d65206c6f6e6765722074657874 | xxd -r -p | sha256sum
74
+ expected : fromHex ("b68f5d298e915ae1753dd333da1f9cf605411a5f2e12516be6758f365e6db265" ),
75
+ },
76
+ "hash with prehash and length prefix" : {
77
+ op : & LeafOp {
78
+ Hash : HashOp_SHA256 ,
79
+ Length : LengthOp_VAR_PROTO ,
80
+ PrehashValue : HashOp_SHA256 ,
81
+ // no prehash, no length prefix
82
+ },
83
+ key : []byte ("food" ), // 04666f6f64
84
+ // TODO: this is hash, then length....
85
+ // echo -n yet another long string | sha256sum
86
+ value : []byte ("yet another long string" ), // 20a48c2d4f67b9f80374938535285ed285819d8a5a8fc1fccd1e3244e437cf290d
87
+ // echo -n 04666f6f6420a48c2d4f67b9f80374938535285ed285819d8a5a8fc1fccd1e3244e437cf290d | xxd -r -p | sha256sum
88
+ expected : fromHex ("87e0483e8fb624aef2e2f7b13f4166cda485baa8e39f437c83d74c94bedb148f" ),
89
+ },
43
90
}
44
91
45
92
for name , tc := range cases {
0 commit comments