# 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/managed_object.py
# class ManagedObject(object, metaclass=abc.ABCMeta):
#     def __init__(self, name=None, created=None, id=None):
#     def id(self):
#     def name(self):
#     def created(self):
#     def format(self):
#     def value(self):
#     def get_encoded(self):
#     def is_metadata_only(self):
#     def managed_type(cls):
#     def from_dict(cls, dict_fields, id=None, metadata_only=False):
#     def to_dict(self, metadata_only=False):


import abc
import binascii
from castellan.common.objects import exception
from castellan.common.objects import managed_object
        pass

    def to_dict(self):
        dict_fields = super().to_dict()

        dict_fields["algorithm"] = self.algorithm
        dict_fields["bit_length"] = self.bit_length

        return dict_fields

    @classmethod
    def from_dict(cls, dict_fields, id=None, metadata_only=False):
        try:
            value = None

            # NOTE(moguimar): the managed object's value is exported as
            # a hex string. For now, this is a compatibility thing with
            # the already existent vault_key_manager backend.
            if not metadata_only and dict_fields["value"] is not None:
                value = binascii.unhexlify(dict_fields["value"])

            return cls(
                algorithm=dict_fields["algorithm"],
                bit_length=dict_fields["bit_length"],
                key=value,
                name=dict_fields["name"],
                created=dict_fields["created"],
                id=id,
            )
        except KeyError as e:

# 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/managed_object.py
# class ManagedObject(object, metaclass=abc.ABCMeta):
#     def __init__(self, name=None, created=None, id=None):
#     def id(self):
#     def name(self):
#     def created(self):
#     def format(self):
#     def value(self):
#     def get_encoded(self):
#     def is_metadata_only(self):
#     def managed_type(cls):
#     def from_dict(cls, dict_fields, id=None, metadata_only=False):
#     def to_dict(self, metadata_only=False):


# Path: castellan/common/objects/key.py
import abc
import binascii
from castellan.common.objects import exception
from castellan.common.objects import managed_object

        pass

    def to_dict(self):
        dict_fields = super().to_dict()

        dict_fields["algorithm"] = self.algorithm
        dict_fields["bit_length"] = self.bit_length

        return dict_fields

    @classmethod
    def from_dict(cls, dict_fields, id=None, metadata_only=False):
        try:
            value = None

            # NOTE(moguimar): the managed object's value is exported as
            # a hex string. For now, this is a compatibility thing with
            # the already existent vault_key_manager backend.
            if not metadata_only and dict_fields["value"] is not None:
                value = binascii.unhexlify(dict_fields["value"])

            return cls(
                algorithm=dict_fields["algorithm"],
                bit_length=dict_fields["bit_length"],
                key=value,
                name=dict_fields["name"],
                created=dict_fields["created"],
                id=id,
            )
        except KeyError as e:

            raise exception.InvalidManagedObjectDictError(field=str(e))