mirror of
https://github.com/FiloSottile/age.git
synced 2025-12-23 05:25:14 +00:00
plugin: add EncodeX25519Recipient
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"crypto/ecdh"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
@@ -53,3 +54,13 @@ func ParseRecipient(s string) (name string, data []byte, err error) {
|
||||
name = strings.TrimPrefix(hrp, "age1")
|
||||
return name, data, nil
|
||||
}
|
||||
|
||||
// EncodeX25519Recipient encodes a native X25519 recipient from a
|
||||
// [crypto/ecdh.X25519] public key. It's meant for plugins that implement
|
||||
// identities that are compatible with native recipients.
|
||||
func EncodeX25519Recipient(pk *ecdh.PublicKey) (string, error) {
|
||||
if pk.Curve() != ecdh.X25519() {
|
||||
return "", fmt.Errorf("wrong ecdh Curve")
|
||||
}
|
||||
return bech32.Encode("age", pk.Bytes())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user