From d84597eb8417a482433ff51dc6b13060d4b2e686 Mon Sep 17 00:00:00 2001
From: Robert Hofer <1058012+hofrob@users.noreply.github.com>
Date: Wed, 7 Sep 2022 22:26:17 +0200
Subject: [PATCH] fix removed cryptography.utils.register_interface
---
pgpy/_curves.py | 73 +++++++++++++++++++++++++++++++++++--------------
1 file changed, 53 insertions(+), 20 deletions(-)
diff --git a/pgpy/_curves.py b/pgpy/_curves.py
index ce6a9f01..2c6ae468 100644
--- a/pgpy/_curves.py
+++ b/pgpy/_curves.py
@@ -34,34 +34,67 @@ def _openssl_get_supported_curves():
return curves
-@utils.register_interface(ec.EllipticCurve)
-class BrainpoolP256R1(object):
- name = 'brainpoolP256r1'
- key_size = 256
+def use_legacy_cryptography_decorator():
+ """
+ The decorator utils.register_interface was removed in version 38.0.0. Keep using it
+ if the decorator exists, inherit from `ec.EllipticCurve` otherwise.
+ """
+ return hasattr(utils, "register_interface") and callable(utils.register_interface)
-@utils.register_interface(ec.EllipticCurve)
-class BrainpoolP384R1(object):
- name = 'brainpoolP384r1'
- key_size = 384
+if use_legacy_cryptography_decorator():
+ @utils.register_interface(ec.EllipticCurve)
+ class BrainpoolP256R1(object):
+ name = 'brainpoolP256r1'
+ key_size = 256
-@utils.register_interface(ec.EllipticCurve)
-class BrainpoolP512R1(object):
- name = 'brainpoolP512r1'
- key_size = 512
+ @utils.register_interface(ec.EllipticCurve)
+ class BrainpoolP384R1(object):
+ name = 'brainpoolP384r1'
+ key_size = 384
-@utils.register_interface(ec.EllipticCurve)
-class X25519(object):
- name = 'X25519'
- key_size = 256
+ @utils.register_interface(ec.EllipticCurve)
+ class BrainpoolP512R1(object):
+ name = 'brainpoolP512r1'
+ key_size = 512
-@utils.register_interface(ec.EllipticCurve)
-class Ed25519(object):
- name = 'ed25519'
- key_size = 256
+ @utils.register_interface(ec.EllipticCurve)
+ class X25519(object):
+ name = 'X25519'
+ key_size = 256
+
+
+ @utils.register_interface(ec.EllipticCurve)
+ class Ed25519(object):
+ name = 'ed25519'
+ key_size = 256
+else:
+ class BrainpoolP256R1(ec.EllipticCurve):
+ name = 'brainpoolP256r1'
+ key_size = 256
+
+
+ class BrainpoolP384R1(ec.EllipticCurve):
+ name = 'brainpoolP384r1'
+ key_size = 384
+
+
+ class BrainpoolP512R1(ec.EllipticCurve):
+ name = 'brainpoolP512r1'
+ key_size = 512
+
+
+ class X25519(ec.EllipticCurve):
+ name = 'X25519'
+ key_size = 256
+
+
+ class Ed25519(ec.EllipticCurve):
+ name = 'ed25519'
+ key_size = 256
# add these curves to the _CURVE_TYPES list