1// +build !go1.13
2
3package webauthncose
4
5import (
6	"crypto/x509/pkix"
7	"encoding/asn1"
8
9	"golang.org/x/crypto/ed25519"
10)
11
12var oidSignatureEd25519 = asn1.ObjectIdentifier{1, 3, 101, 112}
13
14type pkixPublicKey struct {
15	Algo      pkix.AlgorithmIdentifier
16	BitString asn1.BitString
17}
18
19// marshalEd25519PublicKey is a backport of the functionality introduced in
20// Go v1.13.
21// Ref: https://golang.org/doc/go1.13#crypto/ed25519
22// Ref: https://golang.org/doc/go1.13#crypto/x509
23func marshalEd25519PublicKey(pub ed25519.PublicKey) ([]byte, error) {
24	publicKeyBytes := pub
25	var publicKeyAlgorithm pkix.AlgorithmIdentifier
26	publicKeyAlgorithm.Algorithm = oidSignatureEd25519
27
28	pkix := pkixPublicKey{
29		Algo: publicKeyAlgorithm,
30		BitString: asn1.BitString{
31			Bytes:     publicKeyBytes,
32			BitLength: 8 * len(publicKeyBytes),
33		},
34	}
35
36	ret, _ := asn1.Marshal(pkix)
37	return ret, nil
38}
39