@@ -8,7 +8,7 @@ use super::Provide;
8
8
use crate :: authenticators:: ApplicationName ;
9
9
use crate :: key_info_managers:: ManageKeyInfo ;
10
10
use derivative:: Derivative ;
11
- use log:: { error , info, trace} ;
11
+ use log:: { info, trace} ;
12
12
use parsec_interface:: operations:: list_providers:: ProviderInfo ;
13
13
use parsec_interface:: operations:: {
14
14
psa_destroy_key, psa_export_public_key, psa_generate_key, psa_import_key, psa_sign_hash,
@@ -17,9 +17,10 @@ use parsec_interface::operations::{
17
17
use parsec_interface:: requests:: { Opcode , ProviderID , ResponseStatus , Result } ;
18
18
use std:: collections:: HashSet ;
19
19
use std:: io:: ErrorKind ;
20
+ use std:: str:: FromStr ;
20
21
use std:: sync:: { Arc , Mutex , RwLock } ;
21
22
use tss_esapi:: utils:: algorithm_specifiers:: Cipher ;
22
- use tss_esapi:: Tcti ;
23
+ use tss_esapi:: utils :: tcti :: Tcti ;
23
24
use uuid:: Uuid ;
24
25
25
26
mod asym_sign;
@@ -154,7 +155,7 @@ impl Drop for TpmProvider {
154
155
pub struct TpmProviderBuilder {
155
156
#[ derivative( Debug = "ignore" ) ]
156
157
key_info_store : Option < Arc < RwLock < dyn ManageKeyInfo + Send + Sync > > > ,
157
- tcti : Option < Tcti > ,
158
+ tcti : Option < String > ,
158
159
owner_hierarchy_auth : Option < String > ,
159
160
}
160
161
@@ -177,17 +178,7 @@ impl TpmProviderBuilder {
177
178
}
178
179
179
180
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 ( ) ) ;
191
182
192
183
self
193
184
}
@@ -231,8 +222,15 @@ impl TpmProviderBuilder {
231
222
unsafe fn find_default_context_cipher ( & self ) -> std:: io:: Result < Cipher > {
232
223
let ciphers = [ Cipher :: aes_256_cfb ( ) , Cipher :: aes_128_cfb ( ) ] ;
233
224
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
+ } ) ?,
236
234
)
237
235
. or_else ( |e| {
238
236
format_error ! ( "Error when creating TSS Context" , e) ;
@@ -264,9 +262,15 @@ impl TpmProviderBuilder {
264
262
pub unsafe fn build ( mut self ) -> std:: io:: Result < TpmProvider > {
265
263
let hierarchy_auth = self . get_hierarchy_auth ( ) ?;
266
264
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
+ } ) ?;
270
274
TpmProvider :: new (
271
275
self . key_info_store . ok_or_else ( || {
272
276
std:: io:: Error :: new ( ErrorKind :: InvalidData , "missing key info store" )
0 commit comments