-
Notifications
You must be signed in to change notification settings - Fork 29
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
Remove opencontainer dependency for timestamping code #11
Conversation
priteshbandi
commented
Jun 21, 2022
- timestamping shouldn't depend on opencontainers.
- Also, rephrased some of the error message for certificate chain validation.
Signed-off-by: Pritesh Bandi <pritesb@amazon.com>
Signed-off-by: Pritesh Bandi <pritesb@amazon.com>
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.
LGTM
// MalformedRequestError is used when timestamping request is malformed. | ||
type MalformedRequestError struct { |
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.
It is better to name it ErrorMalformedRequest
. It's a convention to put Error
as a prefix.
Signed-off-by: Pritesh Bandi <pritesb@amazon.com>
timestamp/request.go
Outdated
return NewRequest(digest.FromBytes(content)) | ||
} | ||
// NewRequestWithContent creates a request based on the given data and hash algorithm. | ||
func NewRequestWithContent(content []byte, alg crypto.Hash) (*Request, 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.
nit:
func NewRequestWithContent(content []byte, alg crypto.Hash) (*Request, error) { | |
func NewRequestFromContent(content []byte, alg crypto.Hash) (*Request, error) { |
timestamp/token.go
Outdated
// Verify verifies the message against the timestamp token information. | ||
func (tst *TSTInfo) Verify(message []byte) error { | ||
// VerifyWithContent verifies the message against the timestamp token information. | ||
func (tst *TSTInfo) VerifyWithContent(message []byte) 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.
nit:
func (tst *TSTInfo) VerifyWithContent(message []byte) error { | |
func (tst *TSTInfo) VerifyContent(message []byte) error { |
timestamp/request.go
Outdated
func validate(digest []byte, alg crypto.Hash) error { | ||
l := len(digest) | ||
var validContent bool | ||
switch alg { | ||
case crypto.SHA256: | ||
validContent = l == crypto.SHA256.Size() | ||
case crypto.SHA384: | ||
validContent = l == crypto.SHA384.Size() | ||
case crypto.SHA512: | ||
validContent = l == crypto.SHA512.Size() | ||
default: | ||
return MalformedRequestError{msg: fmt.Sprintf("unsupported hashing algorithm: %s", alg)} | ||
} | ||
if !validContent { | ||
return MalformedRequestError{msg: fmt.Sprintf("digest is of incorrect size: %d", l)} | ||
} | ||
return nil | ||
} |
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.
func validate(digest []byte, alg crypto.Hash) error { | |
l := len(digest) | |
var validContent bool | |
switch alg { | |
case crypto.SHA256: | |
validContent = l == crypto.SHA256.Size() | |
case crypto.SHA384: | |
validContent = l == crypto.SHA384.Size() | |
case crypto.SHA512: | |
validContent = l == crypto.SHA512.Size() | |
default: | |
return MalformedRequestError{msg: fmt.Sprintf("unsupported hashing algorithm: %s", alg)} | |
} | |
if !validContent { | |
return MalformedRequestError{msg: fmt.Sprintf("digest is of incorrect size: %d", l)} | |
} | |
return nil | |
} | |
func validate(digest []byte, alg crypto.Hash) error { | |
switch alg { | |
case crypto.SHA256, crypto.SHA384, crypto.SHA512: | |
// no-op | |
default: | |
return MalformedRequestError{msg: fmt.Sprintf("unsupported hashing algorithm: %s", alg)} | |
} | |
if len(digest) != alg.Size() { | |
return MalformedRequestError{msg: fmt.Sprintf("digest is of incorrect size: %d", l)} | |
} | |
return nil | |
} |
Signed-off-by: Pritesh Bandi <pritesb@amazon.com>
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.
LGTM
LGTM! |