def output_jwk(jwk: JWK, private: bool = False, filename: Optional[str] = None) -> None: """Output JWK to file""" serialized = jwk.serialize(private=private) if filename is not None: with open(filename, mode='wt') as file: file.write(json.dumps(serialized)) else: print(json.dumps(serialized, indent=4))
def serialize(key: JWK) -> dict: _dict = key.serialize() inactive = key.inactive_since if inactive: _dict['inactive_since'] = inactive return _dict
def test_appropriate(): _j1 = JWK(use="sig", kid="1", alg="RS512") assert _j1.appropriate_for("sign") assert _j1.appropriate_for("encrypt") is False
def test_cmp_jwk(): _j1 = JWK(use="sig", kid="1", alg="RS512") _j2 = JWK(use="sig", kid="1", alg="RS512") assert _j1 == _j2
def test_jwk_conversion(): _j = JWK(use=b"sig", kid=b"1", alg=b"RS512") assert _j.use == "sig" args = _j.common() assert set(args.keys()) == {"use", "kid", "alg"}
def test_jwk_wrong_alg(): with pytest.raises(UnsupportedAlgorithm): _j = JWK(alg="xyz")
def test_appropriate(): _j1 = JWK(use='sig', kid='1', alg='RS512') assert _j1.appropriate_for('sign') assert _j1.appropriate_for('encrypt') is False
def test_cmp_jwk(): _j1 = JWK(use='sig', kid='1', alg='RS512') _j2 = JWK(use='sig', kid='1', alg='RS512') assert _j1 == _j2
def test_jwk_conversion(): _j = JWK(use=b'sig', kid=b'1', alg=b'RS512') assert _j.use == 'sig' args = _j.common() assert set(args.keys()) == {'use', 'kid', 'alg'}