JSON Web Algorithms

JSON Web Algorithms.

https://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-40

class josepy.jwa.JWA[source]

Bases: josepy.interfaces.JSONDeSerializable

JSON Web Algorithm.

class josepy.jwa.JWASignature(name: str)[source]

Bases: josepy.jwa.JWA, collections.abc.Hashable

Base class for JSON Web Signature Algorithms.

classmethod register(signature_cls: josepy.jwa.JWASignature) → josepy.jwa.JWASignature[source]

Register class for JSON deserialization.

to_partial_json() → Any[source]

Partially serialize.

Following the example, partial serialization means the following:

assert isinstance(Bar().to_partial_json()[0], Foo)
assert isinstance(Bar().to_partial_json()[1], Foo)

# in particular...
assert Bar().to_partial_json() != ['foo', 'foo']
Raises:josepy.errors.SerializationError – in case of any serialization error.
Returns:Partially serializable object.
classmethod from_json(jobj: Any) → josepy.jwa.JWASignature[source]

Deserialize a decoded JSON document.

Parameters:jobj – Python object, composed of only other basic data types, as decoded from JSON document. Not necessarily dict (as decoded from “JSON object” document).
Raises:josepy.errors.DeserializationError – if decoding was unsuccessful, e.g. in case of unparseable X509 certificate, or wrong padding in JOSE base64 encoded string, etc.
sign(key: Any, msg: bytes) → bytes[source]

Sign the msg using key.

verify(key: Any, msg: bytes, sig: bytes) → bool[source]

Verify the msg and sig using key.

class josepy.jwa._JWAHS(name: str, hash_: Callable[[], cryptography.hazmat.primitives.hashes.HashAlgorithm])[source]

Bases: josepy.jwa.JWASignature

kty

alias of josepy.jwk.JWKOct

sign(key: bytes, msg: bytes) → bytes[source]

Sign the msg using key.

verify(key: bytes, msg: bytes, sig: bytes) → bool[source]

Verify the msg and sig using key.

class josepy.jwa._JWARS(name: str, hash_: Callable[[], cryptography.hazmat.primitives.hashes.HashAlgorithm])[source]

Bases: josepy.jwa._JWARSA, josepy.jwa.JWASignature

class josepy.jwa._JWAPS(name: str, hash_: Callable[[], cryptography.hazmat.primitives.hashes.HashAlgorithm])[source]

Bases: josepy.jwa._JWARSA, josepy.jwa.JWASignature

class josepy.jwa._JWAEC(name: str, hash_: Callable[[], cryptography.hazmat.primitives.hashes.HashAlgorithm])[source]

Bases: josepy.jwa.JWASignature

kty

alias of josepy.jwk.JWKEC

sign(key: cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey, msg: bytes) → bytes[source]

Sign the msg using key.

verify(key: cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey, msg: bytes, sig: bytes) → bool[source]

Verify the msg` and ``sig using key.

josepy.jwa.HS256 = HS256

HMAC using SHA-256

josepy.jwa.HS384 = HS384

HMAC using SHA-384

josepy.jwa.HS512 = HS512

HMAC using SHA-512

josepy.jwa.RS256 = RS256

RSASSA-PKCS-v1_5 using SHA-256

josepy.jwa.RS384 = RS384

RSASSA-PKCS-v1_5 using SHA-384

josepy.jwa.RS512 = RS512

RSASSA-PKCS-v1_5 using SHA-512

josepy.jwa.PS256 = PS256

RSASSA-PSS using SHA-256 and MGF1 with SHA-256

josepy.jwa.PS384 = PS384

RSASSA-PSS using SHA-384 and MGF1 with SHA-384

josepy.jwa.PS512 = PS512

RSASSA-PSS using SHA-512 and MGF1 with SHA-512

josepy.jwa.ES256 = ES256

ECDSA using P-256 and SHA-256

josepy.jwa.ES384 = ES384

ECDSA using P-384 and SHA-384

josepy.jwa.ES512 = ES512

ECDSA using P-521 and SHA-512