write -> sum
diff --git a/crypto/hmac.go b/crypto/hmac.go
index a9afb1f..1cb7f6e 100644
--- a/crypto/hmac.go
+++ b/crypto/hmac.go
@@ -50,7 +50,8 @@
return ErrInvalidKey
}
hasher := hmac.New(m.Hash.New, keyBytes)
- if hmac.Equal(signature, hasher.Sum(raw)) {
+ hasher.Write(raw)
+ if hmac.Equal(signature, hasher.Sum(nil)) {
return nil
}
return ErrSignatureInvalid
@@ -64,7 +65,8 @@
return nil, ErrInvalidKey
}
hasher := hmac.New(m.Hash.New, keyBytes)
- return Signature(hasher.Sum(data)), nil
+ hasher.Write(data)
+ return Signature(hasher.Sum(nil)), nil
}
// Hasher implements the SigningMethod interface.
diff --git a/crypto/hmac_test.go b/crypto/hmac_test.go
index ff46861..129e293 100644
--- a/crypto/hmac_test.go
+++ b/crypto/hmac_test.go
@@ -1,10 +1,11 @@
package crypto
// import (
-// "github.com/dgrijalva/jwt-go"
// "io/ioutil"
// "strings"
// "testing"
+
+// "github.com/SermoDigital/jose/jws"
// )
// var hmacTestData = []struct {
@@ -66,7 +67,7 @@
// for _, data := range hmacTestData {
// if data.valid {
// parts := strings.Split(data.tokenString, ".")
-// method := jwt.GetSigningMethod(data.alg)
+// method := jws.GetSigningMethod(data.alg)
// sig, err := method.Sign(strings.Join(parts[0:2], "."), hmacTestKey)
// if err != nil {
// t.Errorf("[%v] Error signing token: %v", data.name, err)
@@ -78,14 +79,14 @@
// }
// }
-// func BenchmarkHS256Signing(b *testing.B) {
-// benchmarkSigning(b, jwt.SigningMethodHS256, hmacTestKey)
-// }
+// // func BenchmarkHS256Signing(b *testing.B) {
+// // benchmarkSigning(b, jwt.SigningMethodHS256, hmacTestKey)
+// // }
-// func BenchmarkHS384Signing(b *testing.B) {
-// benchmarkSigning(b, jwt.SigningMethodHS384, hmacTestKey)
-// }
+// // func BenchmarkHS384Signing(b *testing.B) {
+// // benchmarkSigning(b, jwt.SigningMethodHS384, hmacTestKey)
+// // }
-// func BenchmarkHS512Signing(b *testing.B) {
-// benchmarkSigning(b, jwt.SigningMethodHS512, hmacTestKey)
-// }
+// // func BenchmarkHS512Signing(b *testing.B) {
+// // benchmarkSigning(b, jwt.SigningMethodHS512, hmacTestKey)
+// // }