mirror of https://github.com/golang-jwt/jwt.git
use pre-parsed rsa key for rsa benchmark and make sure signing actually succeeds
This commit is contained in:
parent
c0c67af490
commit
e430b188c0
|
@ -178,7 +178,9 @@ func benchmarkSigning(b *testing.B, method jwt.SigningMethod, key interface{}) {
|
||||||
t := jwt.New(method)
|
t := jwt.New(method)
|
||||||
b.RunParallel(func(pb *testing.PB) {
|
b.RunParallel(func(pb *testing.PB) {
|
||||||
for pb.Next() {
|
for pb.Next() {
|
||||||
t.SignedString(key)
|
if _, err := t.SignedString(key); err != nil {
|
||||||
|
b.Fatal(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
24
rsa_test.go
24
rsa_test.go
|
@ -144,13 +144,31 @@ func TestRSAKeyParsing(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkRS256Signing(b *testing.B) {
|
func BenchmarkRS256Signing(b *testing.B) {
|
||||||
benchmarkSigning(b, jwt.SigningMethodRS256, hmacTestKey)
|
key, _ := ioutil.ReadFile("test/sample_key")
|
||||||
|
parsedKey, err := jwt.ParseRSAPrivateKeyFromPEM(key)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
benchmarkSigning(b, jwt.SigningMethodRS256, parsedKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkRS384Signing(b *testing.B) {
|
func BenchmarkRS384Signing(b *testing.B) {
|
||||||
benchmarkSigning(b, jwt.SigningMethodRS384, hmacTestKey)
|
key, _ := ioutil.ReadFile("test/sample_key")
|
||||||
|
parsedKey, err := jwt.ParseRSAPrivateKeyFromPEM(key)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
benchmarkSigning(b, jwt.SigningMethodRS384, parsedKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkRS512Signing(b *testing.B) {
|
func BenchmarkRS512Signing(b *testing.B) {
|
||||||
benchmarkSigning(b, jwt.SigningMethodRS512, hmacTestKey)
|
key, _ := ioutil.ReadFile("test/sample_key")
|
||||||
|
parsedKey, err := jwt.ParseRSAPrivateKeyFromPEM(key)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
benchmarkSigning(b, jwt.SigningMethodRS512, parsedKey)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue