Skip to content

Commit 02d0f97

Browse files
committed
Add to_crypto() method to inside the class.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
1 parent dfb0745 commit 02d0f97

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

cvc/certificates.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def find_domain(self, cert_dir='', outer=False):
232232
try:
233233
P = CVC().decode(adata).pubkey().find(0x81) if outer is False else None
234234
if (P):
235-
return EcCurve.to_crypto(EcCurve.from_P(P.data()))
235+
return EcCurve.from_P(P.data()).to_crypto()
236236
depth = 10
237237
while (P == None and depth > 0):
238238
car = CVC().decode(adata).outer_car()
@@ -243,7 +243,7 @@ def find_domain(self, cert_dir='', outer=False):
243243
adata = f.read()
244244
P = CVC().decode(adata).pubkey().find(0x81)
245245
if (P):
246-
return EcCurve.to_crypto(EcCurve.from_P(P.data()))
246+
return EcCurve.from_P(P.data()).to_crypto()
247247
depth -= 1
248248
except FileNotFoundError:
249249
print(f'[Warning: File {car.decode()} not found]')

cvc/ec_curves.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,30 @@ class EcCurve(dict):
3232
def from_name(name):
3333
for e in EcCurve.__subclasses__():
3434
if e.__name__.lower() == name.lower():
35-
return e
35+
return e()
3636
return UnsupportedCurve
3737

38-
def to_crypto(curve):
39-
if (curve.__name__ == 'Curve25519'):
38+
def __to_crypto(name):
39+
name = name.lower()
40+
if (name == 'curve25519'):
4041
return ed25519.Ed25519PublicKey
41-
elif (curve.__name__ == 'Curve448'):
42+
elif (name == 'curve448'):
4243
return ed448.Ed448PublicKey
4344
for e in ec.EllipticCurve.__subclasses__():
44-
if (e.__name__.lower() == curve.__name__.lower()):
45+
if (e.__name__.lower() == name):
4546
return e()
4647
return UnsupportedCurve
4748

49+
def to_crypto(curve):
50+
return EcCurve.__to_crypto(curve.__name__)
51+
52+
def to_crypto(self):
53+
return EcCurve.__to_crypto(self.__class__.__name__)
54+
4855
def from_P(P):
4956
for e in EcCurve.__subclasses__():
5057
if e.P == P:
51-
return e
58+
return e()
5259
return UnsupportedCurve
5360

5461
class UnsupportedCurve(EcCurve):
@@ -94,7 +101,6 @@ class SECP521R1(EcCurve):
94101
O = bytearray(unhexlify("01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA51868783BF2F966B7FCC0148F709A5D03BB5C9B8899C47AEBB6FB71E91386409"))
95102
F = bytearray(unhexlify("01"))
96103

97-
98104
class BrainpoolP192R1(EcCurve):
99105
P = bytearray(unhexlify("C302F41D932A36CDA7A3463093D18DB78FCE476DE1A86297"))
100106
A = bytearray(unhexlify("6A91174076B1E0E19C39C031FE8685C1CAE040E5C69A28EF"))

0 commit comments

Comments
 (0)