Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# This file is dual licensed under the terms of the Apache License, Version 

2# 2.0, and the BSD License. See the LICENSE file in the root of this repository 

3# for complete details. 

4 

5import abc 

6from enum import Enum 

7 

8# This exists to break an import cycle. These classes are normally accessible 

9# from the serialization module. 

10 

11 

12class Encoding(Enum): 

13 PEM = "PEM" 

14 DER = "DER" 

15 OpenSSH = "OpenSSH" 

16 Raw = "Raw" 

17 X962 = "ANSI X9.62" 

18 SMIME = "S/MIME" 

19 

20 

21class PrivateFormat(Enum): 

22 PKCS8 = "PKCS8" 

23 TraditionalOpenSSL = "TraditionalOpenSSL" 

24 Raw = "Raw" 

25 OpenSSH = "OpenSSH" 

26 

27 

28class PublicFormat(Enum): 

29 SubjectPublicKeyInfo = "X.509 subjectPublicKeyInfo with PKCS#1" 

30 PKCS1 = "Raw PKCS#1" 

31 OpenSSH = "OpenSSH" 

32 Raw = "Raw" 

33 CompressedPoint = "X9.62 Compressed Point" 

34 UncompressedPoint = "X9.62 Uncompressed Point" 

35 

36 

37class ParameterFormat(Enum): 

38 PKCS3 = "PKCS3" 

39 

40 

41class KeySerializationEncryption(metaclass=abc.ABCMeta): 

42 pass 

43 

44 

45class BestAvailableEncryption(KeySerializationEncryption): 

46 def __init__(self, password: bytes): 

47 if not isinstance(password, bytes) or len(password) == 0: 

48 raise ValueError("Password must be 1 or more bytes.") 

49 

50 self.password = password 

51 

52 

53class NoEncryption(KeySerializationEncryption): 

54 pass