Peter Kurfer
647f602c79
- added Core CRD to manage DB migrations & configuration, PostgREST and GoTrue (auth) - added APIGateway CRD to manage Envoy proxy - added Dashboard CRD to manage (so far) pg-meta and (soon) studio deployments - implemented basic Envoy control plane based on K8s watcher
48 lines
933 B
Go
48 lines
933 B
Go
package jwk
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"encoding/json"
|
|
)
|
|
|
|
type KeyType string
|
|
|
|
const (
|
|
KeyTypeEC KeyType = "EC"
|
|
KeyTypeRSA KeyType = "RSA"
|
|
KeyTypeOctetSequence KeyType = "oct"
|
|
)
|
|
|
|
type Algorithm string
|
|
|
|
const (
|
|
AlgorithmNone Algorithm = ""
|
|
AlgorithmHS256 Algorithm = "HS256"
|
|
AlgorithmHS384 Algorithm = "HS384"
|
|
AlgorithmHS512 Algorithm = "HS512"
|
|
)
|
|
|
|
var _ json.Marshaler = (*SymmetricKey)(nil)
|
|
|
|
type SymmetricKey struct {
|
|
Algorithm Algorithm
|
|
Key []byte
|
|
}
|
|
|
|
// MarshalJSON implements json.Marshaler.
|
|
func (s SymmetricKey) MarshalJSON() ([]byte, error) {
|
|
if s.Algorithm == AlgorithmNone {
|
|
s.Algorithm = AlgorithmHS256
|
|
}
|
|
tmp := struct {
|
|
KeyType KeyType `json:"kty"`
|
|
Algorithm Algorithm `json:"alg"`
|
|
Key string `json:"k"`
|
|
}{
|
|
KeyType: KeyTypeOctetSequence,
|
|
Algorithm: s.Algorithm,
|
|
Key: base64.RawURLEncoding.EncodeToString(s.Key),
|
|
}
|
|
|
|
return json.Marshal(tmp)
|
|
}
|