Skip to content

Commit b62029d

Browse files
authored
Merge pull request #336 from ionut-arm/tkc-asmut-ctx
Implement ref conversions from TKC to Context
2 parents 49921ce + 6e74117 commit b62029d

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

tss-esapi/src/abstraction/transient/mod.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use crate::{
3737
use log::error;
3838
use serde::{Deserialize, Serialize};
3939
use std::collections::HashMap;
40-
use std::convert::{TryFrom, TryInto};
40+
use std::convert::{AsMut, AsRef, TryFrom, TryInto};
4141
use zeroize::Zeroize;
4242

4343
mod key_attestation;
@@ -528,6 +528,18 @@ impl TransientKeyContext {
528528
}
529529
}
530530

531+
impl AsRef<Context> for TransientKeyContext {
532+
fn as_ref(&self) -> &Context {
533+
&self.context
534+
}
535+
}
536+
537+
impl AsMut<Context> for TransientKeyContext {
538+
fn as_mut(&mut self) -> &mut Context {
539+
&mut self.context
540+
}
541+
}
542+
531543
/// Build a new `TransientKeyContext`.
532544
///
533545
/// # Default values

tss-esapi/tests/integration_tests/abstraction_tests/transient_key_context_tests.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,3 +852,13 @@ fn activate_credential_wrong_data() {
852852
panic!("Got crate error ({}) when expecting an error from TPM.", e);
853853
}
854854
}
855+
856+
#[test]
857+
fn get_random_from_tkc() {
858+
// Check that we can convert a reference from TKC to Context
859+
let mut ctx = create_ctx();
860+
let _rand_bytes = ctx
861+
.as_mut()
862+
.execute_without_session(|ctx| ctx.get_random(16))
863+
.expect("Failed to get random bytes");
864+
}

0 commit comments

Comments
 (0)