-
Notifications
You must be signed in to change notification settings - Fork 22
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
Allow associating an ID with a biscuit's root key #151
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package biscuit | ||
|
||
import "io" | ||
|
||
type compositionOption interface { | ||
builderOption | ||
biscuitOption | ||
} | ||
|
||
type rngOption struct { | ||
io.Reader | ||
} | ||
|
||
func (o rngOption) applyToBuilder(b *builderOptions) { | ||
if r := o.Reader; r != nil { | ||
b.rng = o | ||
} | ||
} | ||
|
||
func (o rngOption) applyToBiscuit(b *biscuitOptions) error { | ||
if r := o.Reader; r != nil { | ||
b.rng = r | ||
} | ||
return nil | ||
} | ||
|
||
// WithRNG supplies a random number generator as a byte stream from which to read when generating | ||
// key pairs with which to sign blocks within biscuits. | ||
func WithRNG(r io.Reader) compositionOption { | ||
return rngOption{r} | ||
} | ||
|
||
type rootKeyIDOption uint32 | ||
|
||
func (o rootKeyIDOption) applyToBuilder(b *builderOptions) { | ||
id := uint32(o) | ||
b.rootKeyID = &id | ||
} | ||
|
||
func (o rootKeyIDOption) applyToBiscuit(b *biscuitOptions) error { | ||
id := uint32(o) | ||
b.rootKeyID = &id | ||
return nil | ||
} | ||
|
||
// WithRootKeyID specifies the identifier for the root key pair used to sign a biscuit's authority | ||
// block, allowing a consuming party to later select the corresponding public key to validate that | ||
// signature. | ||
func WithRootKeyID(id uint32) compositionOption { | ||
return rootKeyIDOption(id) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back 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.
would returning a pointer instead of a tuple also work to signal optionality?
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 vacillated over this decision for a while before implementing this new method. I'm glad you asked about it.
Yes, it would work to return a pointer, though it's fairly typical in Go to use this style, especially when the primary return value's type has a sensible zero value.
This paired value style comes from and is adapted somewhat unjustly from a few of Go's statements and expressions that benefit from it:
In each of these cases, callers are free to omit the assignment of this second value, and I don't mean just not assigning it to a named variable. Callers can omit mention of the second value entirely if they don't care about it. By contrast, if a map index expression returned by pointer to indicate whether or not the key was bound to a value in the map, all callers would have to confront the possibility of absence.
My use of that idiom here doesn't benefit from that same treatment, though. A caller of my
(*Biscuit).RootKeyID
cannot ignore the presence of that second return value. They are free to ignore its value, though, and use the first value unconditionally, since the zero value foruint32
is, well, zero, which is a valid key ID.Given that, I'm now coming back around to thinking that returning by pointer would be a safer choice here. Please allow me to make that change, and then you can decide if you like that by-pointer approach better.
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 also think returning a pointer would be a bit safer. The rust implementation distinguishes between no id and 0. Since biscuit uses protobuf 2, I think the serialization also makes that distinction.
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 see commit 9b7f488 for this change. I'll squash the commits before merging.
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.
looks good, thanks! in can also squash-merge the PR if that’s simpler for you
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.
Yes, that's fine with if you squash the commits. I recommend preserving the message from the first one.
After we merge this, I'll carry on with addressing the rest of #150—selecting a public key in calls to the
(b *Biscuit).Authorizer
method, or a new sibling method, per #150 (comment).