blob: 8027ac85864d2aa8f5aacb12ee35239ee0fc619f [file] [log] [blame]
Fabio Utzig8f289ba2023-01-09 21:01:55 -03001# 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())