| 327 | return self.__class__(self.prepared_key.public_key(), self._algorithm) |
| 328 | |
| 329 | def to_pem(self, pem_format="PKCS8"): |
| 330 | if self.is_public(): |
| 331 | if pem_format == "PKCS8": |
| 332 | fmt = serialization.PublicFormat.SubjectPublicKeyInfo |
| 333 | elif pem_format == "PKCS1": |
| 334 | fmt = serialization.PublicFormat.PKCS1 |
| 335 | else: |
| 336 | raise ValueError("Invalid format specified: %r" % pem_format) |
| 337 | pem = self.prepared_key.public_bytes(encoding=serialization.Encoding.PEM, format=fmt) |
| 338 | return pem |
| 339 | |
| 340 | if pem_format == "PKCS8": |
| 341 | fmt = serialization.PrivateFormat.PKCS8 |
| 342 | elif pem_format == "PKCS1": |
| 343 | fmt = serialization.PrivateFormat.TraditionalOpenSSL |
| 344 | else: |
| 345 | raise ValueError("Invalid format specified: %r" % pem_format) |
| 346 | |
| 347 | return self.prepared_key.private_bytes( |
| 348 | encoding=serialization.Encoding.PEM, format=fmt, encryption_algorithm=serialization.NoEncryption() |
| 349 | ) |
| 350 | |
| 351 | def to_dict(self): |
| 352 | if not self.is_public(): |