~dricottone/huttese-apk

huttese-apk/pkgsrc/py3-pgpy/cryptography.patch -rw-r--r-- 2.7 KiB
c845640fDominic Ricottone Cleanup 1 year, 7 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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