11// SPDX-License-Identifier: Apache-2.0
22
33use std:: path:: PathBuf ;
4+ use std:: time:: Duration ;
45
56use anyhow:: Context ;
67use clap:: Parser ;
@@ -14,7 +15,7 @@ use tss_esapi::tss2_esys::TPMT_TK_AUTH;
1415use crate :: cli:: GlobalOpts ;
1516use crate :: context:: create_context;
1617use crate :: handle:: { ContextSource , load_object_from_source} ;
17- use crate :: parse:: parse_context_source;
18+ use crate :: parse:: { parse_context_source, parse_duration } ;
1819use crate :: session:: load_session_from_file;
1920
2021/// Authorize a policy with a signed authorization.
@@ -35,8 +36,8 @@ pub struct PolicySignedCmd {
3536 pub signature : PathBuf ,
3637
3738 /// Expiration time in seconds (0 = no expiration)
38- #[ arg( short = 'x' , long = "expiration" , default_value = "0" ) ]
39- pub expiration : i32 ,
39+ #[ arg( short = 'x' , long = "expiration" , value_parser = parse_duration , default_value = "0" ) ]
40+ pub expiration : Option < Duration > ,
4041
4142 /// cpHash file (optional)
4243 #[ arg( long = "cphash-input" ) ]
@@ -84,33 +85,27 @@ impl PolicySignedCmd {
8485 } ;
8586
8687 let policy_ref = match & self . qualification {
87- Some ( bytes) => Nonce :: try_from ( bytes. as_slice ( ) . to_vec ( ) )
88+ Some ( bytes) => Nonce :: try_from ( bytes. as_slice ( ) )
8889 . map_err ( |e| anyhow:: anyhow!( "qualifying data: {e}" ) ) ?,
8990 None => Nonce :: default ( ) ,
9091 } ;
9192
92- let expiration = if self . expiration == 0 {
93- None
94- } else {
95- Some ( std:: time:: Duration :: from_secs ( self . expiration as u64 ) )
96- } ;
97-
9893 let ( timeout, ticket) = ctx
9994 . policy_signed (
10095 policy_session,
10196 auth_object,
10297 Nonce :: default ( ) , // nonce_tpm
10398 cp_hash,
10499 policy_ref,
105- expiration,
100+ self . expiration ,
106101 signature,
107102 )
108103 . context ( "TPM2_PolicySigned failed" ) ?;
109104
110105 info ! ( "policy signed succeeded" ) ;
111106
112107 if let Some ( ref path) = self . timeout_out {
113- std:: fs:: write ( path, timeout. as_bytes ( ) )
108+ std:: fs:: write ( path, timeout. as_bytes ( ) . to_vec ( ) )
114109 . with_context ( || format ! ( "writing timeout to {}" , path. display( ) ) ) ?;
115110 }
116111
0 commit comments