# Path: pgp/utils.py
# 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


import math
import time
from Crypto import Random
from Crypto.Hash import MD5
from Crypto.Hash import SHA
from Crypto.PublicKey import DSA
from Crypto.PublicKey import ElGamal
from Crypto.PublicKey import RSA
from Crypto.Util.number import bytes_to_long
from pgp import utils
                                               public_key, pub_algorithm_type)
    packets.append(public_key_packet)

    user_id_packet = make_user_id_packet(4, user_id)
    packets.append(user_id_packet)
    user_id_selfsig_subpackets = [
        make_creation_time_subpacket(int(time.time())),
        make_expiration_time_subpacket(0),
        make_issuer_key_subpacket(public_key_packet['key_id']),
        ]
    user_id_selfsig = make_signature_packet(
                            secret_key, public_key_packet, user_id_packet, 4,
                            0x10, pub_algorithm_type, 8,
                            subpackets=user_id_selfsig_subpackets)
    packets.append(user_id_selfsig)

    result = bytearray()
    for packet in packets:
        result.extend(packet_to_bytes(packet))
    return result, secret_key


def make_signature_subpacket(type_, data, critical=False, hashed=True):
    return {'type': type_,
            'critical': critical,
            'hashed': hashed,
            'data': data}


def make_creation_time_subpacket(t, critical=False, hashed=True):

# Path: pgp/utils.py
# 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


# Path: pgp/test_keys.py
import math
import time
from Crypto import Random
from Crypto.Hash import MD5
from Crypto.Hash import SHA
from Crypto.PublicKey import DSA
from Crypto.PublicKey import ElGamal
from Crypto.PublicKey import RSA
from Crypto.Util.number import bytes_to_long
from pgp import utils

                                               public_key, pub_algorithm_type)
    packets.append(public_key_packet)

    user_id_packet = make_user_id_packet(4, user_id)
    packets.append(user_id_packet)
    user_id_selfsig_subpackets = [
        make_creation_time_subpacket(int(time.time())),
        make_expiration_time_subpacket(0),
        make_issuer_key_subpacket(public_key_packet['key_id']),
        ]
    user_id_selfsig = make_signature_packet(
                            secret_key, public_key_packet, user_id_packet, 4,
                            0x10, pub_algorithm_type, 8,
                            subpackets=user_id_selfsig_subpackets)
    packets.append(user_id_selfsig)

    result = bytearray()
    for packet in packets:
        result.extend(packet_to_bytes(packet))
    return result, secret_key


def make_signature_subpacket(type_, data, critical=False, hashed=True):
    return {'type': type_,
            'critical': critical,
            'hashed': hashed,
            'data': data}


def make_creation_time_subpacket(t, critical=False, hashed=True):

    data = utils.int_to_4byte(t)