cargo fmt

This commit is contained in:
Mike Dilger
2023-12-09 09:39:22 +13:00
parent e38717f86c
commit 726ed0521c
3 changed files with 8 additions and 11 deletions
+1 -2
View File
@@ -1,4 +1,3 @@
use thiserror::Error;
#[derive(Clone, Error, Debug, PartialEq)]
@@ -41,5 +40,5 @@ pub enum Error {
// UTF8 Decode
#[error("UTF8 Decode: {0}")]
Utf8Decode(#[from] std::string::FromUtf8Error)
Utf8Decode(#[from] std::string::FromUtf8Error),
}
+2 -8
View File
@@ -51,10 +51,7 @@ pub fn get_conversation_key(
ssp.try_into().unwrap()
}
fn get_message_keys(
conversation_key: &[u8; 32],
salt: &[u8; 32],
) -> Result<MessageKeys, Error> {
fn get_message_keys(conversation_key: &[u8; 32], salt: &[u8; 32]) -> Result<MessageKeys, Error> {
let hk = Hkdf::<Sha256>::new(Some(&salt[..]), conversation_key);
let mut message_keys: MessageKeys = MessageKeys::zero();
if let Err(_) = hk.expand("nip44-v2".as_bytes(), &mut message_keys.0) {
@@ -130,10 +127,7 @@ fn encrypt_inner(
}
/// Decrypt the base64 encrypted contents with a conversation key
pub fn decrypt(
conversation_key: &[u8; 32],
base64_ciphertext: &str,
) -> Result<String, Error> {
pub fn decrypt(conversation_key: &[u8; 32], base64_ciphertext: &str) -> Result<String, Error> {
if base64_ciphertext.as_bytes()[0] == b'#' {
return Err(Error::UnsupportedFutureVersion);
}
+5 -1
View File
@@ -328,7 +328,11 @@ pub fn test_invalid_pub_test_vectors() {
// Test decryption fails
let result = decrypt(&conversation_key, &vector.ciphertext);
assert!(result.is_err(), "Should not have decrypted: {}", vector.note);
assert!(
result.is_err(),
"Should not have decrypted: {}",
vector.note
);
let err = result.unwrap_err();
assert_eq!(err, vector.error, "Plaintext was {}", vector.plaintext);
}