diff --git a/src/encryption.rs b/src/encryption.rs index e7e64ca..6a4b4a7 100644 --- a/src/encryption.rs +++ b/src/encryption.rs @@ -19,7 +19,8 @@ fn generate_aad( data_context: &[impl AsRef<[u8]>], time_period: Option, ) -> String { - let key_context_canon = canonicalize(&key_context.get_value(time_period)); + let elems = key_context.get_ctx_elems(time_period); + let key_context_canon = canonicalize(&elems); let data_context_canon = canonicalize(data_context); join_canonicalized_str(&key_context_canon, &data_context_canon) } diff --git a/src/kdf.rs b/src/kdf.rs index 72a0b04..6b7d379 100644 --- a/src/kdf.rs +++ b/src/kdf.rs @@ -17,7 +17,7 @@ impl KeyContext { self.periodicity = Some(periodicity); } - pub(crate) fn get_value(&self, time_period: Option) -> Vec> { + pub(crate) fn get_ctx_elems(&self, time_period: Option) -> Vec> { let mut ret: Vec> = self.ctx.iter().map(|s| s.as_bytes().to_vec()).collect(); if let Some(tp) = time_period { ret.push(tp.to_le_bytes().to_vec()); @@ -48,7 +48,8 @@ pub(crate) fn derive_key( ctx: &KeyContext, time_period: Option, ) -> Vec { - let key_context = canonicalize(&ctx.get_value(time_period)); + let elems = ctx.get_ctx_elems(time_period); + let key_context = canonicalize(&elems); let kdf = ikm.scheme.get_kdf(); kdf(&key_context, &ikm.content) }