JSON Web Signature

JSON Web Signature.

class josepy.jws.MediaType[source]

Bases: object

MediaType field encoder/decoder.

PREFIX = 'application/'

MIME Media Type and Content Type prefix.

classmethod decode(value)[source]

Decoder.

classmethod encode(value)[source]

Encoder.

class josepy.jws.Header(**kwargs)[source]

Bases: josepy.json_util.JSONObjectWithFields

JOSE Header.

Warning

This class supports only Registered Header Parameter Names (as defined in section 4.1 of the protocol). If you need Public Header Parameter Names (4.2) or Private Header Parameter Names (4.3), you must subclass and override from_json() and to_partial_json() appropriately.

Warning

This class does not support any extensions through the “crit” (Critical) Header Parameter (4.1.11) and as a conforming implementation, from_json() treats its occurrence as an error. Please subclass if you seek for a different behaviour.

Variables:
not_omitted()[source]

Fields that would not be omitted in the JSON object.

find_key()[source]

Find key based on header.

Todo

Supports only “jwk” header parameter lookup.

Returns:(Public) key found in the header.
Return type:JWK
Raises:josepy.errors.Error – if key could not be found
class josepy.jws.Signature(**kwargs)[source]

Bases: josepy.json_util.JSONObjectWithFields

JWS Signature.

Variables:
  • combined – Combined Header (protected and unprotected, Header).
  • protected (unicode) – JWS protected header (Jose Base-64 decoded).
  • header – JWS Unprotected Header (Header).
  • signature (str) – The signature.
header_cls

alias of Header

verify(payload, key=None)[source]

Verify.

Parameters:key (JWK) – Key used for verification.
classmethod sign(payload, key, alg, include_jwk=True, protect=frozenset(), **kwargs)[source]

Sign.

Parameters:key (JWK) – Key for signature.
class josepy.jws.JWS(**kwargs)[source]

Bases: josepy.json_util.JSONObjectWithFields

JSON Web Signature.

Variables:
  • payload (str) – JWS Payload.
  • signature (str) – JWS Signatures.
signature_cls

alias of Signature

verify(key=None)[source]

Verify.

classmethod sign(payload, **kwargs)[source]

Sign.

signature

Get a singleton signature.

Return type:JWS.signature_cls
to_compact()[source]

Compact serialization.

Return type:bytes
classmethod from_compact(compact)[source]

Compact deserialization.

Parameters:compact (bytes) –
class josepy.jws.CLI[source]

Bases: object

JWS CLI.

classmethod sign(args)[source]

Sign.

classmethod verify(args)[source]

Verify.

classmethod run(args=None)[source]

Parse arguments and sign/verify.