コード例 #1
0
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))
コード例 #2
0
 def serialize(key: JWK) -> dict:
     _dict = key.serialize()
     inactive = key.inactive_since
     if inactive:
         _dict['inactive_since'] = inactive
     return _dict
コード例 #3
0
ファイル: test_02_jwk.py プロジェクト: jschlyter/cryptojwt
def test_appropriate():
    _j1 = JWK(use="sig", kid="1", alg="RS512")

    assert _j1.appropriate_for("sign")
    assert _j1.appropriate_for("encrypt") is False
コード例 #4
0
ファイル: test_02_jwk.py プロジェクト: jschlyter/cryptojwt
def test_cmp_jwk():
    _j1 = JWK(use="sig", kid="1", alg="RS512")
    _j2 = JWK(use="sig", kid="1", alg="RS512")

    assert _j1 == _j2
コード例 #5
0
ファイル: test_02_jwk.py プロジェクト: jschlyter/cryptojwt
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"}
コード例 #6
0
ファイル: test_02_jwk.py プロジェクト: jschlyter/cryptojwt
def test_jwk_wrong_alg():
    with pytest.raises(UnsupportedAlgorithm):
        _j = JWK(alg="xyz")
コード例 #7
0
def test_appropriate():
    _j1 = JWK(use='sig', kid='1', alg='RS512')

    assert _j1.appropriate_for('sign')
    assert _j1.appropriate_for('encrypt') is False
コード例 #8
0
def test_cmp_jwk():
    _j1 = JWK(use='sig', kid='1', alg='RS512')
    _j2 = JWK(use='sig', kid='1', alg='RS512')

    assert _j1 == _j2
コード例 #9
0
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'}