diff --git a/rust/bridge/shared/src/crypto.rs b/rust/bridge/shared/src/crypto.rs index a3d245d1..00f55017 100644 --- a/rust/bridge/shared/src/crypto.rs +++ b/rust/bridge/shared/src/crypto.rs @@ -211,7 +211,7 @@ fn CryptographicHash_New(algo: String) -> Result { } #[bridge_fn_void(ffi = false, node = false)] -fn CryptographicHash_Update(hash: &mut CryptographicHash, input: &[u8]) -> Result<()> { +fn CryptographicHash_Update(hash: &mut CryptographicHash, input: &[u8]) { hash.update(input) } @@ -221,14 +221,14 @@ fn CryptographicHash_UpdateWithOffset( input: &[u8], offset: u32, len: u32, -) -> Result<()> { +) { let offset = offset as usize; let len = len as usize; hash.update(&input[offset..(offset + len)]) } #[bridge_fn(ffi = false, node = false)] -fn CryptographicHash_Finalize(hash: &mut CryptographicHash) -> Result> { +fn CryptographicHash_Finalize(hash: &mut CryptographicHash) -> Vec { hash.finalize() } @@ -238,7 +238,7 @@ fn CryptographicMac_New(algo: String, key: &[u8]) -> Result { } #[bridge_fn_void(ffi = false, node = false)] -fn CryptographicMac_Update(mac: &mut CryptographicMac, input: &[u8]) -> Result<()> { +fn CryptographicMac_Update(mac: &mut CryptographicMac, input: &[u8]) { mac.update(input) } @@ -248,13 +248,13 @@ fn CryptographicMac_UpdateWithOffset( input: &[u8], offset: u32, len: u32, -) -> Result<()> { +) { let offset = offset as usize; let len = len as usize; mac.update(&input[offset..(offset + len)]) } #[bridge_fn(ffi = false, node = false)] -fn CryptographicMac_Finalize(mac: &mut CryptographicMac) -> Result> { +fn CryptographicMac_Finalize(mac: &mut CryptographicMac) -> Vec { mac.finalize() } diff --git a/rust/crypto/src/hash.rs b/rust/crypto/src/hash.rs index 571ec229..f45e534b 100644 --- a/rust/crypto/src/hash.rs +++ b/rust/crypto/src/hash.rs @@ -28,23 +28,23 @@ impl CryptographicMac { } } - pub fn update(&mut self, input: &[u8]) -> Result<()> { + pub fn update(&mut self, input: &[u8]) { match self { Self::HmacSha1(sha1) => sha1.update(input), Self::HmacSha256(sha256) => sha256.update(input), } - Ok(()) } - pub fn update_and_get(&mut self, input: &[u8]) -> Result<&mut Self> { - self.update(input).map(|_| self) + pub fn update_and_get(&mut self, input: &[u8]) -> &mut Self { + self.update(input); + self } - pub fn finalize(&mut self) -> Result> { - Ok(match self { + pub fn finalize(&mut self) -> Vec { + match self { Self::HmacSha1(sha1) => sha1.finalize_reset().into_bytes().to_vec(), Self::HmacSha256(sha256) => sha256.finalize_reset().into_bytes().to_vec(), - }) + } } } @@ -65,20 +65,19 @@ impl CryptographicHash { } } - pub fn update(&mut self, input: &[u8]) -> Result<()> { + pub fn update(&mut self, input: &[u8]) { match self { Self::Sha1(sha1) => sha1.update(input), Self::Sha256(sha256) => sha256.update(input), Self::Sha512(sha512) => sha512.update(input), } - Ok(()) } - pub fn finalize(&mut self) -> Result> { - Ok(match self { + pub fn finalize(&mut self) -> Vec { + match self { Self::Sha1(sha1) => sha1.finalize_reset().to_vec(), Self::Sha256(sha256) => sha256.finalize_reset().to_vec(), Self::Sha512(sha512) => sha512.finalize_reset().to_vec(), - }) + } } }