# Path: securesystemslib/exceptions.py
# class Error(Exception):
# class Warning(Warning):
# class FormatError(Error):
# class InvalidMetadataJSONError(FormatError):
# class UnsupportedAlgorithmError(Error):
# class BadHashError(Error):
# class BadPasswordError(Error):
# class CryptoError(Error):
# class BadSignatureError(CryptoError):
# class UnknownMethodError(CryptoError):
# class UnsupportedLibraryError(Error):
# class InvalidNameError(Error):
# class NotFoundError(Error):
# class URLMatchesNoPatternError(Error):
# class InvalidConfigurationError(Error):
# class StorageError(Error):
#   def __init__(self, exception):
#   def __str__(self):
#   def __init__(self, expected_hash, observed_hash):
#   def __str__(self):
#   def __init__(self, metadata_role_name):
#   def __str__(self):
# 
# Path: securesystemslib/process.py
# DEVNULL = subprocess.DEVNULL
# PIPE = subprocess.PIPE
# def _default_timeout():
# def run(cmd, check=True, timeout=_default_timeout(), **kwargs):
# def run_duplicate_streams(cmd, timeout=_default_timeout()):
#       def _duplicate_streams():
# 
# Path: securesystemslib/gpg/constants.py
# def is_available_gnupg(gnupg):
# GPG_COMMAND = ""
# HAVE_GPG = False
# GPG_ENV_COMMAND = os.environ.get('GNUPG')
# GPG2_COMMAND = "gpg2"
# GPG1_COMMAND = "gpg"
#     GPG_COMMAND = GPG_ENV_COMMAND
#   GPG_COMMAND = GPG2_COMMAND
#   GPG_COMMAND = GPG1_COMMAND
#   HAVE_GPG = True
# GPG_VERSION_COMMAND = GPG_COMMAND + " --version"
# FULLY_SUPPORTED_MIN_VERSION = "2.1.0"
# NO_GPG_MSG = "GPG support requires a GPG client. 'gpg2' or 'gpg' with version {} or newer is" \
#   " fully supported.".format(FULLY_SUPPORTED_MIN_VERSION)
# GPG_SIGN_COMMAND = GPG_COMMAND + \
#                    " --detach-sign --digest-algo SHA256 {keyarg} {homearg}"
# GPG_EXPORT_PUBKEY_COMMAND = GPG_COMMAND + " {homearg} --export {keyid}"
# PACKET_TYPE_SIGNATURE = 0x02
# PACKET_TYPE_PRIMARY_KEY = 0x06
# PACKET_TYPE_USER_ID = 0x0D
# PACKET_TYPE_USER_ATTR = 0x11
# PACKET_TYPE_SUB_KEY = 0x0E
# SUPPORTED_SIGNATURE_PACKET_VERSIONS = {0x04}
# SUPPORTED_PUBKEY_PACKET_VERSIONS = {0x04}
# SHA1 = 0x02
# SHA256 = 0x08
# SHA512 = 0x0A
# SIGNATURE_TYPE_BINARY = 0x00
# SIGNATURE_TYPE_SUB_KEY_BINDING = 0x18
# SIGNATURE_TYPE_CERTIFICATES = {0x10, 0x11, 0x12, 0x13}
# SIG_CREATION_SUBPACKET = 0x02
# PARTIAL_KEYID_SUBPACKET = 0x10
# KEY_EXPIRATION_SUBPACKET = 0x09
# PRIMARY_USERID_SUBPACKET = 0x19
# FULL_KEYID_SUBPACKET = 0x21
# 
# Path: securesystemslib/gpg/exceptions.py
# class PacketParsingError(Exception):
#   pass


import struct
import binascii
import re
import logging
from distutils.version import StrictVersion # pylint: disable=no-name-in-module,import-error
  from cryptography.hazmat import backends
  from cryptography.hazmat.primitives import hashes as hashing
from securesystemslib import exceptions
from securesystemslib import process
from securesystemslib.gpg import constants
from securesystemslib.gpg.exceptions import PacketParsingError
  # the data in bytes (as len reports it)
  return int((bitlength - 1)/8) + 1


def hash_object(headers, algorithm, content):
  """
  <Purpose>
    Hash data prior to signature verification in conformance of the RFC4880
    openPGP standard.

  <Arguments>
    headers: the additional OpenPGP headers as populated from
    gpg_generate_signature

    algorithm: The hash algorithm object defined by the cryptography.io hashes
    module

    content: the signed content

  <Exceptions>
    securesystemslib.exceptions.UnsupportedLibraryError if:
      the cryptography module is unavailable

  <Side Effects>
    None

  <Returns>
    The RFC4880-compliant hashed buffer
  """
  if not CRYPTO: # pragma: no cover

# Path: securesystemslib/exceptions.py
# class Error(Exception):
# class Warning(Warning):
# class FormatError(Error):
# class InvalidMetadataJSONError(FormatError):
# class UnsupportedAlgorithmError(Error):
# class BadHashError(Error):
# class BadPasswordError(Error):
# class CryptoError(Error):
# class BadSignatureError(CryptoError):
# class UnknownMethodError(CryptoError):
# class UnsupportedLibraryError(Error):
# class InvalidNameError(Error):
# class NotFoundError(Error):
# class URLMatchesNoPatternError(Error):
# class InvalidConfigurationError(Error):
# class StorageError(Error):
#   def __init__(self, exception):
#   def __str__(self):
#   def __init__(self, expected_hash, observed_hash):
#   def __str__(self):
#   def __init__(self, metadata_role_name):
#   def __str__(self):
# 
# Path: securesystemslib/process.py
# DEVNULL = subprocess.DEVNULL
# PIPE = subprocess.PIPE
# def _default_timeout():
# def run(cmd, check=True, timeout=_default_timeout(), **kwargs):
# def run_duplicate_streams(cmd, timeout=_default_timeout()):
#       def _duplicate_streams():
# 
# Path: securesystemslib/gpg/constants.py
# def is_available_gnupg(gnupg):
# GPG_COMMAND = ""
# HAVE_GPG = False
# GPG_ENV_COMMAND = os.environ.get('GNUPG')
# GPG2_COMMAND = "gpg2"
# GPG1_COMMAND = "gpg"
#     GPG_COMMAND = GPG_ENV_COMMAND
#   GPG_COMMAND = GPG2_COMMAND
#   GPG_COMMAND = GPG1_COMMAND
#   HAVE_GPG = True
# GPG_VERSION_COMMAND = GPG_COMMAND + " --version"
# FULLY_SUPPORTED_MIN_VERSION = "2.1.0"
# NO_GPG_MSG = "GPG support requires a GPG client. 'gpg2' or 'gpg' with version {} or newer is" \
#   " fully supported.".format(FULLY_SUPPORTED_MIN_VERSION)
# GPG_SIGN_COMMAND = GPG_COMMAND + \
#                    " --detach-sign --digest-algo SHA256 {keyarg} {homearg}"
# GPG_EXPORT_PUBKEY_COMMAND = GPG_COMMAND + " {homearg} --export {keyid}"
# PACKET_TYPE_SIGNATURE = 0x02
# PACKET_TYPE_PRIMARY_KEY = 0x06
# PACKET_TYPE_USER_ID = 0x0D
# PACKET_TYPE_USER_ATTR = 0x11
# PACKET_TYPE_SUB_KEY = 0x0E
# SUPPORTED_SIGNATURE_PACKET_VERSIONS = {0x04}
# SUPPORTED_PUBKEY_PACKET_VERSIONS = {0x04}
# SHA1 = 0x02
# SHA256 = 0x08
# SHA512 = 0x0A
# SIGNATURE_TYPE_BINARY = 0x00
# SIGNATURE_TYPE_SUB_KEY_BINDING = 0x18
# SIGNATURE_TYPE_CERTIFICATES = {0x10, 0x11, 0x12, 0x13}
# SIG_CREATION_SUBPACKET = 0x02
# PARTIAL_KEYID_SUBPACKET = 0x10
# KEY_EXPIRATION_SUBPACKET = 0x09
# PRIMARY_USERID_SUBPACKET = 0x19
# FULL_KEYID_SUBPACKET = 0x21
# 
# Path: securesystemslib/gpg/exceptions.py
# class PacketParsingError(Exception):
#   pass


# Path: securesystemslib/gpg/util.py
import struct
import binascii
import re
import logging
from distutils.version import StrictVersion # pylint: disable=no-name-in-module,import-error
  from cryptography.hazmat import backends
  from cryptography.hazmat.primitives import hashes as hashing
from securesystemslib import exceptions
from securesystemslib import process
from securesystemslib.gpg import constants
from securesystemslib.gpg.exceptions import PacketParsingError

  # the data in bytes (as len reports it)
  return int((bitlength - 1)/8) + 1


def hash_object(headers, algorithm, content):
  """
  <Purpose>
    Hash data prior to signature verification in conformance of the RFC4880
    openPGP standard.

  <Arguments>
    headers: the additional OpenPGP headers as populated from
    gpg_generate_signature

    algorithm: The hash algorithm object defined by the cryptography.io hashes
    module

    content: the signed content

  <Exceptions>
    securesystemslib.exceptions.UnsupportedLibraryError if:
      the cryptography module is unavailable

  <Side Effects>
    None

  <Returns>
    The RFC4880-compliant hashed buffer
  """
  if not CRYPTO: # pragma: no cover

    raise exceptions.UnsupportedLibraryError(NO_CRYPTO_MSG)