Skip to content
This repository was archived by the owner on May 9, 2022. It is now read-only.

Commit 378f713

Browse files
committed
feat(rtc_auth_enclave::token_store): add save_access_key
1 parent c1da010 commit 378f713

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

rtc_auth_enclave/src/token_store.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,35 @@ fn derive_lookup_key(dataset_uuid: Uuid, access_key: [u8; 24]) -> SgxResult<Stri
7979
Ok(hex::encode(hash_bytes))
8080
}
8181

82+
/// Save a new dataset access key and associated metadata in the store.
83+
///
84+
/// This must be called before [`issue_token`] can be called.
85+
///
86+
/// # Panics
87+
///
88+
/// If `(dataset_uuid, access_key)` already exists in the store.
89+
#[allow(dead_code)] // TODO
90+
pub(crate) fn save_access_key(
91+
dataset_uuid: Uuid,
92+
access_key: [u8; 24],
93+
dataset_size: u64,
94+
) -> Result<(), io::Error> {
95+
let lookup_key = derive_lookup_key(dataset_uuid, access_key)?;
96+
let mut store = kv_store();
97+
let new_token_set = ExecutionTokenSet::new(dataset_uuid, dataset_size);
98+
99+
store
100+
.try_insert(&lookup_key, &new_token_set)?
101+
.map(|_existing| {
102+
panic!(
103+
"token_store::save_access_key: access key for dateset_uuid={:?} already saved (this should not happen)",
104+
dataset_uuid,
105+
)
106+
});
107+
108+
Ok(())
109+
}
110+
82111
// Returns exec token hash
83112
pub(crate) fn issue_token(
84113
dataset_uuid: Uuid,

0 commit comments

Comments
 (0)