-
Notifications
You must be signed in to change notification settings - Fork 18
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
feat: validate namespace in share constructor #87
Conversation
@@ -110,6 +94,14 @@ func (n Namespace) ID() []byte { | |||
return n.data[NamespaceVersionSize:] | |||
} | |||
|
|||
func Validate(version uint8, id []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.
Needs a little godoc.
|
||
err = validateID(bytes[VersionIndex], bytes[NamespaceVersionSize:]) | ||
if err != nil { | ||
if err := Validate(bytes[VersionIndex], bytes[NamespaceVersionSize:]); err != 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.
nit: to avoid confusing byte slicing you could do:
ns := Namespace{data: bytes}
err := Validate(ns.Version(), ns.ID())
if err != nil {
return Namespace{}, err
}
return ns
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.
Still, I'm not sure why we wouldn't add Validate as a method. (I know it's guaranteed to be valid after the construction but still)
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 gets used by the share
package (which keeps the namespace in bytes form). Maybe we could consider either caching the namespace in the share struct or merging the namespace package with the share
package (and thus we can return the namespace without needing to validate it)
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.
:merge-it:
panic(err) | ||
} | ||
return blob | ||
func NewV0Blob(ns ns.Namespace, data []byte) (*Blob, 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.
godoc
I plan to merge the namespace package into the shares package. This will mean that |
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
Closes: #86
This PR also addresses the nits from @Rootul's review here