in docker/services/key_management_service.py [0:0]
def export_key(self, frmt: str, base64encode: bool = False):
try:
value = self.key.export_key(format=frmt)
except (TypeError, Exception) as e:
_LOG.warning(f'Key:\'{self.kid}\' could not be exported into '
f'{frmt} format, due to: "{e}".')
value = None
base = {
KEY_ID_ATTR: self.kid,
ALGORITHM_ATTR: self.alg
}
pending = {}
if value:
pending[FORMAT_ATTR] = frmt
pending[VALUE_ATTR] = value
if pending[VALUE_ATTR] and base64encode:
pending[B64ENCODED_ATTR] = True
pending[VALUE_ATTR] = standard_b64encode(
value if isinstance(value, bytes) else value.encode('utf-8')
)
elif pending[VALUE_ATTR] and not base64encode:
pending[B64ENCODED_ATTR] = False
if pending[VALUE_ATTR] and isinstance(value, bytes):
try:
pending[VALUE_ATTR] = value.decode()
except (TypeError, Exception) as e:
_LOG.warning(f'Key:\'{self.kid}\' could not be decoded into'
f' a string, due to: "{e}".')
pending = {}
base.update(pending)
return base