@@ -49,33 +49,6 @@ def deser(val):
49
49
return b64d (_val )
50
50
51
51
52
- def okp_construct_public (num ) -> OKPPublicKey :
53
- """
54
- Given a set of values on public attributes build a OKP public key instance.
55
-
56
- :param num: A dictionary with public attributes and their values
57
- :return: A OKPPublicKey instance.
58
- """
59
- try :
60
- return CRV2PUBLIC [as_unicode (num ["crv" ])].from_public_bytes (num ["x" ])
61
- except KeyError :
62
- raise UnsupportedOKPCurve ("Unsupported OKP curve: {}" .format (num ["crv" ]))
63
-
64
-
65
- def okp_construct_private (num ) -> OKPPrivateKey :
66
- """
67
- Given a set of values on public and private attributes build a elliptic
68
- curve private key instance.
69
-
70
- :param num: A dictionary with public and private attributes and their values
71
- :return: A OKPPrivateKey instance.
72
- """
73
- try :
74
- return CRV2PRIVATE [as_unicode (num ["crv" ])].from_private_bytes (num ["d" ])
75
- except KeyError :
76
- raise UnsupportedOKPCurve ("Unsupported OKP curve: {}" .format (num ["crv" ]))
77
-
78
-
79
52
class OKPKey (AsymmetricKey ):
80
53
"""
81
54
JSON Web key representation of an Octet Key Pair key.
@@ -147,13 +120,18 @@ def deserialize(self):
147
120
if self .d :
148
121
try :
149
122
if isinstance (self .d , (str , bytes )):
150
- _d = deser (self .d )
151
- self .priv_key = okp_construct_private ({"x" : _x , "crv" : self .crv , "d" : _d })
123
+ try :
124
+ self .priv_key = CRV2PRIVATE [self .crv ].from_private_bytes (deser (self .d ))
125
+ except KeyError :
126
+ raise UnsupportedOKPCurve ("Unsupported OKP curve: {}" .format (self .crv ))
152
127
self .pub_key = self .priv_key .public_key ()
153
128
except ValueError as err :
154
129
raise DeSerializationNotPossible (str (err ))
155
130
else :
156
- self .pub_key = okp_construct_public ({"x" : _x , "crv" : self .crv })
131
+ try :
132
+ self .pub_key = CRV2PUBLIC [self .crv ].from_public_bytes (_x )
133
+ except KeyError :
134
+ raise UnsupportedOKPCurve ("Unsupported OKP curve: {}" .format (num ["crv" ]))
157
135
158
136
def _serialize (self , key ):
159
137
if isinstance (key , ed25519 .Ed25519PublicKey ):
0 commit comments