Exemplo n.º 1
0
    def from_compact(cls, compact):
        """Compact deserialization.

        :param bytes compact:

        """
        try:
            protected, payload, signature = compact.split(b'.')
        except ValueError:
            raise errors.DeserializationError(
                'Compact JWS serialization should comprise of exactly'
                ' 3 dot-separated components')

        sig = cls.signature_cls(
            protected=b64.b64decode(protected).decode('utf-8'),
            signature=b64.b64decode(signature))
        return cls(payload=b64.b64decode(payload), signatures=(sig, ))
Exemplo n.º 2
0
    def from_compact(cls, compact):
        """Compact deserialization.

        :param bytes compact:

        """
        try:
            protected, payload, signature = compact.split(b'.')
        except ValueError:
            raise errors.DeserializationError(
                'Compact JWS serialization should comprise of exactly'
                ' 3 dot-separated components')

        sig = cls.signature_cls(
            protected=b64.b64decode(protected).decode('utf-8'),
            signature=b64.b64decode(signature))
        return cls(payload=b64.b64decode(payload), signatures=(sig,))
Exemplo n.º 3
0
def decode_b64jose(data, size=None, minimum=False):
    """Decode JOSE Base-64 field.

    :param int size: Required length (after decoding).
    :param bool minimum: If ``True``, then `size` will be treated as
        minimum required length, as opposed to exact equality.

    """
    try:
        decoded = b64.b64decode(data)
    except TypeError as error:
        raise errors.DeserializationError(error)

    if size is not None and ((not minimum and len(decoded) != size) or (minimum and len(decoded) < size)):
        raise errors.DeserializationError()

    return decoded
Exemplo n.º 4
0
def decode_b64jose(data, size=None, minimum=False):
    """Decode JOSE Base-64 field.

    :param int size: Required length (after decoding).
    :param bool minimum: If ``True``, then `size` will be treated as
        minimum required length, as opposed to exact equality.

    """
    try:
        decoded = b64.b64decode(data)
    except TypeError as error:
        raise errors.DeserializationError(error)

    if size is not None and ((not minimum and len(decoded) != size) or
                             (minimum and len(decoded) < size)):
        raise errors.DeserializationError()

    return decoded
Exemplo n.º 5
0
def decode_b64jose(data, size=None, minimum=False):
    """Decode JOSE Base-64 field.

    :param unicode data:
    :param int size: Required length (after decoding).
    :param bool minimum: If ``True``, then `size` will be treated as
        minimum required length, as opposed to exact equality.

    :rtype: bytes

    """
    error_cls = TypeError if six.PY2 else binascii.Error
    try:
        decoded = b64.b64decode(data.encode())
    except error_cls as error:
        raise errors.DeserializationError(error)

    if size is not None and ((not minimum and len(decoded) != size) or (minimum and len(decoded) < size)):
        raise errors.DeserializationError("Expected at least or exactly {0} bytes".format(size))

    return decoded
Exemplo n.º 6
0
def decode_b64jose(data, size=None, minimum=False):
    """Decode JOSE Base-64 field.

    :param unicode data:
    :param int size: Required length (after decoding).
    :param bool minimum: If ``True``, then `size` will be treated as
        minimum required length, as opposed to exact equality.

    :rtype: bytes

    """
    error_cls = TypeError if six.PY2 else binascii.Error
    try:
        decoded = b64.b64decode(data.encode())
    except error_cls as error:
        raise errors.DeserializationError(error)

    if size is not None and ((not minimum and len(decoded) != size) or
                             (minimum and len(decoded) < size)):
        raise errors.DeserializationError()

    return decoded
Exemplo n.º 7
0
 def _call(cls, data):
     from acme.jose.b64 import b64decode
     return b64decode(data)
Exemplo n.º 8
0
 def _call(cls, data):
     from acme.jose.b64 import b64decode
     return b64decode(data)