Closed sirk390 closed 5 years ago
It works but it would return any symbol from the curve module like 'Curve' . This makes is not safe to use on untrusted user input. Maybe create a dictionary at top level with curves only, or loop through the list of oid_lookup
Agreed, the above was just an example, you can of course always add checks and constraints as needed based on your applications needs -
from fastecdsa import curve
curve_lookup = {k: v for k, v in vars(curve).items() if isinstance(v, curve.Curve)}
That gives me a lookup of -
{'P192': P192,
'P224': P224,
'P256': P256,
'P384': P384,
'P521': P521,
'brainpoolP160r1': brainpoolP160r1,
'brainpoolP192r1': brainpoolP192r1,
'brainpoolP224r1': brainpoolP224r1,
'brainpoolP256r1': brainpoolP256r1,
'brainpoolP320r1': brainpoolP320r1,
'brainpoolP384r1': brainpoolP384r1,
'brainpoolP512r1': brainpoolP512r1,
'secp192k1': secp192k1,
'secp224k1': secp224k1,
'secp256k1': secp256k1}
But I'd rather the applications using the package do this sort of thing rather than adding a bunch of special use case data members and functions into the core classes.
You can actually do this by just inspecting the module itself. The OID lookup is there for ASN.1 purposes as we have to get the curve instance based on the OID encoding to properly create point objects.