mirror of
https://github.com/mikedilger/nip44.git
synced 2026-07-04 05:57:29 +00:00
cargo fmt
This commit is contained in:
+1
-2
@@ -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
@@ -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
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user