Exemple #1
0
def generate_random_bytearray(count):
    """
    Generates a random byte array.

    :param count:
        The number of bytes.
    :returns:
        A random byte array.
    """
    return bytes_to_bytearray(generate_random_bytes(count))
Exemple #2
0
def base64_to_bytearray(encoded):
    """
    Converts a base-64 encoded value into a byte array.

    :param encoded:
        The base-64 encoded value.
    :returns:
        Byte array.
    """
    return bytes_to_bytearray(base64_decode(encoded))
Exemple #3
0
def mpi_to_long(mpi_byte_string):
    """
    Converts an OpenSSL-format MPI Bignum byte string into a long.

    :param mpi_byte_string:
        OpenSSL-format MPI Bignum byte string.
    :returns:
        Long value.
    """
    #Make sure this is a positive number
    assert (ord(mpi_byte_string[4]) & 0x80) == 0

    byte_array = bytes_to_bytearray(mpi_byte_string[4:])
    return bytearray_to_long(byte_array)
Exemple #4
0
def bytes_to_long_original(byte_string):
    """
    Convert a byte string to a long integer::

        bytes_to_long(byte_string) : long

    This is (essentially) the inverse of long_to_bytes().

    :param byte_string:
        A byte string.
    :returns:
        Long.
    """
    byte_array = bytes_to_bytearray(byte_string)
    return bytearray_to_long(byte_array)