Expose the get and set helper implementation
This commit is contained in:
@@ -56,8 +56,20 @@ impl<T: Helper> AttestationStore for T {
|
|||||||
if id != &self.attestation_id() {
|
if id != &self.attestation_id() {
|
||||||
return Err(Error::NoSupport);
|
return Err(Error::NoSupport);
|
||||||
}
|
}
|
||||||
let private_key = self.store().find(PRIVATE_KEY_STORAGE_KEY)?;
|
helper_get(self)
|
||||||
let certificate = self.store().find(CERTIFICATE_STORAGE_KEY)?;
|
}
|
||||||
|
|
||||||
|
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) {
|
let (private_key, certificate) = match (private_key, certificate) {
|
||||||
(Some(x), Some(y)) => (x, y),
|
(Some(x), Some(y)) => (x, y),
|
||||||
(None, None) => return Ok(None),
|
(None, None) => return Ok(None),
|
||||||
@@ -70,12 +82,9 @@ impl<T: Helper> AttestationStore for T {
|
|||||||
private_key: *array_ref![private_key, 0, 32],
|
private_key: *array_ref![private_key, 0, 32],
|
||||||
certificate,
|
certificate,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set(&mut self, id: &Id, attestation: Option<&Attestation>) -> Result<(), Error> {
|
pub fn helper_set(env: &mut impl Env, attestation: Option<&Attestation>) -> Result<(), Error> {
|
||||||
if id != &self.attestation_id() {
|
|
||||||
return Err(Error::NoSupport);
|
|
||||||
}
|
|
||||||
let updates = match attestation {
|
let updates = match attestation {
|
||||||
None => [
|
None => [
|
||||||
StoreUpdate::Remove {
|
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];
|
const PRIVATE_KEY_STORAGE_KEY: usize = STORAGE_KEYS[0];
|
||||||
|
|||||||
Reference in New Issue
Block a user