[refactoring] Rename AeadCtx to AeadContext to enhance readability
Test: atest libservice_vm_requests.test
Change-Id: I8669bae45c38bf0449ff94d23a881e09a1010490
diff --git a/libs/bssl/src/aead.rs b/libs/bssl/src/aead.rs
index 74bde84..e0c9fbb 100644
--- a/libs/bssl/src/aead.rs
+++ b/libs/bssl/src/aead.rs
@@ -29,7 +29,7 @@
pub const AES_GCM_NONCE_LENGTH: usize = 12;
/// Magic value indicating that the default tag length for an AEAD should be used to
-/// initialize `AeadCtx`.
+/// initialize `AeadContext`.
const AEAD_DEFAULT_TAG_LENGTH: usize = EVP_AEAD_DEFAULT_TAG_LENGTH as usize;
/// Represents an AEAD algorithm.
@@ -65,12 +65,12 @@
}
/// Represents an AEAD algorithm configuration.
-pub struct AeadCtx {
+pub struct AeadContext {
ctx: NonNull<EVP_AEAD_CTX>,
aead: Aead,
}
-impl Drop for AeadCtx {
+impl Drop for AeadContext {
fn drop(&mut self) {
// SAFETY: It is safe because the pointer has been created with `EVP_AEAD_CTX_new`
// and isn't used after this.
@@ -78,8 +78,8 @@
}
}
-impl AeadCtx {
- /// Creates a new `AeadCtx` with the given `Aead` algorithm, `key` and `tag_len`.
+impl AeadContext {
+ /// Creates a new `AeadContext` with the given `Aead` algorithm, `key` and `tag_len`.
///
/// The default tag length will be used if `tag_len` is None.
pub fn new(aead: Aead, key: &[u8], tag_len: Option<usize>) -> Result<Self> {
@@ -158,7 +158,7 @@
out.get(0..out_len).ok_or(to_call_failed_error(ApiName::EVP_AEAD_CTX_open))
}
- /// Returns the `Aead` represented by this `AeadCtx`.
+ /// Returns the `Aead` represented by this `AeadContext`.
pub fn aead(&self) -> Aead {
self.aead
}
diff --git a/libs/bssl/src/lib.rs b/libs/bssl/src/lib.rs
index ba4ec1f..709e8ad 100644
--- a/libs/bssl/src/lib.rs
+++ b/libs/bssl/src/lib.rs
@@ -30,7 +30,7 @@
pub use bssl_avf_error::{ApiName, CipherError, Error, ReasonCode, Result};
-pub use aead::{Aead, AeadCtx, AES_GCM_NONCE_LENGTH};
+pub use aead::{Aead, AeadContext, AES_GCM_NONCE_LENGTH};
pub use cbb::CbbFixed;
pub use digest::Digester;
pub use ec_key::{EcKey, ZVec};
diff --git a/libs/bssl/tests/aead_test.rs b/libs/bssl/tests/aead_test.rs
index 8ac3f12..8bdb0e7 100644
--- a/libs/bssl/tests/aead_test.rs
+++ b/libs/bssl/tests/aead_test.rs
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-use bssl_avf::{Aead, AeadCtx, ApiName, CipherError, Error, ReasonCode, Result};
+use bssl_avf::{Aead, AeadContext, ApiName, CipherError, Error, ReasonCode, Result};
/// The following vectors are generated randomly with:
/// `hexdump -vn32 -e'32/1 "0x%02x, " 1 "\n"' /dev/urandom`
@@ -38,7 +38,7 @@
let tag_len = None;
let ad = &[];
- let aead_ctx = AeadCtx::new(Aead::aes_256_gcm(), &KEY1, tag_len)?;
+ let aead_ctx = AeadContext::new(Aead::aes_256_gcm(), &KEY1, tag_len)?;
let mut out = vec![0u8; ciphertext.len()];
let plaintext = aead_ctx.open(&ciphertext, &AES_256_GCM_NONCE1, ad, &mut out)?;
@@ -50,7 +50,7 @@
#[test]
fn aes_256_gcm_fails_to_encrypt_with_invalid_nonce() -> Result<()> {
let tag_len = None;
- let aead_ctx = AeadCtx::new(Aead::aes_256_gcm(), &KEY1, tag_len)?;
+ let aead_ctx = AeadContext::new(Aead::aes_256_gcm(), &KEY1, tag_len)?;
let nonce = &[];
let ad = &[];
let mut out = vec![0u8; MESSAGE.len() + aead_ctx.aead().max_overhead()];
@@ -71,7 +71,7 @@
let tag_len = None;
let ad = &[];
- let aead_ctx2 = AeadCtx::new(Aead::aes_256_gcm(), &KEY2, tag_len)?;
+ let aead_ctx2 = AeadContext::new(Aead::aes_256_gcm(), &KEY2, tag_len)?;
let mut plaintext = vec![0u8; ciphertext.len()];
let err = aead_ctx2.open(&ciphertext, &AES_256_GCM_NONCE1, ad, &mut plaintext).unwrap_err();
@@ -88,7 +88,7 @@
let tag_len = None;
let ad2 = &[1];
- let aead_ctx = AeadCtx::new(Aead::aes_256_gcm(), &KEY1, tag_len)?;
+ let aead_ctx = AeadContext::new(Aead::aes_256_gcm(), &KEY1, tag_len)?;
let mut plaintext = vec![0u8; ciphertext.len()];
let err = aead_ctx.open(&ciphertext, &AES_256_GCM_NONCE1, ad2, &mut plaintext).unwrap_err();
@@ -105,7 +105,7 @@
let tag_len = None;
let ad = &[];
- let aead_ctx = AeadCtx::new(Aead::aes_256_gcm(), &KEY1, tag_len)?;
+ let aead_ctx = AeadContext::new(Aead::aes_256_gcm(), &KEY1, tag_len)?;
let mut plaintext = vec![0u8; ciphertext.len()];
let err = aead_ctx.open(&ciphertext, &AES_256_GCM_NONCE2, ad, &mut plaintext).unwrap_err();
@@ -123,7 +123,7 @@
let tag_len = None;
let ad = &[];
- let aead_ctx = AeadCtx::new(Aead::aes_256_gcm(), &KEY1, tag_len)?;
+ let aead_ctx = AeadContext::new(Aead::aes_256_gcm(), &KEY1, tag_len)?;
let mut plaintext = vec![0u8; ciphertext.len()];
let err = aead_ctx.open(&ciphertext, &AES_256_GCM_NONCE1, ad, &mut plaintext).unwrap_err();
@@ -136,7 +136,7 @@
fn aes_256_gcm_encrypt(message: &[u8]) -> Result<Vec<u8>> {
let tag_len = None;
- let aead_ctx = AeadCtx::new(Aead::aes_256_gcm(), &KEY1, tag_len)?;
+ let aead_ctx = AeadContext::new(Aead::aes_256_gcm(), &KEY1, tag_len)?;
let mut out = vec![0u8; message.len() + aead_ctx.aead().max_overhead()];
assert_eq!(aead_ctx.aead().nonce_length(), AES_256_GCM_NONCE1.len());
diff --git a/service_vm/requests/src/keyblob.rs b/service_vm/requests/src/keyblob.rs
index 5558836..a714edd 100644
--- a/service_vm/requests/src/keyblob.rs
+++ b/service_vm/requests/src/keyblob.rs
@@ -17,7 +17,7 @@
use crate::cbor;
use alloc::vec;
use alloc::vec::Vec;
-use bssl_avf::{hkdf, rand_bytes, Aead, AeadCtx, Digester, AES_GCM_NONCE_LENGTH};
+use bssl_avf::{hkdf, rand_bytes, Aead, AeadContext, Digester, AES_GCM_NONCE_LENGTH};
use core::result;
use serde::{Deserialize, Serialize};
use service_vm_comm::RequestProcessingError;
@@ -89,7 +89,7 @@
let kek = hkdf::<32>(kek_secret, &kek_salt, KEK_INFO, Digester::sha512())?;
let tag_len = None;
- let aead_ctx = AeadCtx::new(Aead::aes_256_gcm(), kek.as_slice(), tag_len)?;
+ let aead_ctx = AeadContext::new(Aead::aes_256_gcm(), kek.as_slice(), tag_len)?;
let mut out = vec![0u8; private_key.len() + aead_ctx.aead().max_overhead()];
let ciphertext = aead_ctx.seal(private_key, PRIVATE_KEY_NONCE, PRIVATE_KEY_AD, &mut out)?;
@@ -101,7 +101,7 @@
let kek = hkdf::<32>(kek_secret, &self.kek_salt, KEK_INFO, Digester::sha512())?;
let mut out = Zeroizing::new(vec![0u8; self.encrypted_private_key.len()]);
let tag_len = None;
- let aead_ctx = AeadCtx::new(Aead::aes_256_gcm(), kek.as_slice(), tag_len)?;
+ let aead_ctx = AeadContext::new(Aead::aes_256_gcm(), kek.as_slice(), tag_len)?;
let plaintext = aead_ctx.open(
&self.encrypted_private_key,
PRIVATE_KEY_NONCE,