Fabio Utzig | 8f289ba | 2023-01-09 21:01:55 -0300 | [diff] [blame] | 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | |
| 3 | from cryptography.hazmat.primitives import serialization |
| 4 | |
| 5 | |
| 6 | class 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()) |