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

Commit

Permalink
feat(rtc_auth_enclave::token_store): add save_access_key
Browse files Browse the repository at this point in the history
  • Loading branch information
PiDelport committed Jul 7, 2021
1 parent c1da010 commit 378f713
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions rtc_auth_enclave/src/token_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,35 @@ fn derive_lookup_key(dataset_uuid: Uuid, access_key: [u8; 24]) -> SgxResult<Stri
Ok(hex::encode(hash_bytes))
}

/// Save a new dataset access key and associated metadata in the store.
///
/// This must be called before [`issue_token`] can be called.
///
/// # Panics
///
/// If `(dataset_uuid, access_key)` already exists in the store.
#[allow(dead_code)] // TODO
pub(crate) fn save_access_key(
dataset_uuid: Uuid,
access_key: [u8; 24],
dataset_size: u64,
) -> Result<(), io::Error> {
let lookup_key = derive_lookup_key(dataset_uuid, access_key)?;
let mut store = kv_store();
let new_token_set = ExecutionTokenSet::new(dataset_uuid, dataset_size);

store
.try_insert(&lookup_key, &new_token_set)?
.map(|_existing| {
panic!(
"token_store::save_access_key: access key for dateset_uuid={:?} already saved (this should not happen)",
dataset_uuid,
)
});

Ok(())
}

// Returns exec token hash
pub(crate) fn issue_token(
dataset_uuid: Uuid,
Expand Down

0 comments on commit 378f713

Please sign in to comment.