Remove comments that went too obvious after refactoring the parts they were commenting
This commit is contained in:
parent
85d0ee7e31
commit
382492e915
1 changed files with 0 additions and 19 deletions
|
@ -26,18 +26,11 @@ pub fn encrypt(
|
||||||
data: impl AsRef<[u8]>,
|
data: impl AsRef<[u8]>,
|
||||||
data_context: &[impl AsRef<[u8]>],
|
data_context: &[impl AsRef<[u8]>],
|
||||||
) -> Result<String> {
|
) -> Result<String> {
|
||||||
// Derive the key
|
|
||||||
let ikm = ikml.get_latest_ikm()?;
|
let ikm = ikml.get_latest_ikm()?;
|
||||||
let key = derive_key(ikm, key_context);
|
let key = derive_key(ikm, key_context);
|
||||||
|
|
||||||
// Generate the AAD
|
|
||||||
let aad = generate_aad(key_context, data_context);
|
let aad = generate_aad(key_context, data_context);
|
||||||
|
|
||||||
// Encrypt
|
|
||||||
let encryption_function = ikm.scheme.get_encryption();
|
let encryption_function = ikm.scheme.get_encryption();
|
||||||
let encrypted_data = encryption_function(&key, data.as_ref(), &aad)?;
|
let encrypted_data = encryption_function(&key, data.as_ref(), &aad)?;
|
||||||
|
|
||||||
// Encode
|
|
||||||
Ok(storage::encode(ikm.id, &encrypted_data))
|
Ok(storage::encode(ikm.id, &encrypted_data))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,17 +70,10 @@ pub fn decrypt(
|
||||||
stored_data: &str,
|
stored_data: &str,
|
||||||
data_context: &[impl AsRef<[u8]>],
|
data_context: &[impl AsRef<[u8]>],
|
||||||
) -> Result<Vec<u8>> {
|
) -> Result<Vec<u8>> {
|
||||||
// Retreive the IKM and the encrypted data
|
|
||||||
let (ikm_id, encrypted_data) = storage::decode(stored_data)?;
|
let (ikm_id, encrypted_data) = storage::decode(stored_data)?;
|
||||||
let ikm = ikml.get_ikm_by_id(ikm_id)?;
|
let ikm = ikml.get_ikm_by_id(ikm_id)?;
|
||||||
|
|
||||||
// Derive the key
|
|
||||||
let key = derive_key(ikm, key_context);
|
let key = derive_key(ikm, key_context);
|
||||||
|
|
||||||
// Generate the AAD
|
|
||||||
let aad = generate_aad(key_context, data_context);
|
let aad = generate_aad(key_context, data_context);
|
||||||
|
|
||||||
// Decrypt
|
|
||||||
let decryption_function = ikm.scheme.get_decryption();
|
let decryption_function = ikm.scheme.get_decryption();
|
||||||
decryption_function(&key, &encrypted_data, &aad)
|
decryption_function(&key, &encrypted_data, &aad)
|
||||||
}
|
}
|
||||||
|
@ -97,17 +83,12 @@ pub(crate) fn xchacha20poly1305_decrypt(
|
||||||
encrypted_data: &EncryptedData,
|
encrypted_data: &EncryptedData,
|
||||||
aad: &str,
|
aad: &str,
|
||||||
) -> Result<Vec<u8>> {
|
) -> Result<Vec<u8>> {
|
||||||
// Adapt the key and the nonce
|
|
||||||
let key = Key::from_slice(key);
|
let key = Key::from_slice(key);
|
||||||
let nonce = XNonce::from_slice(&encrypted_data.nonce);
|
let nonce = XNonce::from_slice(&encrypted_data.nonce);
|
||||||
|
|
||||||
// Prepare the payload
|
|
||||||
let payload = Payload {
|
let payload = Payload {
|
||||||
msg: &encrypted_data.ciphertext,
|
msg: &encrypted_data.ciphertext,
|
||||||
aad: aad.as_bytes(),
|
aad: aad.as_bytes(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Decrypt the payload
|
|
||||||
let cipher = XChaCha20Poly1305::new(key);
|
let cipher = XChaCha20Poly1305::new(key);
|
||||||
Ok(cipher.decrypt(nonce, payload)?)
|
Ok(cipher.decrypt(nonce, payload)?)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue