@@ -26,6 +26,7 @@ macro_rules! assert_encode {
26
26
#[ test]
27
27
fn multihash_encode ( ) {
28
28
assert_encode ! {
29
+ Identity , b"beep boop" , "00096265657020626f6f70" ;
29
30
SHA1 , b"beep boop" , "11147c8357577f51d4f0a8d393aa1aaafb28863d9421" ;
30
31
SHA2256 , b"helloworld" , "1220936a185caaa266bb9cbe981e9e05cb78cd732b0b3280eb944412bb6f8f8f07af" ;
31
32
SHA2256 , b"beep boop" , "122090ea688e275d580567325032492b597bc77221c62493e76330b85ddda191ef7c" ;
@@ -59,6 +60,7 @@ macro_rules! assert_decode {
59
60
#[ test]
60
61
fn assert_decode ( ) {
61
62
assert_decode ! {
63
+ Identity , "000a68656c6c6f776f726c64" ;
62
64
SHA1 , "11147c8357577f51d4f0a8d393aa1aaafb28863d9421" ;
63
65
SHA2256 , "1220936a185caaa266bb9cbe981e9e05cb78cd732b0b3280eb944412bb6f8f8f07af" ;
64
66
SHA2256 , "122090ea688e275d580567325032492b597bc77221c62493e76330b85ddda191ef7c" ;
@@ -93,7 +95,7 @@ macro_rules! assert_roundtrip {
93
95
#[ test]
94
96
fn assert_roundtrip ( ) {
95
97
assert_roundtrip ! (
96
- SHA1 , SHA2256 , SHA2512 , SHA3224 , SHA3256 , SHA3384 , SHA3512 , Keccak224 , Keccak256 ,
98
+ Identity , SHA1 , SHA2256 , SHA2512 , SHA3224 , SHA3256 , SHA3384 , SHA3512 , Keccak224 , Keccak256 ,
97
99
Keccak384 , Keccak512 , Blake2b512 , Blake2s256
98
100
) ;
99
101
}
@@ -147,6 +149,7 @@ fn test_methods(hash: Hash, prefix: &str, digest: &str) {
147
149
148
150
#[ test]
149
151
fn multihash_methods ( ) {
152
+ test_methods ( Hash :: Identity , "000b" , "68656c6c6f20776f726c64" ) ;
150
153
test_methods (
151
154
Hash :: SHA1 ,
152
155
"1114" ,
@@ -226,6 +229,12 @@ fn multihash_errors() {
226
229
Multihash :: from_bytes( vec![ 0x12 , 0x20 , 0xff ] ) . is_err( ) ,
227
230
"Should error on correct prefix with wrong digest"
228
231
) ;
232
+ let identity_code = Hash :: Identity . code ( ) as u8 ;
233
+ let identity_length = 3 ;
234
+ assert ! (
235
+ Multihash :: from_bytes( vec![ identity_code, identity_length, 1 , 2 , 3 , 4 ] ) . is_err( ) ,
236
+ "Should error on wrong hash length"
237
+ ) ;
229
238
}
230
239
231
240
#[ test]
@@ -246,4 +255,10 @@ fn multihash_ref_errors() {
246
255
MultihashRef :: from_slice( & [ 0x12 , 0x20 , 0xff ] ) . is_err( ) ,
247
256
"Should error on correct prefix with wrong digest"
248
257
) ;
258
+ let identity_code = Hash :: Identity . code ( ) as u8 ;
259
+ let identity_length = 3 ;
260
+ assert ! (
261
+ MultihashRef :: from_slice( & [ identity_code, identity_length, 1 , 2 , 3 , 4 ] ) . is_err( ) ,
262
+ "Should error on wrong hash length"
263
+ ) ;
249
264
}
0 commit comments