Skip to content

Commit

Permalink
plugin: build tag EncodeX25519Recipient which uses crypto/ecdh
Browse files Browse the repository at this point in the history
  • Loading branch information
FiloSottile committed Aug 6, 2023
1 parent 9fd564d commit f1f96c2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
11 changes: 0 additions & 11 deletions plugin/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package plugin

import (
"crypto/ecdh"
"fmt"
"strings"

Expand Down Expand Up @@ -54,13 +53,3 @@ 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())
}
24 changes: 24 additions & 0 deletions plugin/encode_go1.20.go
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())
}

0 comments on commit f1f96c2

Please sign in to comment.