Skip to content

Commit

Permalink
go/signature: apply options on registered contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
pro-wh committed Mar 23, 2022
1 parent 0318535 commit ed92758
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
1 change: 1 addition & 0 deletions .changelog/4591.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
go/signature: Apply options on registered contexts
24 changes: 12 additions & 12 deletions go/common/crypto/signature/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,20 +313,20 @@ type UnsafeSigner interface {

// PrepareSignerContext prepares a context for use during signing by a Signer.
func PrepareSignerContext(context Context) ([]byte, error) {
// The remote signer implementation uses the raw context, and
// registration is dealt with client side. Just check that the
// length is sensible, even though the client should be sending
// something sane.
if allowUnregisteredContexts {
if cLen := len(context); cLen == 0 || cLen > ed25519.ContextMaxSize {
return nil, errMalformedContext
}
return []byte(context), nil
}

// Ensure that the context is registered for use.
rawOpts, isRegistered := registeredContexts.Load(context)
if !isRegistered {
// The remote signer implementation uses the raw context, and
// registration is dealt with client side. Just check that the
// length is sensible, even though the client should be sending
// something sane.
if allowUnregisteredContexts {
if cLen := len(context); cLen == 0 || cLen > ed25519.ContextMaxSize {
return nil, errMalformedContext
}
return []byte(context), nil
}

// Ensure that the context is registered for use.
return nil, errUnregisteredContext
}
opts := rawOpts.(*contextOptions)
Expand Down

0 comments on commit ed92758

Please sign in to comment.