def legacy_decrypt(jwe, jwk, adata='', validate_claims=True,
                   expiry_seconds=None):
    """ Decrypts a deserialized :class:`~jose.JWE`

    :param jwe: An instance of :class:`~jose.JWE`
    :param jwk: A `dict` representing the JWK required to decrypt the content
                of the :class:`~jose.JWE`.
    :param adata: Arbitrary string data used during encryption for additional
                  authentication.
    :param validate_claims: A `bool` indicating whether or not the `exp`, `iat`
                            and `nbf` claims should be validated. Defaults to
                            `True`.
    :param expiry_seconds: An `int` containing the JWT expiry in seconds, used
                           when evaluating the `iat` claim. Defaults to `None`,
                           which disables `iat` claim validation.
    :rtype: :class:`~jose.JWT`
    :raises: :class:`~jose.Expired` if the JWT has expired
    :raises: :class:`~jose.NotYetValid` if the JWT is not yet valid
    :raises: :class:`~jose.Error` if there is an error decrypting the JWE
    """
    protected_header, encrypted_key, iv, ciphertext, authentication_tag = map(
        b64decode_url, jwe)
    header = json_decode(protected_header)

    alg = header[HEADER_ALG]
    enc = header[HEADER_ENC]

    # decrypt cek
    encryption_key = _decrypt_key(encrypted_key, jwk, alg)

    # decrypt body
    ((_, decipher), _), ((hash_fn, _), mod) = JWA[enc]

    version = header.get(_TEMP_VER_KEY)
    if version:
        plaintext = decipher(ciphertext, encryption_key[-mod.digest_size/2:],
                             iv)
        hash = hash_fn(_jwe_hash_str(ciphertext, iv, adata, version),
                encryption_key[:-mod.digest_size/2], mod=mod)
    else:
        plaintext = decipher(ciphertext, encryption_key[:-mod.digest_size], iv)
        hash = hash_fn(_jwe_hash_str(ciphertext, iv, adata, version),
            encryption_key[-mod.digest_size:], mod=mod)

    if not const_compare(auth_tag(hash), authentication_tag):
        raise Error('Mismatched authentication tags')

    if HEADER_ZIP in header:
        try:
            (_, decompress) = COMPRESSION[header[HEADER_ZIP]]
        except KeyError:
            raise Error('Unsupported compression algorithm: {}'.format(
                header[HEADER_ZIP]))

        plaintext = decompress(plaintext)

    claims = json_decode(plaintext)
    try:
        del claims[_TEMP_VER_KEY]
    except __HOLE__:
        # expected when decrypting legacy tokens
        pass

    _validate(claims, validate_claims, expiry_seconds)

    return JWT(header, claims)
dataset/ETHPy150Open Demonware/jose/jose.py/legacy_decrypt