# Path: mom/builtins.py
# def byte(number):
# def bytes_leading(raw_bytes, needle=_compat.ZERO_BYTE):
# def bytes_trailing(raw_bytes, needle=_compat.ZERO_BYTE):
# def bin(number, prefix="0b"):
# def hex(number, prefix="0x"):
# def is_sequence(obj):
# def is_unicode(obj):
# def is_bytes(obj):
# def is_bytes_or_unicode(obj):
# def is_integer(obj):
# def integer_byte_length(number):
# def integer_byte_size(number):
# def integer_bit_length(number):
# def integer_bit_size(number):
# def integer_bit_count(number):
# def is_even(num):
# def is_odd(num):
# def is_positive(num):
# def is_negative(num):


from array import array
from mom import builtins
  """
  #    from mom._types.bytearray import \
  #        bytes_to_bytearray, bytearray_to_long

  # 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)


def long_to_mpi(num):
  """
  Converts a long value into an OpenSSL-format MPI Bignum byte string.

  :param num:
      Long value.
  :returns:
      OpenSSL-format MPI Bignum byte string.
  """
  #    from mom._types.bytearray import \
  #        long_to_bytearray, bytearray_concat, \
  #        bytearray_to_bytes, bytearray_create_zeros

  byte_array = long_to_bytearray(num)
  ext = 0
  # If the high-order bit is going to be set,
  # add an extra byte of zeros
  if not (builtins.integer_bit_length(num) & 0x7):
    ext = 1

# Path: mom/builtins.py
# def byte(number):
# def bytes_leading(raw_bytes, needle=_compat.ZERO_BYTE):
# def bytes_trailing(raw_bytes, needle=_compat.ZERO_BYTE):
# def bin(number, prefix="0b"):
# def hex(number, prefix="0x"):
# def is_sequence(obj):
# def is_unicode(obj):
# def is_bytes(obj):
# def is_bytes_or_unicode(obj):
# def is_integer(obj):
# def integer_byte_length(number):
# def integer_byte_size(number):
# def integer_bit_length(number):
# def integer_bit_size(number):
# def integer_bit_count(number):
# def is_even(num):
# def is_odd(num):
# def is_positive(num):
# def is_negative(num):


# Path: mom/_types/bytearray.py
from array import array
from mom import builtins

  """
  #    from mom._types.bytearray import \
  #        bytes_to_bytearray, bytearray_to_long

  # 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)


def long_to_mpi(num):
  """
  Converts a long value into an OpenSSL-format MPI Bignum byte string.

  :param num:
      Long value.
  :returns:
      OpenSSL-format MPI Bignum byte string.
  """
  #    from mom._types.bytearray import \
  #        long_to_bytearray, bytearray_concat, \
  #        bytearray_to_bytes, bytearray_create_zeros

  byte_array = long_to_bytearray(num)
  ext = 0
  # If the high-order bit is going to be set,
  # add an extra byte of zeros
  if not (builtins.integer_bit_length(num) & 0x7):
    ext = 1

  length = builtins.integer_byte_length(num) + ext