| 1 | package jwkscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/ |
| 2 | |
| 3 | import ( |
| 4 | "bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/" |
| 5 | "cryptoscip-go gomod github.com/golang/go/src go1.24.0 crypto/" |
| 6 | "crypto/ecdhscip-go gomod github.com/golang/go/src go1.24.0 `crypto/ecdh`/" |
| 7 | "crypto/ed25519scip-go gomod github.com/golang/go/src go1.24.0 `crypto/ed25519`/" |
| 8 | "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/" |
| 9 | "reflectscip-go gomod github.com/golang/go/src go1.24.0 reflect/" |
| 10 | |
| 11 | "github.com/lestrrat-go/blackmagicscip-go gomod github.com/lestrrat-go/blackmagic v1.0.4 `github.com/lestrrat-go/blackmagic`/" |
| 12 | "github.com/lestrrat-go/jwx/v3/internal/base64scip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/base64`/" |
| 13 | "github.com/lestrrat-go/jwx/v3/jwascip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/" |
| 14 | ) |
| 15 | |
| 16 | func initscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/init().() { |
| 17 | RegisterKeyExporterscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/RegisterKeyExporter().(jwascip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/.OKPscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/OKP().(), KeyExportFuncscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/KeyExportFunc#(okpJWKToRawscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpJWKToRaw().)) |
| 18 | } |
| 19 | |
| 20 | // Mental note: |
| 21 | // |
| 22 | // Curve25519 refers to a particular curve, and is represented in its Montgomery form. |
| 23 | // |
| 24 | // Ed25519 refers to the biratinally equivalent curve of Curve25519, except it's in Edwards form. |
| 25 | // Ed25519 is the name of the curve and the also the signature scheme using that curve. |
| 26 | // The full name of the scheme is Edwards Curve Digital Signature Algorithm, and thus it is |
| 27 | // also referred to as EdDSA. |
| 28 | // |
| 29 | // X25519 refers to the Diffie-Hellman key exchange protocol that uses Cruve25519. |
| 30 | // Because this is an elliptic curve based Diffie Hellman protocol, it is also referred to |
| 31 | // as ECDH. |
| 32 | // |
| 33 | // OKP keys are used to represent private/public pairs of thse elliptic curve |
| 34 | // keys. But note that the name just means Octet Key Pair. |
| 35 | |
| 36 | func (k *okpPublicKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPublicKey#) Importscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPublicKey#Import().(rawKeyIf any) error { |
| 37 | k.muscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPublicKey#mu..Lockscip-go gomod github.com/golang/go/src go1.24.0 sync/RWMutex#Lock().() |
| 38 | defer k.muscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPublicKey#mu..Unlockscip-go gomod github.com/golang/go/src go1.24.0 sync/RWMutex#Unlock().() |
| 39 | |
| 40 | var crv jwascip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/.EllipticCurveAlgorithmscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/EllipticCurveAlgorithm# |
| 41 | switch rawKey := rawKeyIf.(type) { |
| 42 | case ed25519scip-go gomod github.com/golang/go/src go1.24.0 `crypto/ed25519`/.PublicKeyscip-go gomod github.com/golang/go/src go1.24.0 `crypto/ed25519`/PublicKey#: |
| 43 | k.xscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPublicKey#x. = rawKey |
| 44 | crv = jwascip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/.Ed25519scip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/Ed25519().() |
| 45 | k.crvscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPublicKey#crv. = &crv |
| 46 | case *ecdhscip-go gomod github.com/golang/go/src go1.24.0 `crypto/ecdh`/.PublicKeyscip-go gomod github.com/golang/go/src go1.24.0 `crypto/ecdh`/PublicKey#: |
| 47 | k.xscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPublicKey#x. = rawKey.Bytesscip-go gomod github.com/golang/go/src go1.24.0 `crypto/ecdh`/PublicKey#Bytes().() |
| 48 | crv = jwascip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/.X25519scip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/X25519().() |
| 49 | k.crvscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPublicKey#crv. = &crv |
| 50 | default: |
| 51 | return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`unknown key type %T`, rawKeyIf) |
| 52 | } |
| 53 | |
| 54 | return nil |
| 55 | } |
| 56 | |
| 57 | func (k *okpPrivateKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPrivateKey#) Importscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPrivateKey#Import().(rawKeyIf any) error { |
| 58 | k.muscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPrivateKey#mu..Lockscip-go gomod github.com/golang/go/src go1.24.0 sync/RWMutex#Lock().() |
| 59 | defer k.muscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPrivateKey#mu..Unlockscip-go gomod github.com/golang/go/src go1.24.0 sync/RWMutex#Unlock().() |
| 60 | |
| 61 | var crv jwascip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/.EllipticCurveAlgorithmscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/EllipticCurveAlgorithm# |
| 62 | switch rawKey := rawKeyIf.(type) { |
| 63 | case ed25519scip-go gomod github.com/golang/go/src go1.24.0 `crypto/ed25519`/.PrivateKeyscip-go gomod github.com/golang/go/src go1.24.0 `crypto/ed25519`/PrivateKey#: |
| 64 | k.dscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPrivateKey#d. = rawKey.Seedscip-go gomod github.com/golang/go/src go1.24.0 `crypto/ed25519`/PrivateKey#Seed().() |
| 65 | k.xscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPrivateKey#x. = rawKey.Publicscip-go gomod github.com/golang/go/src go1.24.0 `crypto/ed25519`/PrivateKey#Public().().(ed25519scip-go gomod github.com/golang/go/src go1.24.0 `crypto/ed25519`/.PublicKeyscip-go gomod github.com/golang/go/src go1.24.0 `crypto/ed25519`/PublicKey#) //nolint:forcetypeassert |
| 66 | crv = jwascip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/.Ed25519scip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/Ed25519().() |
| 67 | k.crvscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPrivateKey#crv. = &crv |
| 68 | case *ecdhscip-go gomod github.com/golang/go/src go1.24.0 `crypto/ecdh`/.PrivateKeyscip-go gomod github.com/golang/go/src go1.24.0 `crypto/ecdh`/PrivateKey#: |
| 69 | // k.d = rawKey.Seed() |
| 70 | k.dscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPrivateKey#d. = rawKey.Bytesscip-go gomod github.com/golang/go/src go1.24.0 `crypto/ecdh`/PrivateKey#Bytes().() |
| 71 | k.xscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPrivateKey#x. = rawKey.PublicKeyscip-go gomod github.com/golang/go/src go1.24.0 `crypto/ecdh`/PrivateKey#PublicKey().().Bytesscip-go gomod github.com/golang/go/src go1.24.0 `crypto/ecdh`/PublicKey#Bytes().() |
| 72 | crv = jwascip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/.X25519scip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/X25519().() |
| 73 | k.crvscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPrivateKey#crv. = &crv |
| 74 | default: |
| 75 | return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`unknown key type %T`, rawKeyIf) |
| 76 | } |
| 77 | |
| 78 | return nil |
| 79 | } |
| 80 | |
| 81 | func buildOKPPublicKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/buildOKPPublicKey().(alg jwascip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/.EllipticCurveAlgorithmscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/EllipticCurveAlgorithm#, xbuf []byte) (any, error) { |
| 82 | switch alg { |
| 83 | case jwascip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/.Ed25519scip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/Ed25519().(): |
| 84 | return ed25519scip-go gomod github.com/golang/go/src go1.24.0 `crypto/ed25519`/.PublicKeyscip-go gomod github.com/golang/go/src go1.24.0 `crypto/ed25519`/PublicKey#(xbuf), nil |
| 85 | case jwascip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/.X25519scip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/X25519().(): |
| 86 | ret, err := ecdhscip-go gomod github.com/golang/go/src go1.24.0 `crypto/ecdh`/.X25519scip-go gomod github.com/golang/go/src go1.24.0 `crypto/ecdh`/X25519().().NewPublicKeyscip-go gomod github.com/golang/go/src go1.24.0 `crypto/ecdh`/Curve#NewPublicKey().(xbuf) |
| 87 | if err != nil { |
| 88 | return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`failed to parse x25519 public key %x (size %d): %w`, xbuf, len(xbuf), err) |
| 89 | } |
| 90 | return ret, nil |
| 91 | default: |
| 92 | return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`invalid curve algorithm %s`, alg) |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | // Raw returns the EC-DSA public key represented by this JWK |
| 97 | func (k *okpPublicKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPublicKey#) Rawscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPublicKey#Raw().(v any) error { |
| 98 | k.muscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPublicKey#mu..RLockscip-go gomod github.com/golang/go/src go1.24.0 sync/RWMutex#RLock().() |
| 99 | defer k.muscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPublicKey#mu..RUnlockscip-go gomod github.com/golang/go/src go1.24.0 sync/RWMutex#RUnlock().() |
| 100 | |
| 101 | crv, ok := k.Crvscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPublicKey#Crv().() |
| 102 | if !ok { |
| 103 | return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`missing "crv" field`) |
| 104 | } |
| 105 | |
| 106 | pubk, err := buildOKPPublicKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/buildOKPPublicKey().(crv, k.xscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPublicKey#x.) |
| 107 | if err != nil { |
| 108 | return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`jwk.OKPPublicKey: failed to build public key: %w`, err) |
| 109 | } |
| 110 | |
| 111 | if err := blackmagicscip-go gomod github.com/lestrrat-go/blackmagic v1.0.4 `github.com/lestrrat-go/blackmagic`/.AssignIfCompatiblescip-go gomod github.com/lestrrat-go/blackmagic v1.0.4 `github.com/lestrrat-go/blackmagic`/AssignIfCompatible().(v, pubk); err != nil { |
| 112 | return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`jwk.OKPPublicKey: failed to assign to destination variable: %w`, err) |
| 113 | } |
| 114 | return nil |
| 115 | } |
| 116 | |
| 117 | func buildOKPPrivateKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/buildOKPPrivateKey().(alg jwascip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/.EllipticCurveAlgorithmscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/EllipticCurveAlgorithm#, xbuf []byte, dbuf []byte) (any, error) { |
| 118 | if len(dbuf) == 0 { |
| 119 | return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`cannot use empty seed`) |
| 120 | } |
| 121 | switch alg { |
| 122 | case jwascip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/.Ed25519scip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/Ed25519().(): |
| 123 | if len(dbuf) != ed25519scip-go gomod github.com/golang/go/src go1.24.0 `crypto/ed25519`/.SeedSizescip-go gomod github.com/golang/go/src go1.24.0 `crypto/ed25519`/SeedSize. { |
| 124 | return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`ed25519: wrong private key size`) |
| 125 | } |
| 126 | ret := ed25519scip-go gomod github.com/golang/go/src go1.24.0 `crypto/ed25519`/.NewKeyFromSeedscip-go gomod github.com/golang/go/src go1.24.0 `crypto/ed25519`/NewKeyFromSeed().(dbuf) |
| 127 | //nolint:forcetypeassert |
| 128 | if !bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.Equalscip-go gomod github.com/golang/go/src go1.24.0 bytes/Equal().(xbuf, ret.Publicscip-go gomod github.com/golang/go/src go1.24.0 `crypto/ed25519`/PrivateKey#Public().().(ed25519scip-go gomod github.com/golang/go/src go1.24.0 `crypto/ed25519`/.PublicKeyscip-go gomod github.com/golang/go/src go1.24.0 `crypto/ed25519`/PublicKey#)) { |
| 129 | return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`ed25519: invalid x value given d value`) |
| 130 | } |
| 131 | return ret, nil |
| 132 | case jwascip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/.X25519scip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/X25519().(): |
| 133 | ret, err := ecdhscip-go gomod github.com/golang/go/src go1.24.0 `crypto/ecdh`/.X25519scip-go gomod github.com/golang/go/src go1.24.0 `crypto/ecdh`/X25519().().NewPrivateKeyscip-go gomod github.com/golang/go/src go1.24.0 `crypto/ecdh`/Curve#NewPrivateKey().(dbuf) |
| 134 | if err != nil { |
| 135 | return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`x25519: unable to construct x25519 private key from seed: %w`, err) |
| 136 | } |
| 137 | return ret, nil |
| 138 | default: |
| 139 | return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`invalid curve algorithm %s`, alg) |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | var okpConvertibleKeysscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpConvertibleKeys. = []reflectscip-go gomod github.com/golang/go/src go1.24.0 reflect/.Typescip-go gomod github.com/golang/go/src go1.24.0 reflect/Type#{ |
| 144 | reflectscip-go gomod github.com/golang/go/src go1.24.0 reflect/.TypeForscip-go gomod github.com/golang/go/src go1.24.0 reflect/TypeFor().[OKPPrivateKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/OKPPrivateKey#](), |
| 145 | reflectscip-go gomod github.com/golang/go/src go1.24.0 reflect/.TypeForscip-go gomod github.com/golang/go/src go1.24.0 reflect/TypeFor().[OKPPublicKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/OKPPublicKey#](), |
| 146 | } |
| 147 | |
| 148 | // This is half baked. I think it will blow up if we used ecdh.* keys and/or x25519 keys |
| 149 | func okpJWKToRawscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpJWKToRaw().(key Keyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Key#, _ any /* this is unused because this is half baked */) (any, error) { |
| 150 | extracted, err := extractEmbeddedKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/extractEmbeddedKey().(key, okpConvertibleKeysscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpConvertibleKeys.) |
| 151 | if err != nil { |
| 152 | return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`jwk.OKP: failed to extract embedded key: %w`, err) |
| 153 | } |
| 154 | |
| 155 | switch key := extracted.(type) { |
| 156 | case OKPPrivateKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/OKPPrivateKey#: |
| 157 | locker, ok := key.(rlockerscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/rlocker#) |
| 158 | if ok { |
| 159 | locker.rlockscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/rlocker#rlock.() |
| 160 | defer locker.runlockscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/rlocker#runlock.() |
| 161 | } |
| 162 | |
| 163 | crv, ok := key.Crvscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/OKPPrivateKey#Crv.() |
| 164 | if !ok { |
| 165 | return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`missing "crv" field`) |
| 166 | } |
| 167 | |
| 168 | x, ok := key.Xscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/OKPPrivateKey#X.() |
| 169 | if !ok { |
| 170 | return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`missing "x" field`) |
| 171 | } |
| 172 | |
| 173 | d, ok := key.Dscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/OKPPrivateKey#D.() |
| 174 | if !ok { |
| 175 | return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`missing "d" field`) |
| 176 | } |
| 177 | |
| 178 | privk, err := buildOKPPrivateKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/buildOKPPrivateKey().(crv, x, d) |
| 179 | if err != nil { |
| 180 | return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`jwk.OKPPrivateKey: failed to build private key: %w`, err) |
| 181 | } |
| 182 | return privk, nil |
| 183 | case OKPPublicKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/OKPPublicKey#: |
| 184 | locker, ok := key.(rlockerscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/rlocker#) |
| 185 | if ok { |
| 186 | locker.rlockscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/rlocker#rlock.() |
| 187 | defer locker.runlockscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/rlocker#runlock.() |
| 188 | } |
| 189 | |
| 190 | crv, ok := key.Crvscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/OKPPublicKey#Crv.() |
| 191 | if !ok { |
| 192 | return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`missing "crv" field`) |
| 193 | } |
| 194 | |
| 195 | x, ok := key.Xscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/OKPPublicKey#X.() |
| 196 | if !ok { |
| 197 | return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`missing "x" field`) |
| 198 | } |
| 199 | pubk, err := buildOKPPublicKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/buildOKPPublicKey().(crv, x) |
| 200 | if err != nil { |
| 201 | return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`jwk.OKPPublicKey: failed to build public key: %w`, err) |
| 202 | } |
| 203 | return pubk, nil |
| 204 | default: |
| 205 | return nil, ContinueErrorscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/ContinueError().() |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | func makeOKPPublicKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/makeOKPPublicKey().(src Keyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Key#) (Keyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Key#, error) { |
| 210 | newKey := newOKPPublicKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/newOKPPublicKey().() |
| 211 | |
| 212 | // Iterate and copy everything except for the bits that should not be in the public key |
| 213 | for _, k := range src.Keysscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Key#Keys.() { |
| 214 | switch k { |
| 215 | case OKPDKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/OKPDKey.: |
| 216 | continue |
| 217 | default: |
| 218 | var v any |
| 219 | if err := src.Getscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Key#Get.(k, &v); err != nil { |
| 220 | return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`failed to get field %q: %w`, k, err) |
| 221 | } |
| 222 | |
| 223 | if err := newKey.Setscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPublicKey#Set().(k, v); err != nil { |
| 224 | return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`failed to set field %q: %w`, k, err) |
| 225 | } |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | return newKey, nil |
| 230 | } |
| 231 | |
| 232 | func (k *okpPrivateKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPrivateKey#) PublicKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPrivateKey#PublicKey().() (Keyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Key#, error) { |
| 233 | return makeOKPPublicKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/makeOKPPublicKey().(k) |
| 234 | } |
| 235 | |
| 236 | func (k *okpPublicKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPublicKey#) PublicKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPublicKey#PublicKey().() (Keyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Key#, error) { |
| 237 | return makeOKPPublicKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/makeOKPPublicKey().(k) |
| 238 | } |
| 239 | |
| 240 | func okpThumbprintscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpThumbprint().(hash cryptoscip-go gomod github.com/golang/go/src go1.24.0 crypto/.Hashscip-go gomod github.com/golang/go/src go1.24.0 crypto/Hash#, crv, x string) []byte { |
| 241 | h := hash.Newscip-go gomod github.com/golang/go/src go1.24.0 crypto/Hash#New().() |
| 242 | fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Fprintscip-go gomod github.com/golang/go/src go1.24.0 fmt/Fprint().(h, `{"crv":"`) |
| 243 | fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Fprintscip-go gomod github.com/golang/go/src go1.24.0 fmt/Fprint().(h, crv) |
| 244 | fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Fprintscip-go gomod github.com/golang/go/src go1.24.0 fmt/Fprint().(h, `","kty":"OKP","x":"`) |
| 245 | fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Fprintscip-go gomod github.com/golang/go/src go1.24.0 fmt/Fprint().(h, x) |
| 246 | fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Fprintscip-go gomod github.com/golang/go/src go1.24.0 fmt/Fprint().(h, `"}`) |
| 247 | return h.Sumscip-go gomod github.com/golang/go/src go1.24.0 hash/Hash#Sum().(nil) |
| 248 | } |
| 249 | |
| 250 | // Thumbprint returns the JWK thumbprint using the indicated |
| 251 | // hashing algorithm, according to RFC 7638 / 8037 |
| 252 | func (k okpPublicKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPublicKey#) Thumbprintscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPublicKey#Thumbprint().(hash cryptoscip-go gomod github.com/golang/go/src go1.24.0 crypto/.Hashscip-go gomod github.com/golang/go/src go1.24.0 crypto/Hash#) ([]byte, error) { |
| 253 | k.muscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPublicKey#mu..RLockscip-go gomod github.com/golang/go/src go1.24.0 sync/RWMutex#RLock().() |
| 254 | defer k.muscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPublicKey#mu..RUnlockscip-go gomod github.com/golang/go/src go1.24.0 sync/RWMutex#RUnlock().() |
| 255 | |
| 256 | crv, ok := k.Crvscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPublicKey#Crv().() |
| 257 | if !ok { |
| 258 | return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`missing "crv" field`) |
| 259 | } |
| 260 | return okpThumbprintscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpThumbprint().( |
| 261 | hash, |
| 262 | crv.Stringscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/EllipticCurveAlgorithm#String().(), |
| 263 | base64scip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/base64`/.EncodeToStringscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/base64`/EncodeToString().(k.xscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPublicKey#x.), |
| 264 | ), nil |
| 265 | } |
| 266 | |
| 267 | // Thumbprint returns the JWK thumbprint using the indicated |
| 268 | // hashing algorithm, according to RFC 7638 / 8037 |
| 269 | func (k okpPrivateKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPrivateKey#) Thumbprintscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPrivateKey#Thumbprint().(hash cryptoscip-go gomod github.com/golang/go/src go1.24.0 crypto/.Hashscip-go gomod github.com/golang/go/src go1.24.0 crypto/Hash#) ([]byte, error) { |
| 270 | k.muscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPrivateKey#mu..RLockscip-go gomod github.com/golang/go/src go1.24.0 sync/RWMutex#RLock().() |
| 271 | defer k.muscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPrivateKey#mu..RUnlockscip-go gomod github.com/golang/go/src go1.24.0 sync/RWMutex#RUnlock().() |
| 272 | |
| 273 | crv, ok := k.Crvscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPrivateKey#Crv().() |
| 274 | if !ok { |
| 275 | return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`missing "crv" field`) |
| 276 | } |
| 277 | |
| 278 | return okpThumbprintscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpThumbprint().( |
| 279 | hash, |
| 280 | crv.Stringscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/EllipticCurveAlgorithm#String().(), |
| 281 | base64scip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/base64`/.EncodeToStringscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/base64`/EncodeToString().(k.xscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPrivateKey#x.), |
| 282 | ), nil |
| 283 | } |
| 284 | |
| 285 | func validateOKPKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/validateOKPKey().(key interface { |
| 286 | Crv() (jwascip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/.EllipticCurveAlgorithmscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/EllipticCurveAlgorithm#, bool) |
| 287 | X() ([]byte, bool) |
| 288 | }) error { |
| 289 | if v, ok := key.Crv(); !ok || v == jwascip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/.InvalidEllipticCurvescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/InvalidEllipticCurve().() { |
| 290 | return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`invalid curve algorithm`) |
| 291 | } |
| 292 | |
| 293 | if v, ok := key.X(); !ok || len(v) == 0 { |
| 294 | return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`missing "x" field`) |
| 295 | } |
| 296 | |
| 297 | if priv, ok := key.(keyWithDscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/keyWithD#); ok { |
| 298 | if d, ok := priv.Dscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/keyWithD#D.(); !ok || len(d) == 0 { |
| 299 | return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`missing "d" field`) |
| 300 | } |
| 301 | } |
| 302 | return nil |
| 303 | } |
| 304 | |
| 305 | func (k *okpPublicKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPublicKey#) Validatescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPublicKey#Validate().() error { |
| 306 | k.muscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPublicKey#mu..RLockscip-go gomod github.com/golang/go/src go1.24.0 sync/RWMutex#RLock().() |
| 307 | defer k.muscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPublicKey#mu..RUnlockscip-go gomod github.com/golang/go/src go1.24.0 sync/RWMutex#RUnlock().() |
| 308 | if err := validateOKPKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/validateOKPKey().(k); err != nil { |
| 309 | return NewKeyValidationErrorscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/NewKeyValidationError().(fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`jwk.OKPPublicKey: %w`, err)) |
| 310 | } |
| 311 | return nil |
| 312 | } |
| 313 | |
| 314 | func (k *okpPrivateKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPrivateKey#) Validatescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPrivateKey#Validate().() error { |
| 315 | k.muscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPrivateKey#mu..RLockscip-go gomod github.com/golang/go/src go1.24.0 sync/RWMutex#RLock().() |
| 316 | defer k.muscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPrivateKey#mu..RUnlockscip-go gomod github.com/golang/go/src go1.24.0 sync/RWMutex#RUnlock().() |
| 317 | if err := validateOKPKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/validateOKPKey().(k); err != nil { |
| 318 | return NewKeyValidationErrorscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/NewKeyValidationError().(fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`jwk.OKPPrivateKey: %w`, err)) |
| 319 | } |
| 320 | return nil |
| 321 | } |