# Path: castellan/common/exception.py
# _FATAL_EXCEPTION_FORMAT_ERRORS = False
# class RedirectException(Exception):
# class CastellanException(Exception):
# class Forbidden(CastellanException):
# class KeyManagerError(CastellanException):
# class ManagedObjectNotFoundError(CastellanException):
# class InvalidManagedObjectDictError(CastellanException):
# class UnknownManagedObjectTypeError(CastellanException):
# class AuthTypeInvalidError(CastellanException):
# class InsufficientCredentialDataError(CastellanException):
#     def __init__(self, url):
#     def __init__(self, message_arg=None, *args, **kwargs):
# 
# Path: castellan/common/objects/private_key.py
# class PrivateKey(key.Key):
#     def __init__(self, algorithm, bit_length, key,
#                  name=None, created=None, id=None):
#     def managed_type(cls):
#     def algorithm(self):
#     def format(self):
#     def bit_length(self):
#     def get_encoded(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
# 
# Path: castellan/common/objects/public_key.py
# class PublicKey(key.Key):
#     def __init__(self, algorithm, bit_length, key,
#                  name=None, created=None, id=None):
#     def managed_type(cls):
#     def algorithm(self):
#     def format(self):
#     def get_encoded(self):
#     def bit_length(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
# 
# Path: castellan/common/objects/symmetric_key.py
# class SymmetricKey(key.Key):
#     def __init__(self, algorithm, bit_length, key,
#                  name=None, created=None, id=None):
#     def managed_type(cls):
#     def algorithm(self):
#     def format(self):
#     def get_encoded(self):
#     def bit_length(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
# 
# Path: castellan/i18n.py

# 
# Path: castellan/key_manager/key_manager.py
# class KeyManager(object, metaclass=abc.ABCMeta):
#     def __init__(self, configuration):
#     def create_key(self, context, algorithm, length,
#                    expiration=None, name=None):
#     def create_key_pair(self, context, algorithm, length,
#                         expiration=None, name=None):
#     def store(self, context, managed_object, expiration=None):
#     def get(self, context, managed_object_id, metadata_only=False):
#     def delete(self, context, managed_object_id):
#     def list(self, context, object_type=None, metadata_only=False):
#     def list_options_for_discovery(self):


import binascii
import os
import time
import uuid
import requests
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.primitives.serialization import Encoding
from cryptography.hazmat.primitives.serialization import NoEncryption
from cryptography.hazmat.primitives.serialization import PrivateFormat
from cryptography.hazmat.primitives.serialization import PublicFormat
from keystoneauth1 import loading
from oslo_config import cfg
from oslo_log import log as logging
from oslo_utils import timeutils
from castellan.common import exception
from castellan.common.objects import private_key as pri_key
from castellan.common.objects import public_key as pub_key
from castellan.common.objects import symmetric_key as sym_key
from castellan.i18n import _
from castellan.key_manager import key_manager
            resp = method(resource, headers=headers, json=json, verify=verify)
        except requests.exceptions.Timeout as ex:
            raise exception.KeyManagerError(str(ex))
        except requests.exceptions.ConnectionError as ex:
            raise exception.KeyManagerError(str(ex))
        except Exception as ex:
            raise exception.KeyManagerError(str(ex))

        if resp.status_code in _EXCEPTIONS_BY_CODE:
            raise exception.KeyManagerError(resp.reason)
        if resp.status_code == requests.codes['forbidden']:
            raise exception.Forbidden()

        return resp

    def create_key_pair(self, context, algorithm, length,
                        expiration=None, name=None):
        """Creates an asymmetric key pair."""

        if algorithm.lower() != 'rsa':
            raise NotImplementedError(
                "VaultKeyManager only implements rsa keys"
            )

        priv_key = rsa.generate_private_key(
            public_exponent=65537,
            key_size=length,
            backend=default_backend()
        )


# Path: castellan/common/exception.py
# _FATAL_EXCEPTION_FORMAT_ERRORS = False
# class RedirectException(Exception):
# class CastellanException(Exception):
# class Forbidden(CastellanException):
# class KeyManagerError(CastellanException):
# class ManagedObjectNotFoundError(CastellanException):
# class InvalidManagedObjectDictError(CastellanException):
# class UnknownManagedObjectTypeError(CastellanException):
# class AuthTypeInvalidError(CastellanException):
# class InsufficientCredentialDataError(CastellanException):
#     def __init__(self, url):
#     def __init__(self, message_arg=None, *args, **kwargs):
# 
# Path: castellan/common/objects/private_key.py
# class PrivateKey(key.Key):
#     def __init__(self, algorithm, bit_length, key,
#                  name=None, created=None, id=None):
#     def managed_type(cls):
#     def algorithm(self):
#     def format(self):
#     def bit_length(self):
#     def get_encoded(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
# 
# Path: castellan/common/objects/public_key.py
# class PublicKey(key.Key):
#     def __init__(self, algorithm, bit_length, key,
#                  name=None, created=None, id=None):
#     def managed_type(cls):
#     def algorithm(self):
#     def format(self):
#     def get_encoded(self):
#     def bit_length(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
# 
# Path: castellan/common/objects/symmetric_key.py
# class SymmetricKey(key.Key):
#     def __init__(self, algorithm, bit_length, key,
#                  name=None, created=None, id=None):
#     def managed_type(cls):
#     def algorithm(self):
#     def format(self):
#     def get_encoded(self):
#     def bit_length(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
# 
# Path: castellan/i18n.py

# 
# Path: castellan/key_manager/key_manager.py
# class KeyManager(object, metaclass=abc.ABCMeta):
#     def __init__(self, configuration):
#     def create_key(self, context, algorithm, length,
#                    expiration=None, name=None):
#     def create_key_pair(self, context, algorithm, length,
#                         expiration=None, name=None):
#     def store(self, context, managed_object, expiration=None):
#     def get(self, context, managed_object_id, metadata_only=False):
#     def delete(self, context, managed_object_id):
#     def list(self, context, object_type=None, metadata_only=False):
#     def list_options_for_discovery(self):


# Path: castellan/key_manager/vault_key_manager.py
import binascii
import os
import time
import uuid
import requests
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.primitives.serialization import Encoding
from cryptography.hazmat.primitives.serialization import NoEncryption
from cryptography.hazmat.primitives.serialization import PrivateFormat
from cryptography.hazmat.primitives.serialization import PublicFormat
from keystoneauth1 import loading
from oslo_config import cfg
from oslo_log import log as logging
from oslo_utils import timeutils
from castellan.common import exception
from castellan.common.objects import private_key as pri_key
from castellan.common.objects import public_key as pub_key
from castellan.common.objects import symmetric_key as sym_key
from castellan.i18n import _
from castellan.key_manager import key_manager

            resp = method(resource, headers=headers, json=json, verify=verify)
        except requests.exceptions.Timeout as ex:
            raise exception.KeyManagerError(str(ex))
        except requests.exceptions.ConnectionError as ex:
            raise exception.KeyManagerError(str(ex))
        except Exception as ex:
            raise exception.KeyManagerError(str(ex))

        if resp.status_code in _EXCEPTIONS_BY_CODE:
            raise exception.KeyManagerError(resp.reason)
        if resp.status_code == requests.codes['forbidden']:
            raise exception.Forbidden()

        return resp

    def create_key_pair(self, context, algorithm, length,
                        expiration=None, name=None):
        """Creates an asymmetric key pair."""

        if algorithm.lower() != 'rsa':
            raise NotImplementedError(
                "VaultKeyManager only implements rsa keys"
            )

        priv_key = rsa.generate_private_key(
            public_exponent=65537,
            key_size=length,
            backend=default_backend()
        )


        private_key = pri_key.PrivateKey(