Verify implements token verification for the SigningMethod. For this verify method, key must be an ed25519.PublicKey
(signingString string, sig []byte, key any)
| 34 | // Verify implements token verification for the SigningMethod. |
| 35 | // For this verify method, key must be an ed25519.PublicKey |
| 36 | func (m *SigningMethodEd25519) Verify(signingString string, sig []byte, key any) error { |
| 37 | var ed25519Key ed25519.PublicKey |
| 38 | var ok bool |
| 39 | |
| 40 | if ed25519Key, ok = key.(ed25519.PublicKey); !ok { |
| 41 | return newError("Ed25519 verify expects ed25519.PublicKey", ErrInvalidKeyType) |
| 42 | } |
| 43 | |
| 44 | if len(ed25519Key) != ed25519.PublicKeySize { |
| 45 | return ErrInvalidKey |
| 46 | } |
| 47 | |
| 48 | // Verify the signature |
| 49 | if !ed25519.Verify(ed25519Key, []byte(signingString), sig) { |
| 50 | return ErrEd25519Verification |
| 51 | } |
| 52 | |
| 53 | return nil |
| 54 | } |
| 55 | |
| 56 | // Sign implements token signing for the SigningMethod. |
| 57 | // For this signing method, key must be an ed25519.PrivateKey |