Documentation ¶
Overview ¶
Package cose contains the subset of the CBOR Object Signing and Encryption (COSE) standard needed for webauthn.
Index ¶
- Variables
- type Algorithm
- type Curve
- type ECDSAPublicKey
- func (key ECDSAPublicKey) Algorithm() Algorithm
- func (key ECDSAPublicKey) CryptoPublicKey() crypto.PublicKey
- func (key ECDSAPublicKey) Marshal() ([]byte, error)
- func (key ECDSAPublicKey) RawX962ECC() RawX962ECC
- func (ECDSAPublicKey) Type() KeyType
- func (key ECDSAPublicKey) Verify(data, signature []byte) error
- type EdDSAPublicKey
- type KeyType
- type PublicKey
- type RSAPublicKey
- type RawX962ECC
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidPublicKey = errors.New("invalid public key") ErrInvalidSignature = errors.New("invalid signature") ErrUnsupportedAlgorithm = errors.New("unsupported COSE algorithm") ErrUnsupportedCurve = errors.New("unsupported elliptic curve") ErrUnsupportedKeyType = errors.New("unsupported COSE key type") )
Errors
Functions ¶
This section is empty.
Types ¶
type Algorithm ¶
type Algorithm int
The Algorithm identifies a cryptographic algorithm as defined in https://www.iana.org/assignments/cose/cose.xhtml#algorithms.
const ( // AlgorithmRS1 indicates RSASSA-PKCS1-v1_5 with SHA-1. AlgorithmRS1 Algorithm = -65535 // AlgorithmRS512 indicates RSASSA-PKCS1-v1_5 with SHA-512. AlgorithmRS512 Algorithm = -259 // AlgorithmRS384 indicates RSASSA-PKCS1-v1_5 with SHA-384. AlgorithmRS384 Algorithm = -258 // AlgorithmRS256 indicates RSASSA-PKCS1-v1_5 with SHA-256. AlgorithmRS256 Algorithm = -257 // AlgorithmPS512 indicates RSASSA-PSS with SHA-512. AlgorithmPS512 Algorithm = -39 // AlgorithmPS384 indicates RSASSA-PSS with SHA-384. AlgorithmPS384 Algorithm = -38 // AlgorithmPS256 indicates RSASSA-PSS with SHA-256. AlgorithmPS256 Algorithm = -37 // AlgorithmES512 indicates ECDSA w/ SHA-512. AlgorithmES512 Algorithm = -36 // AlgorithmES384 indicates ECDSA w/ SHA-384. AlgorithmES384 Algorithm = -35 // AlgorithmEdDSA indicates EdDSA. AlgorithmEdDSA Algorithm = -8 // AlgorithmES256 indicates ECDSA w/ SHA-256. AlgorithmES256 Algorithm = -7 )
func (Algorithm) X509SignatureAlgorithm ¶
func (alg Algorithm) X509SignatureAlgorithm() x509.SignatureAlgorithm
X509SignatureAlgorithm returns the corresponding x509.SignatureAlgorithm for the Algorithm.
type Curve ¶
type Curve int
Curve indicates the cryptographic elliptic curve used by an algorithm as defined in: https://www.iana.org/assignments/cose/cose.xhtml#elliptic-curves
const ( CurveP256 Curve = iota + 1 CurveP384 CurveP521 CurveX25519 CurveX448 CurveEd25519 CurveEd448 CurveSECP256K1 )
Elliptic curves
func (Curve) EllipticCurve ¶
EllipticCurve returns the elliptic.Curve for the given Curve.
type ECDSAPublicKey ¶
type ECDSAPublicKey struct {
// contains filtered or unexported fields
}
An ECDSAPublicKey is a public key using ECDSA.
func NewECDSAPublicKey ¶
func NewECDSAPublicKey( algorithm Algorithm, publicKey ecdsa.PublicKey, ) (*ECDSAPublicKey, error)
NewECDSAPublicKey creates a new ECDSAPublicKey from an existing key.
func UnmarshalECDSAPublicKey ¶
func UnmarshalECDSAPublicKey(raw []byte) (key *ECDSAPublicKey, remaining []byte, err error)
UnmarshalECDSAPublicKey unmarshals an ECDSA key using the COSE_Key format.
func (ECDSAPublicKey) Algorithm ¶
func (key ECDSAPublicKey) Algorithm() Algorithm
Algorithm returns the ECDSA algorithm.
func (ECDSAPublicKey) CryptoPublicKey ¶
func (key ECDSAPublicKey) CryptoPublicKey() crypto.PublicKey
CryptoPublicKey returns the crypto ECDSA public key.
func (ECDSAPublicKey) Marshal ¶
func (key ECDSAPublicKey) Marshal() ([]byte, error)
Marshal marshals the key.
func (ECDSAPublicKey) RawX962ECC ¶
func (key ECDSAPublicKey) RawX962ECC() RawX962ECC
RawX962ECC returns the RawX962ECC formatted public key.
func (ECDSAPublicKey) Verify ¶
func (key ECDSAPublicKey) Verify(data, signature []byte) error
Verify returns true if the signature is a valid ECDSA signature for data.
type EdDSAPublicKey ¶
type EdDSAPublicKey struct {
// contains filtered or unexported fields
}
An EdDSAPublicKey is a public key using EdDSA.
func UnmarshalEdDSAPublicKey ¶
func UnmarshalEdDSAPublicKey(raw []byte) (key *EdDSAPublicKey, remaining []byte, err error)
UnmarshalEdDSAPublicKey unmarshals an EdDSA key using the COSE_Key format.
func (EdDSAPublicKey) Algorithm ¶
func (EdDSAPublicKey) Algorithm() Algorithm
Algorithm returns EdDSA.
func (EdDSAPublicKey) CryptoPublicKey ¶
func (key EdDSAPublicKey) CryptoPublicKey() crypto.PublicKey
CryptoPublicKey returns the crypto EdDSA public key.
func (EdDSAPublicKey) Marshal ¶
func (key EdDSAPublicKey) Marshal() ([]byte, error)
Marshal marshals the key.
func (EdDSAPublicKey) Verify ¶
func (key EdDSAPublicKey) Verify(data, signature []byte) error
Verify returns true if the signature is a valid EdDSA signature for data.
type PublicKey ¶
type PublicKey interface { Algorithm() Algorithm CryptoPublicKey() crypto.PublicKey Marshal() ([]byte, error) Type() KeyType Verify(data, signature []byte) error }
A PublicKey is a credential public key.
type RSAPublicKey ¶
type RSAPublicKey struct {
// contains filtered or unexported fields
}
An RSAPublicKey is a public key using RSA.
func NewRSAPublicKey ¶
func NewRSAPublicKey( algorithm Algorithm, publicKey rsa.PublicKey, ) (*RSAPublicKey, error)
NewRSAPublicKey creates a new RSAPublicKey.
func UnmarshalRSAPublicKey ¶
func UnmarshalRSAPublicKey(raw []byte) (key *RSAPublicKey, remaining []byte, err error)
UnmarshalRSAPublicKey unmarshals an RSA key using the COSE_Key format.
func (RSAPublicKey) Algorithm ¶
func (key RSAPublicKey) Algorithm() Algorithm
Algorithm returns the RSA algorithm.
func (RSAPublicKey) CryptoPublicKey ¶
func (key RSAPublicKey) CryptoPublicKey() crypto.PublicKey
CryptoPublicKey returns the crypto RSA public key.
func (RSAPublicKey) Marshal ¶
func (key RSAPublicKey) Marshal() ([]byte, error)
Marshal marshals the key.
func (RSAPublicKey) Verify ¶
func (key RSAPublicKey) Verify(data, signature []byte) error
Verify returns true if the signature is a valid RSA signature for data.
type RawX962ECC ¶
type RawX962ECC [65]byte
RawX962ECC represents the Raw ANSI X9.62 public key format for ALG_KEY_ECC_X962_RAW as defined in: https://fidoalliance.org/specs/fido-v2.0-id-20180227/fido-registry-v2.0-id-20180227.html#public-key-representation-formats
func NewRawX962ECC ¶
func NewRawX962ECC(x, y [32]byte) RawX962ECC
NewRawX962ECC creates a new RawX962ECC.