Inline Helper

This commit is contained in:
Julien Cretin
2022-07-14 12:46:01 +02:00
parent b28f8f6d33
commit 07a28fe611
6 changed files with 53 additions and 51 deletions

View File

@@ -43,30 +43,6 @@ pub enum Error {
/// Keys of the environment store reserved for the attestation store.
pub const STORAGE_KEYS: &[usize] = &[1, 2];
/// Implements a default attestation store using the environment store.
///
/// Supports only one attestation at a time.
pub trait Helper: Env {
/// Returns the current attestation id.
fn attestation_id(&self) -> Id;
}
impl<T: Helper> AttestationStore for T {
fn get(&mut self, id: &Id) -> Result<Option<Attestation>, Error> {
if id != &self.attestation_id() {
return Err(Error::NoSupport);
}
helper_get(self)
}
fn set(&mut self, id: &Id, attestation: Option<&Attestation>) -> Result<(), Error> {
if id != &self.attestation_id() {
return Err(Error::NoSupport);
}
helper_set(self, attestation)
}
}
pub fn helper_get(env: &mut impl Env) -> Result<Option<Attestation>, Error> {
let private_key = env.store().find(PRIVATE_KEY_STORAGE_KEY)?;
let certificate = env.store().find(CERTIFICATE_STORAGE_KEY)?;