@@ -35,8 +35,7 @@ def ec_construct_public(num):
35
35
public key instance.
36
36
37
37
:param num: A dictionary with public attributes and their values
38
- :return: A
39
- cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey
38
+ :return: A cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey
40
39
instance.
41
40
"""
42
41
ecpn = ec .EllipticCurvePublicNumbers (num ['x' ], num ['y' ],
@@ -50,8 +49,7 @@ def ec_construct_private(num):
50
49
curve private key instance.
51
50
52
51
:param num: A dictionary with public and private attributes and their values
53
- :return: A
54
- cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey
52
+ :return: A cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey
55
53
instance.
56
54
"""
57
55
pub_ecpn = ec .EllipticCurvePublicNumbers (num ['x' ], num ['y' ],
@@ -66,8 +64,7 @@ def import_private_key_from_file(filename, passphrase=None):
66
64
67
65
:param filename: The name of the file
68
66
:param passphrase: A pass phrase to use to unpack the PEM file.
69
- :return: A
70
- cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey
67
+ :return: A cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey
71
68
instance
72
69
"""
73
70
with open (filename , "rb" ) as key_file :
@@ -84,9 +81,7 @@ def import_public_key_from_file(filename):
84
81
Read a public Elliptic Curve key from a PEM file.
85
82
86
83
:param filename: The name of the file
87
- :param passphrase: A pass phrase to use to unpack the PEM file.
88
- :return: A
89
- cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey
84
+ :return: A cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey
90
85
instance
91
86
"""
92
87
with open (filename , "rb" ) as key_file :
@@ -188,17 +183,18 @@ def deserialize(self):
188
183
{'x' : _x , 'y' : _y , 'crv' : self .crv })
189
184
190
185
def _serialize (self , key ):
186
+ mlen = int (key .key_size / 8 )
191
187
if isinstance (key , ec .EllipticCurvePublicKey ):
192
188
pn = key .public_numbers ()
193
- self .x = long_to_base64 (pn .x )
194
- self .y = long_to_base64 (pn .y )
189
+ self .x = long_to_base64 (pn .x , mlen )
190
+ self .y = long_to_base64 (pn .y , mlen )
195
191
self .crv = SEC2NIST [pn .curve .name ]
196
192
elif isinstance (key , ec .EllipticCurvePrivateKey ):
197
193
pn = key .private_numbers ()
198
- self .x = long_to_base64 (pn .public_numbers .x )
199
- self .y = long_to_base64 (pn .public_numbers .y )
194
+ self .x = long_to_base64 (pn .public_numbers .x , mlen )
195
+ self .y = long_to_base64 (pn .public_numbers .y , mlen )
200
196
self .crv = SEC2NIST [pn .public_numbers .curve .name ]
201
- self .d = long_to_base64 (pn .private_value )
197
+ self .d = long_to_base64 (pn .private_value , mlen )
202
198
203
199
def serialize (self , private = False ):
204
200
"""
0 commit comments