Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Nov 13, 2023. It is now read-only.

Latest commit

 

History

History
History
executable file
·
44 lines (36 loc) · 1.21 KB

File metadata and controls

executable file
·
44 lines (36 loc) · 1.21 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python
""" Benchmark verifying a JWT """
# pylint: disable=wrong-import-position,wrong-import-order
from datetime import timedelta
from bench.unitbench import Benchmark
from test.fixtures import payload, priv_keys, pub_keys, algs
from bench.reporter import Reporter
import python_jwt as jwt
class VerifyTokenBenchmark(Benchmark):
""" Verify JWT benchmark """
def input(self):
""" Name of benchmark """
return ["Verify Token"]
def repeats(self):
""" Iterations """
return 1000
#pylint: disable=W0621
def make_bench_verify_token(alg):
""" Return function which will generate token for particular algorithm """
privk = priv_keys[alg]['python-jwt']
token = jwt.generate_jwt(payload, privk, alg, timedelta(days=1))
def f(_):
""" Verify token """
pubk = pub_keys[alg]['python-jwt']
jwt.verify_jwt(token, pubk, [alg])
return f
for alg in algs:
name = 'bench_' + alg
f = make_bench_verify_token(alg)
f.__name__ = name
setattr(VerifyTokenBenchmark, name, f)
if __name__ == "__main__":
#pylint: disable=W0402
import string
string.capwords = lambda x: x
VerifyTokenBenchmark().run(reporter=Reporter())
Morty Proxy This is a proxified and sanitized view of the page, visit original site.