@@ -21,6 +21,7 @@ const DEVICE: &str = "device";
21
21
const MSSIM : & str = "mssim" ;
22
22
const SWTPM : & str = "swtpm" ;
23
23
const TABRMD : & str = "tabrmd" ;
24
+ const LIBTPMS : & str = "libtpms" ;
24
25
25
26
/// TCTI Context created via a TCTI Loader Library.
26
27
/// Wrapper around the TSS2_TCTI_CONTEXT structure.
@@ -139,6 +140,10 @@ pub enum TctiNameConf {
139
140
///
140
141
/// For more information about configuration, see [this page](https://www.mankier.com/3/Tss2_Tcti_Mssim_Init)
141
142
Swtpm ( TpmSimulatorConfig ) ,
143
+ /// Connect to a TPM (simulator) available as a library
144
+ ///
145
+ /// This allows for an optional state file
146
+ LibTpms { state : Option < PathBuf > } ,
142
147
/// Connect to a TPM through an Access Broker/Resource Manager daemon
143
148
///
144
149
/// For more information about configuration, see [this page](https://www.mankier.com/3/Tss2_Tcti_Tabrmd_Init)
@@ -174,6 +179,7 @@ impl TryFrom<TctiNameConf> for CString {
174
179
TctiNameConf :: Mssim ( ..) => MSSIM ,
175
180
TctiNameConf :: Swtpm ( ..) => SWTPM ,
176
181
TctiNameConf :: Tabrmd ( ..) => TABRMD ,
182
+ TctiNameConf :: LibTpms { .. } => LIBTPMS ,
177
183
} ;
178
184
179
185
let tcti_conf = match tcti {
@@ -204,6 +210,9 @@ impl TryFrom<TctiNameConf> for CString {
204
210
TctiNameConf :: Tabrmd ( config) => {
205
211
format ! ( "bus_name={},bus_type={}" , config. bus_name, config. bus_type)
206
212
}
213
+ TctiNameConf :: LibTpms { state } => {
214
+ state. map ( |s| s. display ( ) . to_string ( ) ) . unwrap_or_default ( )
215
+ }
207
216
} ;
208
217
209
218
if tcti_conf. is_empty ( ) {
@@ -247,6 +256,15 @@ impl FromStr for TctiNameConf {
247
256
) ?) ) ;
248
257
}
249
258
259
+ let libtpms_pattern = Regex :: new ( r"^libtpms(:(.*))?$" ) . unwrap ( ) ; //should not fail
260
+ if let Some ( captures) = libtpms_pattern. captures ( config_str) {
261
+ return Ok ( TctiNameConf :: LibTpms {
262
+ state : captures
263
+ . get ( 2 )
264
+ . and_then ( |s| PathBuf :: from_str ( s. as_str ( ) ) . ok ( ) ) ,
265
+ } ) ;
266
+ }
267
+
250
268
Err ( Error :: WrapperError ( WrapperErrorKind :: InvalidParam ) )
251
269
}
252
270
}
@@ -327,6 +345,17 @@ fn validate_from_str_tcti() {
327
345
328
346
let tcti = TctiNameConf :: from_str ( "tabrmd" ) . unwrap ( ) ;
329
347
assert_eq ! ( tcti, TctiNameConf :: Tabrmd ( Default :: default ( ) ) ) ;
348
+
349
+ let tcti = TctiNameConf :: from_str ( "libtpms:/try/this/path" ) . unwrap ( ) ;
350
+ assert_eq ! (
351
+ tcti,
352
+ TctiNameConf :: LibTpms {
353
+ state: Some ( PathBuf :: from( "/try/this/path" ) )
354
+ }
355
+ ) ;
356
+
357
+ let tcti = TctiNameConf :: from_str ( "libtpms" ) . unwrap ( ) ;
358
+ assert_eq ! ( tcti, TctiNameConf :: LibTpms { state: None } ) ;
330
359
}
331
360
332
361
/// Configuration for a Device TCTI context
0 commit comments