Switch to ? syntax in the remaining files still using try!().

This commit is contained in:
Brian Smith 2017-05-17 21:38:43 -10:00
parent 67d1712243
commit 6ab31bb8b4
6 changed files with 12 additions and 13 deletions

View File

@ -101,8 +101,8 @@ pub fn from_hex(hex_str: &str) -> Result<Vec<u8>, 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)

View File

@ -28,7 +28,7 @@ impl BitLength {
#[inline]
pub fn from_usize_bytes(bytes: usize)
-> Result<BitLength, error::Unspecified> {
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<BitLength, error::Unspecified> {
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))
}
}

View File

@ -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(())
}

View File

@ -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");

View File

@ -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() {

View File

@ -307,8 +307,8 @@ pub fn from_hex(hex_str: &str) -> Result<Vec<u8>, 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)