use std::sync::Mutex;
use crate::error::AppError;
use super::{BoxFuture, SeedStore};
pub struct KmsTeeSeedStore {
seed: Mutex<Option<Vec<u8>>>,
_key_arn: String,
_region: String,
}
impl KmsTeeSeedStore {
pub fn new(seed: Vec<u8>, key_arn: String, region: String) -> Self {
Self {
seed: Mutex::new(Some(seed)),
_key_arn: key_arn,
_region: region,
}
}
}
impl SeedStore for KmsTeeSeedStore {
fn get(&self) -> BoxFuture<'_, Result<Option<Vec<u8>>, AppError>> {
Box::pin(async {
let guard = self
.seed
.lock()
.map_err(|e| AppError::SecretStore(format!("seed lock poisoned: {e}")))?;
Ok(guard.clone())
})
}
fn set(&self, seed: &[u8]) -> BoxFuture<'_, Result<(), AppError>> {
let seed = seed.to_vec();
Box::pin(async move {
tracing::warn!(
"seed updated in memory — restart the enclave to re-encrypt \
and persist the new seed via KMS bootstrap"
);
let mut guard = self
.seed
.lock()
.map_err(|e| AppError::SecretStore(format!("seed lock poisoned: {e}")))?;
*guard = Some(seed);
Ok(())
})
}
}