This change updates to go-jose v4, which was a new major release. jose.ParseSigned now expects the supported signing algorithms to be passed, on which we previously did our own check. As they use a dedicated type for this, the slice of string needs to be converted. The returned error also need to be handled in a non-standard way in order to stay compatible. For OIDC v4 we should use the jose.SignatureAlgorithm type directly and wrap errors, instead of returned static defined errors. Closes #583
27 lines
515 B
Go
27 lines
515 B
Go
package crypto
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
|
|
jose "github.com/go-jose/go-jose/v4"
|
|
)
|
|
|
|
func Sign(object any, signer jose.Signer) (string, error) {
|
|
payload, err := json.Marshal(object)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return SignPayload(payload, signer)
|
|
}
|
|
|
|
func SignPayload(payload []byte, signer jose.Signer) (string, error) {
|
|
if signer == nil {
|
|
return "", errors.New("missing signer")
|
|
}
|
|
result, err := signer.Sign(payload)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return result.CompactSerialize()
|
|
}
|