mirror of
https://github.com/pomerium/pomerium.git
synced 2025-08-02 16:30:17 +02:00
hpke: move published public keys to a new endpoint (#4044)
This commit is contained in:
parent
74463c5468
commit
0f295d4a63
13 changed files with 136 additions and 71 deletions
|
@ -97,6 +97,16 @@ type PublicKey struct {
|
|||
key kem.PublicKey
|
||||
}
|
||||
|
||||
// PublicKeyFromBytes converts raw bytes into a public key.
|
||||
func PublicKeyFromBytes(raw []byte) (*PublicKey, error) {
|
||||
key, err := kemID.Scheme().UnmarshalBinaryPublicKey(raw)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &PublicKey{key: key}, nil
|
||||
}
|
||||
|
||||
// PublicKeyFromString converts a string into a public key.
|
||||
func PublicKeyFromString(raw string) (*PublicKey, error) {
|
||||
bs, err := decode(raw)
|
||||
|
@ -128,6 +138,20 @@ func (key *PublicKey) Equals(other *PublicKey) bool {
|
|||
return key.key.Equal(other.key)
|
||||
}
|
||||
|
||||
// Bytes returns the public key as raw bytes.
|
||||
func (key *PublicKey) Bytes() []byte {
|
||||
if key == nil || key.key == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
bs, err := key.key.MarshalBinary()
|
||||
if err != nil {
|
||||
// this should not happen
|
||||
panic(fmt.Sprintf("failed to marshal public HPKE key: %v", err))
|
||||
}
|
||||
return bs
|
||||
}
|
||||
|
||||
// MarshalJSON returns the JSON Web Key representation of the public key.
|
||||
func (key *PublicKey) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(JWK{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue