diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2019-02-21 12:53:45 +0800 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2019-02-20 23:53:45 -0500 |
commit | e1f7e0978231f73382f95b864200fdeca7d37bb7 (patch) | |
tree | ea0c6c6362b62bf634922b94113e37a43f2fdfd9 /src/cryptography/hazmat | |
parent | 5cfaa5b79d446e1c63de3948e7558cd00561ea1f (diff) | |
download | cryptography-e1f7e0978231f73382f95b864200fdeca7d37bb7.tar.gz cryptography-e1f7e0978231f73382f95b864200fdeca7d37bb7.tar.bz2 cryptography-e1f7e0978231f73382f95b864200fdeca7d37bb7.zip |
add an EC OID to curve dictionary mapping (#4759)
* add an EC OID to curve dictionary mapping
* oid_to_curve function
* changelog and docs fix
* rename to get_curve_for_oid
Diffstat (limited to 'src/cryptography/hazmat')
-rw-r--r-- | src/cryptography/hazmat/primitives/asymmetric/ec.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/cryptography/hazmat/primitives/asymmetric/ec.py b/src/cryptography/hazmat/primitives/asymmetric/ec.py index 1de0976a..529391f9 100644 --- a/src/cryptography/hazmat/primitives/asymmetric/ec.py +++ b/src/cryptography/hazmat/primitives/asymmetric/ec.py @@ -465,3 +465,36 @@ class EllipticCurvePrivateNumbers(object): class ECDH(object): pass + + +_OID_TO_CURVE = { + EllipticCurveOID.SECP192R1: SECP192R1, + EllipticCurveOID.SECP224R1: SECP224R1, + EllipticCurveOID.SECP256K1: SECP256K1, + EllipticCurveOID.SECP256R1: SECP256R1, + EllipticCurveOID.SECP384R1: SECP384R1, + EllipticCurveOID.SECP521R1: SECP521R1, + EllipticCurveOID.BRAINPOOLP256R1: BrainpoolP256R1, + EllipticCurveOID.BRAINPOOLP384R1: BrainpoolP384R1, + EllipticCurveOID.BRAINPOOLP512R1: BrainpoolP512R1, + EllipticCurveOID.SECT163K1: SECT163K1, + EllipticCurveOID.SECT163R2: SECT163R2, + EllipticCurveOID.SECT233K1: SECT233K1, + EllipticCurveOID.SECT233R1: SECT233R1, + EllipticCurveOID.SECT283K1: SECT283K1, + EllipticCurveOID.SECT283R1: SECT283R1, + EllipticCurveOID.SECT409K1: SECT409K1, + EllipticCurveOID.SECT409R1: SECT409R1, + EllipticCurveOID.SECT571K1: SECT571K1, + EllipticCurveOID.SECT571R1: SECT571R1, +} + + +def get_curve_for_oid(oid): + try: + return _OID_TO_CURVE[oid] + except KeyError: + raise LookupError( + "The provided object identifier has no matching elliptic " + "curve class" + ) |