-
-
Notifications
You must be signed in to change notification settings - Fork 511
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plugin: build tag EncodeX25519Recipient which uses crypto/ecdh
- Loading branch information
1 parent
9fd564d
commit f1f96c2
Showing
2 changed files
with
24 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2023 The age Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
//go:build go1.20 | ||
|
||
package plugin | ||
|
||
import ( | ||
"crypto/ecdh" | ||
"fmt" | ||
|
||
"filippo.io/age/internal/bech32" | ||
) | ||
|
||
// 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()) | ||
} |