Verify implements the Verify method from SigningMethod. For this signing method, must be a []byte.
(raw []byte, signature Signature, key interface{})
| 45 | // Verify implements the Verify method from SigningMethod. |
| 46 | // For this signing method, must be a []byte. |
| 47 | func (m *SigningMethodHMAC) Verify(raw []byte, signature Signature, key interface{}) error { |
| 48 | keyBytes, ok := key.([]byte) |
| 49 | if !ok { |
| 50 | return ErrInvalidKey |
| 51 | } |
| 52 | hasher := hmac.New(m.Hash.New, keyBytes) |
| 53 | hasher.Write(raw) |
| 54 | if hmac.Equal(signature, hasher.Sum(nil)) { |
| 55 | return nil |
| 56 | } |
| 57 | return ErrSignatureInvalid |
| 58 | } |
| 59 | |
| 60 | // Sign implements the Sign method from SigningMethod for this signing method. |
| 61 | // Key must be a []byte. |