@@ -168,13 +168,12 @@ func (t TPM) Sign(rr io.Reader, digest []byte, opts crypto.SignerOpts) ([]byte,
168
168
var se tpm2.Session
169
169
if t .AuthSession != nil {
170
170
var err error
171
- se , err = t .AuthSession .GetSession ()
171
+ var closer func () error
172
+ se , closer , err = t .AuthSession .GetSession ()
172
173
if err != nil {
173
174
return nil , fmt .Errorf ("signer: error getting session %s" , err )
174
175
}
175
- defer func () {
176
- _ , err = (& tpm2.FlushContext {FlushHandle : se .Handle ()}).Execute (rwr )
177
- }()
176
+ defer closer ()
178
177
} else {
179
178
se = tpm2 .PasswordAuth (nil )
180
179
}
@@ -302,8 +301,7 @@ func (t TPM) TLSCertificate() (tls.Certificate, error) {
302
301
}
303
302
304
303
type Session interface {
305
- io.Closer // read closer to the TPM
306
- GetSession () (auth tpm2.Session , err error ) // this supplies the session handle to the library
304
+ GetSession () (auth tpm2.Session , closer func () error , err error ) // this supplies the session handle to the library
307
305
}
308
306
309
307
// for pcr sessions
@@ -316,10 +314,10 @@ func NewPCRSession(rwr transport.TPM, sel []tpm2.TPMSPCRSelection) (PCRSession,
316
314
return PCRSession {rwr , sel }, nil
317
315
}
318
316
319
- func (p PCRSession ) GetSession () (auth tpm2.Session , err error ) {
320
- sess , _ , err := tpm2 .PolicySession (p .rwr , tpm2 .TPMAlgSHA256 , 16 )
317
+ func (p PCRSession ) GetSession () (auth tpm2.Session , closer func () error , err error ) {
318
+ sess , closer , err := tpm2 .PolicySession (p .rwr , tpm2 .TPMAlgSHA256 , 16 )
321
319
if err != nil {
322
- return nil , err
320
+ return nil , nil , err
323
321
}
324
322
_ , err = tpm2.PolicyPCR {
325
323
PolicySession : sess .Handle (),
@@ -328,13 +326,9 @@ func (p PCRSession) GetSession() (auth tpm2.Session, err error) {
328
326
},
329
327
}.Execute (p .rwr )
330
328
if err != nil {
331
- return nil , err
329
+ return nil , nil , err
332
330
}
333
- return sess , nil
334
- }
335
-
336
- func (p PCRSession ) Close () error {
337
- return nil
331
+ return sess , closer , nil
338
332
}
339
333
340
334
// for password sessions
@@ -347,10 +341,7 @@ func NewPasswordSession(rwr transport.TPM, password []byte) (PasswordSession, er
347
341
return PasswordSession {rwr , password }, nil
348
342
}
349
343
350
- func (p PasswordSession ) GetSession () (auth tpm2.Session , err error ) {
351
- return tpm2 .PasswordAuth (p .password ), nil
352
- }
353
-
354
- func (p PasswordSession ) Close () error {
355
- return nil
344
+ func (p PasswordSession ) GetSession () (auth tpm2.Session , closer func () error , err error ) {
345
+ c := func () error { return nil }
346
+ return tpm2 .PasswordAuth (p .password ), c , nil
356
347
}
0 commit comments