use crate::envelope::{decrypt_for_use, encrypt_for_storage, EnvelopeEncrypted};
use crate::error::DataError;
use crate::kms::KeyProvider;
#[derive(Debug, Clone)]
pub struct RotationPlan {
pub source_alias: String,
pub target_alias: String,
}
impl RotationPlan {
#[must_use]
pub fn new(source_alias: String, target_alias: String) -> Self {
Self {
source_alias,
target_alias,
}
}
}
pub async fn re_encrypt<P: KeyProvider>(
old_envelope: &EnvelopeEncrypted,
new_key_alias: &str,
provider: &P,
) -> Result<EnvelopeEncrypted, DataError> {
let plaintext = decrypt_for_use(old_envelope, provider).await?;
encrypt_for_storage(&plaintext, new_key_alias, provider).await
}