@@ -8,7 +8,7 @@ use super::Provide;
88use crate :: authenticators:: ApplicationName ;
99use crate :: key_info_managers:: ManageKeyInfo ;
1010use derivative:: Derivative ;
11- use log:: { error , info, trace} ;
11+ use log:: { info, trace} ;
1212use parsec_interface:: operations:: list_providers:: ProviderInfo ;
1313use parsec_interface:: operations:: {
1414 psa_destroy_key, psa_export_public_key, psa_generate_key, psa_import_key, psa_sign_hash,
@@ -17,9 +17,10 @@ use parsec_interface::operations::{
1717use parsec_interface:: requests:: { Opcode , ProviderID , ResponseStatus , Result } ;
1818use std:: collections:: HashSet ;
1919use std:: io:: ErrorKind ;
20+ use std:: str:: FromStr ;
2021use std:: sync:: { Arc , Mutex , RwLock } ;
2122use tss_esapi:: utils:: algorithm_specifiers:: Cipher ;
22- use tss_esapi:: Tcti ;
23+ use tss_esapi:: utils :: tcti :: Tcti ;
2324use uuid:: Uuid ;
2425
2526mod asym_sign;
@@ -154,7 +155,7 @@ impl Drop for TpmProvider {
154155pub struct TpmProviderBuilder {
155156 #[ derivative( Debug = "ignore" ) ]
156157 key_info_store : Option < Arc < RwLock < dyn ManageKeyInfo + Send + Sync > > > ,
157- tcti : Option < Tcti > ,
158+ tcti : Option < String > ,
158159 owner_hierarchy_auth : Option < String > ,
159160}
160161
@@ -177,17 +178,7 @@ impl TpmProviderBuilder {
177178 }
178179
179180 pub fn with_tcti ( mut self , tcti : & str ) -> TpmProviderBuilder {
180- // Convert from a String to the enum.
181- self . tcti = match tcti {
182- "device" => Some ( Tcti :: Device ) ,
183- "mssim" => Some ( Tcti :: Mssim ) ,
184- _ => {
185- if crate :: utils:: GlobalConfig :: log_error_details ( ) {
186- error ! ( "The string {} does not match a TCTI device." , tcti) ;
187- }
188- None
189- }
190- } ;
181+ self . tcti = Some ( tcti. to_owned ( ) ) ;
191182
192183 self
193184 }
@@ -231,8 +222,15 @@ impl TpmProviderBuilder {
231222 unsafe fn find_default_context_cipher ( & self ) -> std:: io:: Result < Cipher > {
232223 let ciphers = [ Cipher :: aes_256_cfb ( ) , Cipher :: aes_128_cfb ( ) ] ;
233224 let mut ctx = tss_esapi:: Context :: new (
234- self . tcti
235- . ok_or_else ( || std:: io:: Error :: new ( ErrorKind :: InvalidData , "missing TCTI" ) ) ?,
225+ Tcti :: from_str ( self . tcti . as_ref ( ) . ok_or_else ( || {
226+ std:: io:: Error :: new ( ErrorKind :: InvalidData , "Invalid TCTI configuration string" )
227+ } ) ?)
228+ . or_else ( |_| {
229+ Err ( std:: io:: Error :: new (
230+ ErrorKind :: InvalidData ,
231+ "Invalid TCTI configuration string" ,
232+ ) )
233+ } ) ?,
236234 )
237235 . or_else ( |e| {
238236 format_error ! ( "Error when creating TSS Context" , e) ;
@@ -264,9 +262,15 @@ impl TpmProviderBuilder {
264262 pub unsafe fn build ( mut self ) -> std:: io:: Result < TpmProvider > {
265263 let hierarchy_auth = self . get_hierarchy_auth ( ) ?;
266264 let default_cipher = self . find_default_context_cipher ( ) ?;
267- let tcti = self
268- . tcti
269- . ok_or_else ( || std:: io:: Error :: new ( ErrorKind :: InvalidData , "missing TCTI" ) ) ?;
265+ let tcti = Tcti :: from_str ( self . tcti . as_ref ( ) . ok_or_else ( || {
266+ std:: io:: Error :: new ( ErrorKind :: InvalidData , "Invalid TCTI configuration string" )
267+ } ) ?)
268+ . or_else ( |_| {
269+ Err ( std:: io:: Error :: new (
270+ ErrorKind :: InvalidData ,
271+ "Invalid TCTI configuration string" ,
272+ ) )
273+ } ) ?;
270274 TpmProvider :: new (
271275 self . key_info_store . ok_or_else ( || {
272276 std:: io:: Error :: new ( ErrorKind :: InvalidData , "missing key info store" )
0 commit comments