57 lines
987 B
Go
57 lines
987 B
Go
package model
|
|
|
|
import (
|
|
"crypto/rsa"
|
|
"strings"
|
|
|
|
"github.com/go-jose/go-jose/v4"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
type SigningKey struct {
|
|
PrivateKey *rsa.PrivateKey
|
|
KeyID uuid.UUID
|
|
Algorithm jose.SignatureAlgorithm
|
|
}
|
|
|
|
func (k *SigningKey) ID() string {
|
|
return strings.ReplaceAll(k.KeyID.String(), "-", "")
|
|
}
|
|
|
|
func (k *SigningKey) SignatureAlgorithm() jose.SignatureAlgorithm {
|
|
return k.Algorithm
|
|
}
|
|
|
|
func (k *SigningKey) Key() any {
|
|
return k.PrivateKey
|
|
}
|
|
|
|
type Key struct {
|
|
PrivateKey *rsa.PrivateKey
|
|
KeyID uuid.UUID
|
|
SigningAlg jose.SignatureAlgorithm
|
|
}
|
|
|
|
func (k *Key) SigningKey() *SigningKey {
|
|
return &SigningKey{
|
|
PrivateKey: k.PrivateKey,
|
|
KeyID: k.KeyID,
|
|
Algorithm: k.SigningAlg,
|
|
}
|
|
}
|
|
|
|
func (k *Key) ID() string {
|
|
return strings.ReplaceAll(k.KeyID.String(), "-", "")
|
|
}
|
|
|
|
func (k *Key) Algorithm() jose.SignatureAlgorithm {
|
|
return k.SigningAlg
|
|
}
|
|
|
|
func (k *Key) Key() any {
|
|
return &k.PrivateKey.PublicKey
|
|
}
|
|
|
|
func (k *Key) Use() string {
|
|
return "sig"
|
|
}
|