1+ //go:build go1.27
2+
13package webauthncose
24
35import (
46 "crypto"
57 "fmt"
8+
9+ "github.com/go-webauthn/webauthn/protocol/webauthncbor"
610)
711
812// AKPPublicKeyData is a credential public key of the AKP (Algorithm Key Pair) key type, which carries its key
@@ -29,9 +33,6 @@ func (k *AKPPublicKeyData) Verify(data []byte, sig []byte) (bool, error) {
2933
3034// ToPublicKey converts the AKPPublicKeyData to the standard library key of the algorithm it names, which for the
3135// ML-DSA parameter sets is a *[crypto/mldsa.PublicKey].
32- //
33- // The concrete type is not named in the signature because the package which declares it is only present from Go
34- // 1.27, which is also the point from which this returns a key at all.
3536func (k * AKPPublicKeyData ) ToPublicKey () (key crypto.PublicKey , err error ) {
3637 if err = validateAKPPublicKey (k ); err != nil {
3738 return nil , err
@@ -40,6 +41,48 @@ func (k *AKPPublicKeyData) ToPublicKey() (key crypto.PublicKey, err error) {
4041 return mldsaPublicKey (COSEAlgorithmIdentifier (k .Algorithm ), k .PublicKey )
4142}
4243
44+ // parseAKPPublicKey decodes a credential public key of the AKP key type. It is the arm [ParsePublicKey] delegates
45+ // that key type to, so that the parser itself does not name a type which only exists on a build that can verify
46+ // with it.
47+ func parseAKPPublicKey (pk PublicKeyData , keyBytes []byte ) (key any , err error ) {
48+ var a AKPPublicKeyData
49+
50+ if err = webauthncbor .Unmarshal (keyBytes , & a ); err != nil {
51+ return nil , err
52+ }
53+
54+ a .PublicKeyData = pk
55+
56+ if err = validateAKPPublicKey (& a ); err != nil {
57+ return nil , err
58+ }
59+
60+ return a , nil
61+ }
62+
63+ // verifyAKPSignature is the arm [VerifySignature] delegates a key of the AKP key type to. A key of any other type
64+ // has already been handled by its caller, so anything reaching here that is not one is a key this library does not
65+ // verify with.
66+ func verifyAKPSignature (key any , data []byte , sig []byte ) (bool , error ) {
67+ k , ok := key .(AKPPublicKeyData )
68+ if ! ok {
69+ return false , ErrUnsupportedKey
70+ }
71+
72+ return k .Verify (data , sig )
73+ }
74+
75+ // displayAKPPublicKey is the arm [DisplayPublicKey] delegates a key of the AKP key type to. A nil encoding and a
76+ // nil error report that the key is not an AKP key at all, which the caller renders as a key type it cannot display.
77+ func displayAKPPublicKey (key any ) (der []byte , err error ) {
78+ k , ok := key .(AKPPublicKeyData )
79+ if ! ok {
80+ return nil , nil
81+ }
82+
83+ return mldsaMarshalPublicKey (COSEAlgorithmIdentifier (k .Algorithm ), k .PublicKey )
84+ }
85+
4386// validateAKPPublicKey checks that a credential public key of type AKP names an algorithm this library verifies
4487// with, and carries key material that algorithm accepts.
4588//
0 commit comments