-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented and Tested ReadPublic #279
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the change! This looks pretty solid, I just have some minor notes (mostly about the test)
}, | ||
}, | ||
}, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we defer
a FlushContext
similar to what we do here:
go-tpm/direct/tpm2/policy_test.go
Lines 53 to 61 in 7cd0fbd
cleanup := func() { | |
t.Helper() | |
flush := FlushContext{ | |
FlushHandle: rsp.ObjectHandle, | |
} | |
if err := flush.Execute(thetpm); err != nil { | |
t.Errorf("could not flush signing key: %v", err) | |
} | |
} |
Something like:
defer func() {
flush := FlushContext{
FlushHandle: rsp.ObjectHandle,
}
if err := flush.Execute(thetpm); err != nil {
t.Errorf("could not flush signing key: %v", err)
}
}()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chrisfenner
Sorry to make this more convoluted. Common commands like FlushContext take up more lines of code than go-tpm/tpm2
currently does. Users likely wouldn't want the clutter of management commands like FlushContext taking too much space; they care about the business logic of what they're putting into commands like CreatePrimary or ReadPublic.
Would having the idiom below be easier to read?
defer func() {
if err := FlushContext{FlushHandle: rsp.ObjectHandle}.Execute(thetpm); err != nil {
t.Errorf("...")
}
}
we could also make wrappers for commands like FlushContext, although I think it seems unnecessary for a small command like FlushContext.
e.g. in a util pkg or something:
direct/tpm2/directutil/context
func FlushContext(t transport.TPM, flushHandle handle) error {
return FlushContext{ FlushHandle: flushHandle}.Execute(t)
}
direct/tpm2/read_public_test.go:
defer func() {
if err := directutil.FlushContext(thetpm, rsp.ObjectHandle); err != nil {
t.Errorf("...")
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We discussed offline - we don't have to assert that every flush succeeded during the tests (the current tests don't; we just need a FlushContext test that checks it once).
So, I'd like to update my suggestion to just: can we add
defer &FlushContext{rsp.ObjectHandle}.Execute(thetpm))
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was getting
function must be invoked in defer statement
for
defer &FlushContext{rsp.ObjectHandle}.Execute(thetpm))
So my work around was
flushContext := FlushContext{FlushHandle: rspCP.ObjectHandle}
defer flushContext.Execute(thetpm)
which seems to work just as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you try defer (&FlushContext{rsp.ObjectHandle}).Execute(thetpm))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same error occurs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with the 2 line version here, and if we think of a neat idiom later it's easy to change.
}, | ||
}, | ||
}, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chrisfenner
Sorry to make this more convoluted. Common commands like FlushContext take up more lines of code than go-tpm/tpm2
currently does. Users likely wouldn't want the clutter of management commands like FlushContext taking too much space; they care about the business logic of what they're putting into commands like CreatePrimary or ReadPublic.
Would having the idiom below be easier to read?
defer func() {
if err := FlushContext{FlushHandle: rsp.ObjectHandle}.Execute(thetpm); err != nil {
t.Errorf("...")
}
}
we could also make wrappers for commands like FlushContext, although I think it seems unnecessary for a small command like FlushContext.
e.g. in a util pkg or something:
direct/tpm2/directutil/context
func FlushContext(t transport.TPM, flushHandle handle) error {
return FlushContext{ FlushHandle: flushHandle}.Execute(t)
}
direct/tpm2/read_public_test.go:
defer func() {
if err := directutil.FlushContext(thetpm, rsp.ObjectHandle); err != nil {
t.Errorf("...")
}
}
Not at all @alexmwu, I totally agree with the feedback. It would be awesome to have a one-line idiom for "defer flush this thing" and even awesomer to have a test version that asserts that the flush succeeded. I'm in email/meeting mode all day today so I can't remember if this would compile but can we have something along the lines of defer t.Run("🚽", &FlushContext{rsp.ObjectHandle}.Execute(thetpm) == nil) in the tests and defer &FlushContext{rsp.ObjectHandle}.Execute(thetpm)) in sample code? If that's not possible with the current reflection logic, are there tweaks we could make to make it possible? |
}, | ||
}, | ||
}, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with the 2 line version here, and if we think of a neat idiom later it's easy to change.
* Implemented and Tested ReadPublic * Fixed Comment Style for ReadPublic * Resolved most changes requested for PR Co-authored-by: Matthew Tsai <[email protected]>
Implemented and Tested ReadPublic