-
Notifications
You must be signed in to change notification settings - Fork 4
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
Enhance corim display Command to Support Unsigned CoRIMs #14
Conversation
Signed-off-by: Ravjot Singh <[email protected]>
// try to decode as a signed CoRIM | ||
var s corim.SignedCorim | ||
if err = s.FromCOSE(corimCBOR); err == nil { | ||
// successfully decoded as signed CoRIM |
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 code in this branch should be in a displaySignedCorim function to avoid the rightward drift
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.
@deeglaze okiee should i create separate functions for signed and unsigned corims and call them in display function?
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.
That’s my preference
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.
okieee @deeglaze i will update this file. Any more suggestions?
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.
Today I just started my holiday break. Splitting up into functions is a fine enough improvement for now.
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 @deeglaze really appreciate you suggestion...
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.
@deeglaze i have made some adjustments to the code according to your recommendations can you review them...
Signed-off-by: Ravjot Singh <[email protected]>
cmd/corimDisplay.go
Outdated
} | ||
|
||
if metaJSON, err = json.MarshalIndent(&s.Meta, "", " "); err != nil { | ||
return fmt.Errorf("error decoding CoRIM Meta from %s: %w", signedCorimFile, err) | ||
fmt.Println("Corim:") |
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.
Please use consistent capitalization.
fmt.Println("Corim:") | |
fmt.Println("CoRIM:") |
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.
Resolved...
cmd/corimDisplay.go
Outdated
|
||
if showTags { | ||
fmt.Println("Tags:") | ||
// convert []corim.Tag to [][]byte |
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 don’t think I’d put the conversion here. Maybe displayTags converts and calls displayTagBytes if you need the bytes form.
cmd/corimDisplay.go
Outdated
} else { | ||
fmt.Printf(">> unmatched CBOR tag: %x\n", cborTag) | ||
} | ||
// convert []corim.Tag to [][]byte |
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.
A translation here is duplicative.
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 will add this code to display function itself
} | ||
|
||
return nil | ||
} | ||
|
||
func display(corimFile string, showTags bool) error { |
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.
Generally you’d want a rendering function to be versatile in input and output types, so I’d recommend reading from an io.Reader and writing to an io.Writer. You can then make convenience functions that prepare the options for you. In terms of options, showTags as a boolean input makes calling positions hard to interpret and makes adding options more difficult. I’d recommend making the writer and showTags options fields of a DisplayOptions struct to take as the only other argument from the reader.
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.
@deeglaze I appreciate your recommendation to utilize io.Reader and io.Writer along with a DisplayOptions struct to enhance the versatility and flexibility of our rendering functions.
However, I’ve observed that the majority of the code in our repository currently follows a different approach. To maintain consistency throughout the project, I believe it would be more effective to adhere to our existing coding patterns.
Could you please share some references or examples in contexts similar to our project? This would help me better understand how we might integrate these improvements in a way that aligns with our current structure...
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.
Here’s another cli in go that uses the pattern of (context, subject, options) https://github.com/google/gce-tcb-verifier/tree/main/gcetcbendorsement
writing to os.Stdout and writing to string buffer shouldn’t need fundamentally different implementations.
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.
@deeglaze may be i could raise a new issue about changing to this pattern all the instances where there is io kinda situation
cmd/corimDisplay.go
Outdated
// displayTags processes and displays embedded tags within a CoRIM | ||
func displayTags(tags [][]byte) { | ||
for i, e := range tags { | ||
// ensure the tag has at least 4 bytes (3 for tag identifier and 1 for data) |
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 description of the constant’s significance should be above its definition as a named constant. Then change the literal to the named constant.
continue | ||
} | ||
|
||
// Split tag identifier from data |
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.
This is probably better suited to a function that identifies a tag into an enum that you can then use in the switch. I think that function would belong in the corim library.
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.
This is probably better suited to a function that identifies a tag into an enum that you can then use in the switch. I think that function would belong in the corim library.
I reviewed the corim library but couldn't find an existing function to identify tags and map them to enums. Let me know if you'd like me to implement the tag identification function or if there are other directions you'd prefer.
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.
If you implement it here unexported, we can move it to the corim repo later.
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.
yup i will surly do that but i was thinking that i maybe could raise a new PR about this as this issue was about display of unsigned CoRIMs
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.
@deeglaze i will start working on this....
Signed-off-by: Ravjot Singh <[email protected]>
@deeglaze can you guide about test why they are failing do i need to update display_test file ?? |
@deeglaze |
yeah , i face the same issue in repo mocks file is missing in cmd and |
The makefile uses mockgen to create the mocks files. I’ll need to fuss with the CI to see why it’s now failing. I’m on holiday break right now, so no promises I can get to it soon. |
@ravjot07 you can try this to create mocks : make presubmit |
Signed-off-by: Ravjot Singh <[email protected]>
@deeglaze i think there was some issue on my side as in mockgen installation and its been resolved now. |
@Priyanshuthapliyal2005 yaa it worked this time actually there was installation errors, and then i installed mockgen package manually so it worked |
} | ||
cmd.SetArgs(args) | ||
|
||
fs = afero.NewMemMapFs() | ||
err := afero.WriteFile(fs, "invalid.cbor", testSignedCorimInvalid, 0644) |
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.
What about the invalid.cbor testdata is unsuitable now? This orphans the test file and embedding variable.
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.
@deeglaze yee, i kinda missed this will update this..
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.
@deeglaze I have updated the test. I really appreciate your help and guidance, especially while you are on holiday. Thank you so much for taking the time to assist me—it means a lot!
@Priyanshuthapliyal2005 ya that the whole point for this PR is to enhance the display command to support unsigned CoRIMs |
Problem:
The
corim display
command was limited to handling only signed CoRIM files. Attempting to display an unsigned CoRIM resulted error:Solution:
display
function to attempt decoding the input file as a signed CoRIM first. If this fails, it falls back to decoding as an unsigned CoRIM.[]corim.Tag
to[][]byte
before passing it to thedisplayTags
function.Closes Issue 49 form Corim Repository (veraison/corim#49)