You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ed25519_go112.go 875B

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