supabase-operator/internal/jwk/key.go
Peter Kurfer 647f602c79
Some checks failed
Lint / Run on Ubuntu (push) Failing after 2m58s
E2E Tests / Run on Ubuntu (push) Failing after 4m18s
Tests / Run on Ubuntu (push) Failing after 2m39s
feat: basic functionality implemented
- 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
2025-01-04 17:07:49 +01:00

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)
}