mirror of
https://github.com/signalapp/libsignal.git
synced 2024-09-20 03:52:17 +02:00
Make HMAC and hash algorithm methods infallible
Remove the Result types from the Rust functions that only every return Ok. Unwrap Result<T> return types for bridge functions that only ever return Ok.
This commit is contained in:
parent
483d220aba
commit
319f3e58b0
@ -211,7 +211,7 @@ fn CryptographicHash_New(algo: String) -> Result<CryptographicHash> {
|
||||
}
|
||||
|
||||
#[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<Vec<u8>> {
|
||||
fn CryptographicHash_Finalize(hash: &mut CryptographicHash) -> Vec<u8> {
|
||||
hash.finalize()
|
||||
}
|
||||
|
||||
@ -238,7 +238,7 @@ fn CryptographicMac_New(algo: String, key: &[u8]) -> Result<CryptographicMac> {
|
||||
}
|
||||
|
||||
#[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<Vec<u8>> {
|
||||
fn CryptographicMac_Finalize(mac: &mut CryptographicMac) -> Vec<u8> {
|
||||
mac.finalize()
|
||||
}
|
||||
|
@ -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<Vec<u8>> {
|
||||
Ok(match self {
|
||||
pub fn finalize(&mut self) -> Vec<u8> {
|
||||
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<Vec<u8>> {
|
||||
Ok(match self {
|
||||
pub fn finalize(&mut self) -> Vec<u8> {
|
||||
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(),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user