package jwt
import (
"crypto"
"crypto/ed25519"
"crypto/x509"
"encoding/pem"
"errors"
)
var (
ErrNotEdPrivateKey = errors .New ("key is not a valid Ed25519 private key" )
ErrNotEdPublicKey = errors .New ("key is not a valid Ed25519 public key" )
)
func ParseEdPrivateKeyFromPEM (key []byte ) (crypto .PrivateKey , error ) {
var err error
var block *pem .Block
if block , _ = pem .Decode (key ); block == nil {
return nil , ErrKeyMustBePEMEncoded
}
var parsedKey interface {}
if parsedKey , err = x509 .ParsePKCS8PrivateKey (block .Bytes ); err != nil {
return nil , err
}
var pkey ed25519 .PrivateKey
var ok bool
if pkey , ok = parsedKey .(ed25519 .PrivateKey ); !ok {
return nil , ErrNotEdPrivateKey
}
return pkey , nil
}
func ParseEdPublicKeyFromPEM (key []byte ) (crypto .PublicKey , error ) {
var err error
var block *pem .Block
if block , _ = pem .Decode (key ); block == nil {
return nil , ErrKeyMustBePEMEncoded
}
var parsedKey interface {}
if parsedKey , err = x509 .ParsePKIXPublicKey (block .Bytes ); err != nil {
return nil , err
}
var pkey ed25519 .PublicKey
var ok bool
if pkey , ok = parsedKey .(ed25519 .PublicKey ); !ok {
return nil , ErrNotEdPublicKey
}
return pkey , nil
}
The pages are generated with Golds v0.6.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds .