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


import binascii
from castellan.common import exception
from castellan.common.objects import symmetric_key
from oslo_config import cfg
from oslo_log import log as logging
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

LOG = logging.getLogger(__name__)


def handle_migration(conf, key_mgr):
    try:
        conf.register_opt(cfg.StrOpt('fixed_key'), group='key_manager')
    except cfg.DuplicateOptError:
        pass

    if conf.key_manager.fixed_key is not None and \
       not conf.key_manager.backend.endswith('ConfKeyManager'):

        LOG.warning("Using MigrationKeyManager to provide support for legacy"
                    " fixed_key encryption")

        class MigrationKeyManager(type(key_mgr)):
            def __init__(self, configuration):
                self.fixed_key = configuration.key_manager.fixed_key
                self.fixed_key_id = '00000000-0000-0000-0000-000000000000'
                super(MigrationKeyManager, self).__init__(configuration)

            def get(self, context, managed_object_id):
                if managed_object_id == self.fixed_key_id:

# 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/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/key_manager/migration.py
import binascii
from castellan.common import exception
from castellan.common.objects import symmetric_key
from oslo_config import cfg
from oslo_log import log as logging

#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

LOG = logging.getLogger(__name__)


def handle_migration(conf, key_mgr):
    try:
        conf.register_opt(cfg.StrOpt('fixed_key'), group='key_manager')
    except cfg.DuplicateOptError:
        pass

    if conf.key_manager.fixed_key is not None and \
       not conf.key_manager.backend.endswith('ConfKeyManager'):

        LOG.warning("Using MigrationKeyManager to provide support for legacy"
                    " fixed_key encryption")

        class MigrationKeyManager(type(key_mgr)):
            def __init__(self, configuration):
                self.fixed_key = configuration.key_manager.fixed_key
                self.fixed_key_id = '00000000-0000-0000-0000-000000000000'
                super(MigrationKeyManager, self).__init__(configuration)

            def get(self, context, managed_object_id):
                if managed_object_id == self.fixed_key_id:

                    LOG.debug("Processing request for secret associated"