Expose the get and set helper implementation

This commit is contained in:
Julien Cretin
2022-07-12 16:57:19 +02:00
parent bc354d8abb
commit f528567ce1

View File

@@ -56,8 +56,20 @@ impl<T: Helper> AttestationStore for T {
if id != &self.attestation_id() {
return Err(Error::NoSupport);
}
let private_key = self.store().find(PRIVATE_KEY_STORAGE_KEY)?;
let certificate = self.store().find(CERTIFICATE_STORAGE_KEY)?;
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)?;
let (private_key, certificate) = match (private_key, certificate) {
(Some(x), Some(y)) => (x, y),
(None, None) => return Ok(None),
@@ -70,12 +82,9 @@ impl<T: Helper> AttestationStore for T {
private_key: *array_ref![private_key, 0, 32],
certificate,
}))
}
}
fn set(&mut self, id: &Id, attestation: Option<&Attestation>) -> Result<(), Error> {
if id != &self.attestation_id() {
return Err(Error::NoSupport);
}
pub fn helper_set(env: &mut impl Env, attestation: Option<&Attestation>) -> Result<(), Error> {
let updates = match attestation {
None => [
StoreUpdate::Remove {
@@ -96,8 +105,7 @@ impl<T: Helper> AttestationStore for T {
},
],
};
Ok(self.store().transaction(&updates)?)
}
Ok(env.store().transaction(&updates)?)
}
const PRIVATE_KEY_STORAGE_KEY: usize = STORAGE_KEYS[0];