* updates go-jose to new updated repo due to migration - updated from /square/go-jose to /go-jose/go-jose - updates to v2.6.3 - addresses CVE-2016-9123 and CVE-2016-9121 - fixes tests that were adjusting for a 1s delay * revert 299>300 in op_test.go
36 lines
702 B
Go
36 lines
702 B
Go
package op
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"gopkg.in/go-jose/go-jose.v2"
|
|
)
|
|
|
|
var ErrSignerCreationFailed = errors.New("signer creation failed")
|
|
|
|
type SigningKey interface {
|
|
SignatureAlgorithm() jose.SignatureAlgorithm
|
|
Key() any
|
|
ID() string
|
|
}
|
|
|
|
func SignerFromKey(key SigningKey) (jose.Signer, error) {
|
|
signer, err := jose.NewSigner(jose.SigningKey{
|
|
Algorithm: key.SignatureAlgorithm(),
|
|
Key: &jose.JSONWebKey{
|
|
Key: key.Key(),
|
|
KeyID: key.ID(),
|
|
},
|
|
}, (&jose.SignerOptions{}).WithType("JWT"))
|
|
if err != nil {
|
|
return nil, ErrSignerCreationFailed // TODO: log / wrap error?
|
|
}
|
|
return signer, nil
|
|
}
|
|
|
|
type Key interface {
|
|
ID() string
|
|
Algorithm() jose.SignatureAlgorithm
|
|
Use() string
|
|
Key() any
|
|
}
|