diff --git a/crates/scryptenc/src/error.rs b/crates/scryptenc/src/error.rs index 8bf9c06..99e9b7b 100644 --- a/crates/scryptenc/src/error.rs +++ b/crates/scryptenc/src/error.rs @@ -62,6 +62,12 @@ impl std::error::Error for Error { } } +impl From for Error { + fn from(err: InvalidParams) -> Self { + Self::InvalidParams(err) + } +} + /// A specialized [`Result`](result::Result) type for read and write operations /// for the scrypt encrypted data format. /// @@ -340,6 +346,14 @@ mod tests { .is::()); } + #[test] + fn from_invalid_params_to_error() { + assert_eq!( + Error::from(InvalidParams), + Error::InvalidParams(InvalidParams) + ); + } + #[test] fn result_type() { use core::any; diff --git a/crates/scryptenc/src/format.rs b/crates/scryptenc/src/format.rs index 1240e47..e7b3b99 100644 --- a/crates/scryptenc/src/format.rs +++ b/crates/scryptenc/src/format.rs @@ -133,9 +133,8 @@ impl Header { .try_into() .expect("size of `p` parameter should be 4 bytes"), ); - let params = scrypt::Params::new(log_n, r, p, scrypt::Params::RECOMMENDED_LEN) - .map(Params::from) - .map_err(Error::InvalidParams)?; + let params = + scrypt::Params::new(log_n, r, p, scrypt::Params::RECOMMENDED_LEN).map(Params::from)?; let salt = data[16..48] .try_into() .expect("size of salt should be 32 bytes"); diff --git a/crates/scryptenc/tests/decrypt.rs b/crates/scryptenc/tests/decrypt.rs index 2f0ba31..59d70d3 100644 --- a/crates/scryptenc/tests/decrypt.rs +++ b/crates/scryptenc/tests/decrypt.rs @@ -87,19 +87,19 @@ fn invalid_params() { { data[7] = 65; let err = Decryptor::new(&data, PASSPHRASE).unwrap_err(); - assert_eq!(err, Error::InvalidParams(InvalidParams)); + assert_eq!(err, InvalidParams.into()); } { data[8..12].copy_from_slice(&u32::to_be_bytes(0)); let err = Decryptor::new(&data, PASSPHRASE).unwrap_err(); - assert_eq!(err, Error::InvalidParams(InvalidParams)); + assert_eq!(err, InvalidParams.into()); } { data[12..16].copy_from_slice(&u32::to_be_bytes(0)); let err = Decryptor::new(&data, PASSPHRASE).unwrap_err(); - assert_eq!(err, Error::InvalidParams(InvalidParams)); + assert_eq!(err, InvalidParams.into()); } }