def test_jws_2(): msg = {"iss": "joe", "exp": 1300819380, "http://example.com/is_root": True} key = SYMKey(key=intarr2bin(HMAC_KEY)) _jws = JWS(msg, cty="JWT", alg="HS256", jwk=key.serialize()) res = _jws.sign_compact() _jws2 = JWS(alg="HS256") _jws2.verify_compact_verbose(res, keys=[key]) assert _jws2.msg == msg assert _jws2.key == key
def test_signer_es256_verbose(): payload = "Please take a moment to register today" eck = ec.generate_private_key(ec.SECP256R1(), default_backend()) _key = ECKey().load_key(eck) keys = [_key] _jws = JWS(payload, alg="ES256") _jwt = _jws.sign_compact(keys) _pubkey = ECKey().load_key(eck.public_key()) _rj = JWS(alg="ES256") info = _rj.verify_compact_verbose(_jwt, [_pubkey]) assert info["msg"] == payload assert info["key"] == _pubkey