class CannotParseCritical(RuntimeError):
    """This signature subpacket cannot be parsed by this implementation
    and is marked as critical. It must be discarded.
    """ class CannotParseCriticalNotation(CannotParseCritical):
    """This notation subpacket cannot be parsed by this implementation
    and is marked as critical. It must be discarded.
    """ class InvalidKeyPacketOrder(InvalidKey):
    """The packets that make up this public key are ordered in an
    invalid way.
    """ class InvalidKeyPacketType(InvalidKey):
    """This packet is not valid for a transferrable public key.""" class LocalCertificationSignature(InvalidKey):
    """This signature is a local certification. We should not have
    received it and should discard it.""" class RegexValueError(InvalidSignatureSubpacket):
    """This regular expression signature subpacket contains an invalid
    expression.
    """

    def __init__(self, position, string, unterminated=False):
        if unterminated:
            position -= 1
        self.position = position
        self.string = string

    def __str__(self):
        return 'Invalid character at position {0}\n{1}\n{2}^'.format(
                    self.position, self.string, ' ' * self.position
                    ) class UnsupportedPacketType(InvalidKey):
    """This packet type is unsupported in public key data.""" class UnsupportedSignatureVersion(UnsupportedPacketVersion):
    """The version of this signature is not supported by this
    implementation.
    """ def validate_subpacket_regex(re_str):
    tokens = re_tokenizer.findall(re_str)
    unterminated, valid, valid_portion = \
        validate_partial_subpacket_regex(tokens)
    if unterminated:
        raise RegexValueError(len(valid_portion), re_str, unterminated=True)
    if not valid:
        raise RegexValueError(len(valid_portion), re_str) def sign_hash(pub_algorithm_type, secret_key, hash_, k=None):
def verify_hash(pub_algorithm_type, public_key, hash_, values):
def get_hash_instance(type_):
def get_public_key_constructor(type_):
    def __init__(self, *args, **kwargs):
    def encrypt(self, block):
    def decrypt(self, block):
def get_symmetric_cipher(type_, key, mode, iv=None, segment_size=None,
                         syncable=False):
    def compress(self, data):
    def decompress(self, data):
    def flush(self):
    def __init__(self, level):
    def compress(self, data):
    def decompress(self, data):
    def flush(self):
    def __init__(self, level):
    def compress(self, data):
    def decompress(self, data):
    def flush(self):
def get_compression_instance(type_, level=None):
def hash_key(data_to_hash, key_packet_data):
def packet_type_from_first_byte(byte_):
def hash_user_data(data_to_hash, target_type, target_packet_data,
                   signature_version):
def hash_packet_for_signature(packet_for_hash,
                              signature_type, signature_version,
                              hash_algorithm_type, signature_creation_time,
                              pub_algorithm_type, public_key_packet=None,
                              hashed_subpacket_data=None,
                              fake_hash_algorithm_type=None):
def bytes_to_int(bytes_, offset, length):
def byte_to_int(bytes_, offset):
def short_to_int(bytes_, offset):
def long_to_int(bytes_, offset):
def mpi_length(bytes_, offset):
def mpi_to_int(bytes_, offset):
def int_to_bytes(i):
def int_to_2byte(i):
def int_to_4byte(i):
def int_to_8byte(i):
def s2k_count_to_int(byte, offset=0):
def int_to_s2k_count(i):
def int_to_hex(i, expected_size=None):
def int_to_mpi(i):
def old_packet_length_from_stream(fh):
def old_packet_length(data, offset):
def new_packet_length_from_stream(fh):
def new_packet_length(data, offset):
def new_packet_length_to_bytes(data_length, allow_partial):
def old_packet_length_to_bytes(data_length):
def hex_to_bytes(hex_val, expected_length=None):
def bytearray_to_hex(arr, offset=0, expected=None):
def compare_packets(packet1, packet2):
def sort_key(packets):
def concat_key(packets):
def hash_key_data(packets):
def get_signature_values(signature_packet_data):
def key_packet_fingerprint(packet):
class NoopCipher():
class NoopCompression(object):
class ZlibCompression(object):
class DeflateCompression(object):
ECB = blockalgo.MODE_ECB
CBC = blockalgo.MODE_CBC
CFB = blockalgo.MODE_CFB
OFB = blockalgo.MODE_OFB
CTR = blockalgo.MODE_CTR
OPENPGP = blockalgo.MODE_OPENPGP
EXPBIAS = 6
MAX_PACKET_LENGTH = 4294967295
from base64 import b64encode
from pgp.exceptions import CannotParseCritical
from pgp.exceptions import CannotParseCriticalNotation
from pgp.exceptions import InvalidKeyPacketOrder
from pgp.exceptions import InvalidKeyPacketType
from pgp.exceptions import LocalCertificationSignature
from pgp.exceptions import RegexValueError
from pgp.exceptions import UnsupportedPacketType
from pgp.exceptions import UnsupportedSignatureVersion
from pgp.regex import validate_subpacket_regex
from pgp import utils
import sys
import traceback
import magic
import pgpdump
# python-pgp A Python OpenPGP implementation
# Copyright (C) 2014 Richard Mitchell
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.





_marker = object()


def subpacket_type_to_keys(type_):
    return {
        2: ['creation_time'],
        3: ['expiration_seconds'],
        4: ['exportable'],
        5: ['trust_level', 'trust_amount'],
        6: ['regex'],
        7: ['revocable'],
        9: ['key_expiration_seconds'],
        11: ['preferred_sym_algorithms'],
        12: ['revocation_key'],
        21: ['preferred_hash_algorithms'],
        22: ['preferred_compression_algorithms'],
        23: ['key_server_no_modify'],
        24: ['preferred_key_server'],
        25: ['primary'],
        26: ['policy_uri'],
        27: ['may_certify_others', 'may_sign_data', 'may_encrypt_comms',
             'may_encrypt_storage', 'may_have_been_split',
             'may_be_used_for_auth', 'may_have_multiple_owners'],
        28: ['user_id'],
        29: ['revocation_code', 'revocation_reason'],
        30: ['supports_modification_detection'],
        31: ['target_pub_key_algorithm', 'target_hash_algorithm', 'target'],
    }.get(type_, None)


def parse_notation(data, hashed, encode_non_readable=b64encode):
    flags = utils.long_to_int(data, 0)

    notation_name_length = utils.short_to_int(data, 4)

    notation_value_length = utils.short_to_int(data, 6)