fmt
This commit is contained in:
parent
f2bb938fa4
commit
de14367ce0
@ -121,7 +121,7 @@ impl Aes256Decryption {
|
||||
Purpose::Login => {
|
||||
let half_key = self.decrypt_login()?;
|
||||
Ok(half_key.to_inner())
|
||||
},
|
||||
}
|
||||
Purpose::ThirtyTwoBytes => {
|
||||
let thirty_two_buf = self.decrypt_thirty_two()?;
|
||||
Ok(thirty_two_buf.to_vec())
|
||||
@ -225,7 +225,7 @@ impl Aes256Encryption {
|
||||
pub fn encrypt_with_aes_key(&self) -> Result<CipherText> {
|
||||
match self.purpose {
|
||||
Purpose::Login => self.encrypt_login(),
|
||||
Purpose::ThirtyTwoBytes => self.encrypt_thirty_two()
|
||||
Purpose::ThirtyTwoBytes => self.encrypt_thirty_two(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -252,6 +252,7 @@ impl Aes256Encryption {
|
||||
.encrypt(&self.nonce.into(), thirty_two.as_slice())
|
||||
.map_err(|e| Error::msg(format!("{}", e)))?;
|
||||
let mut res = Vec::with_capacity(self.nonce.len() + cipher_text.len());
|
||||
log::info!("{}", cipher_text.len());
|
||||
res.extend_from_slice(&self.nonce);
|
||||
res.extend_from_slice(&cipher_text);
|
||||
Ok(res)
|
||||
@ -267,8 +268,10 @@ mod tests {
|
||||
const ALICE_SP_ADDRESS: &str = "tsp1qqw3lqr6xravz9nf8ntazgwwl0fqv47kfjdxsnxs6eutavqfwyv5q6qk97mmyf6dtkdyzqlu2zv6h9j2ggclk7vn705q5u2phglpq7yw3dg5rwpdz";
|
||||
const BOB_SP_ADDRESS: &str = "tsp1qq2hlsgrj0gz8kcfkf9flqw5llz0u2vr04telqndku9mcqm6dl4fhvq60t8r78srrf56w9yr7w9e9dusc2wjqc30up6fjwnh9mw3e3veqegdmtf08";
|
||||
const TRANSACTION: &str = "4e6d03dec558e1b6624f813bf2da7cd8d8fb1c2296684c08cf38724dcfd8d10b";
|
||||
const ALICE_SHARED_SECRET: &str = "ccf02d364c2641ca129a3fdf49de57b705896e233f7ba6d738991993ea7e2106";
|
||||
const BOB_SHARED_SECRET: &str = "15ef3e377fb842e81de52dbaaea8ba30aeb051a81043ee19264afd27353da521";
|
||||
const ALICE_SHARED_SECRET: &str =
|
||||
"ccf02d364c2641ca129a3fdf49de57b705896e233f7ba6d738991993ea7e2106";
|
||||
const BOB_SHARED_SECRET: &str =
|
||||
"15ef3e377fb842e81de52dbaaea8ba30aeb051a81043ee19264afd27353da521";
|
||||
|
||||
#[test]
|
||||
fn new_aes_empty_plaintext() {
|
||||
@ -304,7 +307,12 @@ mod tests {
|
||||
let plaintext = [1u8; HALFKEYSIZE];
|
||||
let aes_key = Aes256Gcm::generate_key(&mut thread_rng());
|
||||
let nonce = Aes256Gcm::generate_nonce(&mut thread_rng());
|
||||
let aes_enc = Aes256Encryption::import_key(Purpose::Login, plaintext.to_vec(), aes_key.into(), nonce.into());
|
||||
let aes_enc = Aes256Encryption::import_key(
|
||||
Purpose::Login,
|
||||
plaintext.to_vec(),
|
||||
aes_key.into(),
|
||||
nonce.into(),
|
||||
);
|
||||
|
||||
assert!(aes_enc.is_ok());
|
||||
|
||||
@ -315,7 +323,8 @@ mod tests {
|
||||
let mut plain_key = [0u8; 32];
|
||||
plain_key.copy_from_slice(&aes_key.to_vec());
|
||||
|
||||
let aes_dec = Aes256Decryption::new(Purpose::Login, cipher.unwrap(), plain_key.to_vec(), None);
|
||||
let aes_dec =
|
||||
Aes256Decryption::new(Purpose::Login, cipher.unwrap(), plain_key.to_vec(), None);
|
||||
|
||||
assert!(aes_dec.is_ok());
|
||||
}
|
||||
@ -370,8 +379,9 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn aes_encrypt_key_many() {
|
||||
let plaintext = [1u8; HALFKEYSIZE];
|
||||
let mut aes_enc = Aes256Encryption::new(Purpose::Login, plaintext.to_vec()).unwrap();
|
||||
let plaintext = [1u8; THIRTYTWO];
|
||||
let mut aes_enc =
|
||||
Aes256Encryption::new(Purpose::ThirtyTwoBytes, plaintext.to_vec()).unwrap();
|
||||
|
||||
let mut shared_secrets: HashMap<Txid, _> = HashMap::new();
|
||||
let mut sp_address2shared_secrets: HashMap<SilentPaymentAddress, SharedSecret> =
|
||||
@ -396,28 +406,23 @@ mod tests {
|
||||
assert!(sp_address2encrypted_keys.is_ok());
|
||||
|
||||
// Alice
|
||||
let encrypted_key = sp_address2encrypted_keys.as_mut()
|
||||
let encrypted_key = sp_address2encrypted_keys
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.get(&ALICE_SP_ADDRESS.try_into().unwrap())
|
||||
.cloned();
|
||||
|
||||
let ciphertext = aes_enc.encrypt_with_aes_key();
|
||||
|
||||
assert!(ciphertext.is_ok());
|
||||
|
||||
let aes_dec = Aes256Decryption::new(
|
||||
Purpose::Login,
|
||||
Purpose::ThirtyTwoBytes,
|
||||
ciphertext.unwrap(),
|
||||
encrypted_key.unwrap(),
|
||||
Some(SharedSecret::from_str(ALICE_SHARED_SECRET).unwrap()),
|
||||
);
|
||||
|
||||
assert!(aes_dec.is_ok());
|
||||
|
||||
let retrieved_plain = aes_dec.unwrap().decrypt_with_key();
|
||||
|
||||
assert!(retrieved_plain.is_ok());
|
||||
|
||||
assert!(retrieved_plain.unwrap() == plaintext);
|
||||
|
||||
// Bob
|
||||
@ -428,21 +433,15 @@ mod tests {
|
||||
|
||||
let ciphertext = aes_enc.encrypt_with_aes_key();
|
||||
|
||||
assert!(ciphertext.is_ok());
|
||||
|
||||
let aes_dec = Aes256Decryption::new(
|
||||
Purpose::Login,
|
||||
Purpose::ThirtyTwoBytes,
|
||||
ciphertext.unwrap(),
|
||||
encrypted_key.unwrap(),
|
||||
Some(SharedSecret::from_str(BOB_SHARED_SECRET).unwrap()),
|
||||
);
|
||||
|
||||
assert!(aes_dec.is_ok());
|
||||
|
||||
let retrieved_plain = aes_dec.unwrap().decrypt_with_key();
|
||||
|
||||
assert!(retrieved_plain.is_ok());
|
||||
|
||||
assert!(retrieved_plain.unwrap() == plaintext);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user