From 6ab31bb8b4f6688ddb8168d0eb1d06ba10343259 Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Wed, 17 May 2017 21:38:43 -1000 Subject: [PATCH] Switch to `?` syntax in the remaining files still using `try!()`. --- examples/checkdigest.rs | 4 ++-- src/bits.rs | 4 ++-- src/digest/digest.rs | 4 ++-- src/hkdf.rs | 3 +-- src/hmac.rs | 6 +++--- src/test.rs | 4 ++-- 6 files changed, 12 insertions(+), 13 deletions(-) diff --git a/examples/checkdigest.rs b/examples/checkdigest.rs index ea08ee999..b8ac0f7c0 100644 --- a/examples/checkdigest.rs +++ b/examples/checkdigest.rs @@ -101,8 +101,8 @@ pub fn from_hex(hex_str: &str) -> Result, String> { let mut result = Vec::with_capacity(hex_str.len() / 2); for digits in hex_str.as_bytes().chunks(2) { - let hi = try!(from_hex_digit(digits[0])); - let lo = try!(from_hex_digit(digits[1])); + let hi = from_hex_digit(digits[0])?; + let lo = from_hex_digit(digits[1])?; result.push((hi * 0x10) | lo); } Ok(result) diff --git a/src/bits.rs b/src/bits.rs index 42c8814a4..938e234cc 100644 --- a/src/bits.rs +++ b/src/bits.rs @@ -28,7 +28,7 @@ impl BitLength { #[inline] pub fn from_usize_bytes(bytes: usize) -> Result { - let bits = try!(bytes.checked_mul(8).ok_or(error::Unspecified)); + let bits = bytes.checked_mul(8).ok_or(error::Unspecified)?; Ok(BitLength::from_usize_bits(bits)) } @@ -55,7 +55,7 @@ impl BitLength { #[inline] pub fn try_sub(self, other: BitLength) -> Result { - let sum = try!(self.0.checked_sub(other.0).ok_or(error::Unspecified)); + let sum = self.0.checked_sub(other.0).ok_or(error::Unspecified)?; Ok(BitLength(sum)) } } diff --git a/src/digest/digest.rs b/src/digest/digest.rs index fb0bd221c..500d3861c 100644 --- a/src/digest/digest.rs +++ b/src/digest/digest.rs @@ -261,9 +261,9 @@ impl AsRef<[u8]> for Digest { impl core::fmt::Debug for Digest { fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result { - try!(write!(fmt, "{:?}:", self.algorithm)); + write!(fmt, "{:?}:", self.algorithm)?; for byte in self.as_ref() { - try!(write!(fmt, "{:02x}", byte)); + write!(fmt, "{:02x}", byte)?; } Ok(()) } diff --git a/src/hkdf.rs b/src/hkdf.rs index 4603e3ca5..8094a26dc 100644 --- a/src/hkdf.rs +++ b/src/hkdf.rs @@ -140,8 +140,7 @@ mod tests { test::from_file("src/hkdf_tests.txt", |section, test_case| { assert_eq!(section, ""); let digest_alg = - try!(test_case.consume_digest_alg("Hash") - .ok_or(error::Unspecified)); + test_case.consume_digest_alg("Hash").ok_or(error::Unspecified)?; let secret = test_case.consume_bytes("IKM"); let salt = test_case.consume_bytes("salt"); let info = test_case.consume_bytes("info"); diff --git a/src/hmac.rs b/src/hmac.rs index c548299e5..2ed9fd4d4 100644 --- a/src/hmac.rs +++ b/src/hmac.rs @@ -203,7 +203,7 @@ impl SigningKey { if key_bytes.len() != recommended_key_len(digest_alg) { return Err(error::Unspecified); } - try!(rng.fill(key_bytes)); + rng.fill(key_bytes)?; Ok(SigningKey::new(digest_alg, key_bytes)) } @@ -495,8 +495,8 @@ mod tests { None => { return Ok(()); }, // Unsupported digest algorithm }; - try!(hmac_test_case_inner(digest_alg, &key_value[..], &input[..], - &output[..], true)); + hmac_test_case_inner(digest_alg, &key_value[..], &input[..], + &output[..], true)?; // Tamper with the input and check that verification fails. if input.is_empty() { diff --git a/src/test.rs b/src/test.rs index a73a71fb2..7852c0bbc 100644 --- a/src/test.rs +++ b/src/test.rs @@ -307,8 +307,8 @@ pub fn from_hex(hex_str: &str) -> Result, String> { let mut result = Vec::with_capacity(hex_str.len() / 2); for digits in hex_str.as_bytes().chunks(2) { - let hi = try!(from_hex_digit(digits[0])); - let lo = try!(from_hex_digit(digits[1])); + let hi = from_hex_digit(digits[0])?; + let lo = from_hex_digit(digits[1])?; result.push((hi * 0x10) | lo); } Ok(result)