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].get('default', priv_key) token = jwt.generate_jwt(payload, privk, alg, timedelta(days=1)) def f(_): """ Verify token """ pubk = pub_keys[alg].get('default', pub_key) 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())
#!/usr/bin/env python """ Benchmark loading an RSA key from a PEM string """ # pylint: disable=wrong-import-position,wrong-import-order from bench.unitbench import Benchmark from test.fixtures import priv_pem, to_bytes_2and3 from bench.reporter import Reporter from jwcrypto.jwk import JWK class LoadKeyBenchmark(Benchmark): """ Load key benchmark """ def input(self): """ Name of benchmark """ return ["Load Key"] def repeats(self): """ Iterations """ return 10000 def bench_RSA(self): """ Import key """ JWK.from_pem(to_bytes_2and3(priv_pem)) if __name__ == "__main__": #pylint: disable=W0402 import string string.capwords = lambda x: x LoadKeyBenchmark().run(reporter=Reporter())
#!/usr/bin/env python """ Benchmark generating an RSA key """ # pylint: disable=wrong-import-position,wrong-import-order import Crypto.PublicKey.RSA as RSA from unitbench import Benchmark from bench.reporter import Reporter class GenerateKeyBenchmark(Benchmark): """ Generate key benchmark """ def input(self): """ Name of benchmark """ return ["Generate Key"] def repeats(self): """ Iterations """ return 100 def bench_RSA(self): """ Generate key """ RSA.generate(2048) if __name__ == "__main__": #pylint: disable=W0402 import string string.capwords = lambda x: x GenerateKeyBenchmark().run(reporter=Reporter())
""" Nme of benchmark """ return ["Generate Token"] def repeats(self): """ Iterations """ return 1000 #pylint: disable=W0621 def make_bench_generate_token(alg): """ Return function which will generate token for particular algorithm """ def f(_): """ Generate token """ privk = priv_keys[alg].get('default', priv_key) jwt.generate_jwt(payload, privk, alg, timedelta(seconds=5)) return f for alg in algs: name = 'bench_' + alg f = make_bench_generate_token(alg) f.__name__ = name setattr(GenerateTokenBenchmark, name, f) if __name__ == "__main__": #pylint: disable=W0402 import string string.capwords = lambda x: x GenerateTokenBenchmark().run(reporter=Reporter())