1# SPDX-License-Identifier: Apache-2.0 2 3from cryptography.hazmat.primitives import serialization 4 5 6class PrivateBytesMixin(): 7 def _get_private_bytes(self, minimal, format, exclass): 8 if format is None: 9 format = self._DEFAULT_FORMAT 10 if format not in self._VALID_FORMATS: 11 raise exclass("{} does not support {}".format( 12 self.shortname(), format)) 13 return format, self.key.private_bytes( 14 encoding=serialization.Encoding.DER, 15 format=self._VALID_FORMATS[format], 16 encryption_algorithm=serialization.NoEncryption()) 17