diff --git a/derive/src/multihash.rs b/derive/src/multihash.rs index 0b23c97f..3e6f6e86 100644 --- a/derive/src/multihash.rs +++ b/derive/src/multihash.rs @@ -232,8 +232,8 @@ pub fn multihash(s: Structure) -> TokenStream { } } - fn wrap(&self, digest: &[u8]) -> Multihash { - Multihash::wrap((*self).into(), digest).unwrap() + fn wrap(&self, digest: &[u8]) -> Result { + Multihash::wrap((*self).into(), digest) } } @@ -298,8 +298,8 @@ mod tests { } } - fn wrap(&self, digest: &[u8]) -> Multihash { - Multihash::wrap((*self).into(), digest).unwrap() + fn wrap(&self, digest: &[u8]) -> Result { + Multihash::wrap((*self).into(), digest) } } diff --git a/src/multihash.rs b/src/multihash.rs index c679c4a5..9f759c66 100644 --- a/src/multihash.rs +++ b/src/multihash.rs @@ -49,7 +49,7 @@ pub trait MultihashDigest: /// let hash = Code::Sha3_256.wrap(&hasher.finalize()); /// println!("{:02x?}", hash); /// ``` - fn wrap(&self, digest: &[u8]) -> Multihash; + fn wrap(&self, digest: &[u8]) -> Result, Error>; } /// A Multihash instance that only supports the basic functionality and no hashing. diff --git a/src/multihash_impl.rs b/src/multihash_impl.rs index 61f8af91..7350c4f0 100644 --- a/src/multihash_impl.rs +++ b/src/multihash_impl.rs @@ -89,7 +89,7 @@ mod tests { let mut hasher = Sha3_256::default(); hasher.update(b"hello world"); let digest = hasher.finalize(); - let hash = Code::Sha3_256.wrap(digest); + let hash = Code::Sha3_256.wrap(digest).unwrap(); let hash2 = Code::Sha3_256.digest(b"hello world"); assert_eq!(hash.code(), u64::from(Code::Sha3_256)); assert_eq!(hash.size(), 32); @@ -102,7 +102,7 @@ mod tests { let mut hasher = Sha3_512::default(); hasher.update(b"hello world"); let digest = hasher.finalize(); - let hash = Code::Sha3_512.wrap(digest); + let hash = Code::Sha3_512.wrap(digest).unwrap(); let hash2 = Code::Sha3_512.digest(b"hello world"); assert_eq!(hash.code(), u64::from(Code::Sha3_512)); assert_eq!(hash.size(), 64); diff --git a/tests/lib.rs b/tests/lib.rs index e36ea346..3fdcba3b 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -66,7 +66,7 @@ macro_rules! assert_encode { let mut hasher = <$alg>::default(); hasher.update($data); assert_eq!( - $code.wrap(hasher.finalize()).to_bytes(), + $code.wrap(hasher.finalize()).unwrap().to_bytes(), expected, "{:?} encodes correctly (from hasher)", stringify!($alg) ); @@ -151,7 +151,7 @@ macro_rules! assert_roundtrip { { let mut hasher = <$alg>::default(); hasher.update(b"helloworld"); - let hash = $code.wrap(hasher.finalize()); + let hash = $code.wrap(hasher.finalize()).unwrap(); assert_eq!( Multihash::from_bytes(&hash.to_bytes()).unwrap().code(), hash.code() @@ -161,7 +161,7 @@ macro_rules! assert_roundtrip { { let mut hasher = <$alg>::default(); hasher.write_all(b"helloworld").unwrap(); - let hash = $code.wrap(hasher.finalize()); + let hash = $code.wrap(hasher.finalize()).unwrap(); assert_eq!( Multihash::from_bytes(&hash.to_bytes()).unwrap().code(), hash.code() @@ -217,7 +217,7 @@ where // Test from hasher digest conversion let mut hasher = H::default(); hasher.update(b"hello world"); - let multihash_from_digest = code.wrap(hasher.finalize()); + let multihash_from_digest = code.wrap(hasher.finalize()).unwrap(); assert_eq!(multihash_from_digest.code(), u64::from(code)); assert_eq!(multihash_from_digest.size() as usize, digest.len()); assert_eq!(multihash_from_digest.digest(), digest);