Gentoo Archives: gentoo-commits

From: Horea Christian <horea.christ@×××××.com>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/sci:master commit in: dev-python/keyrings_alt/files/, dev-python/keyrings_alt/
Date: Wed, 30 Mar 2022 14:04:41
Message-Id: 1648649061.bdb13c16565fab539d46e176db6b5b1df08e3652.chymera@gentoo
1 commit: bdb13c16565fab539d46e176db6b5b1df08e3652
2 Author: Horea Christian <chr <AT> chymera <DOT> eu>
3 AuthorDate: Wed Mar 30 14:04:21 2022 +0000
4 Commit: Horea Christian <horea.christ <AT> gmail <DOT> com>
5 CommitDate: Wed Mar 30 14:04:21 2022 +0000
6 URL: https://gitweb.gentoo.org/proj/sci.git/commit/?id=bdb13c16
7
8 dev-python/keyrings_alt: compatibility with pycryptodome
9
10 Package-Manager: Portage-3.0.30, Repoman-3.0.3
11 Signed-off-by: Horea Christian <chr <AT> chymera.eu>
12
13 .../files/keyrings_alt-4.1.0-pycryptodome.patch | 90 ++++++++++++++++++++++
14 ...t-4.1.0.ebuild => keyrings_alt-4.1.0-r1.ebuild} | 8 +-
15 dev-python/keyrings_alt/metadata.xml | 1 -
16 3 files changed, 97 insertions(+), 2 deletions(-)
17
18 diff --git a/dev-python/keyrings_alt/files/keyrings_alt-4.1.0-pycryptodome.patch b/dev-python/keyrings_alt/files/keyrings_alt-4.1.0-pycryptodome.patch
19 new file mode 100644
20 index 000000000..e0ca3a012
21 --- /dev/null
22 +++ b/dev-python/keyrings_alt/files/keyrings_alt-4.1.0-pycryptodome.patch
23 @@ -0,0 +1,90 @@
24 +diff --git a/keyrings/alt/file.py b/keyrings/alt/file.py
25 +index 37c837f..866e8d0 100644
26 +--- a/keyrings/alt/file.py
27 ++++ b/keyrings/alt/file.py
28 +@@ -44,8 +44,12 @@ class Encrypted:
29 + """
30 + Create the cipher object to encrypt or decrypt a payload.
31 + """
32 +- from Cryptodome.Protocol.KDF import PBKDF2
33 +- from Cryptodome.Cipher import AES
34 ++ try:
35 ++ from Cryptodome.Protocol.KDF import PBKDF2
36 ++ from Cryptodome.Cipher import AES
37 ++ except ImportError:
38 ++ from Crypto.Protocol.KDF import PBKDF2
39 ++ from Crypto.Cipher import AES
40 +
41 + pw = PBKDF2(password, salt, dkLen=self.block_size)
42 + return AES.new(pw[: self.block_size], AES.MODE_CFB, IV)
43 +@@ -79,7 +83,12 @@ class EncryptedKeyring(Encrypted, Keyring):
44 + __import__('Cryptodome.Protocol.KDF')
45 + __import__('Cryptodome.Random')
46 + except ImportError: # pragma: no cover
47 +- raise RuntimeError("pycryptodomex required")
48 ++ try:
49 ++ __import__('Crypto.Cipher.AES')
50 ++ __import__('Crypto.Protocol.KDF')
51 ++ __import__('Crypto.Random')
52 ++ except ImportError:
53 ++ raise RuntimeError("pycryptodomex or pycryptodome required")
54 + if not json: # pragma: no cover
55 + raise RuntimeError("JSON implementation such as simplejson required.")
56 + return 0.6
57 +@@ -190,10 +199,16 @@ class EncryptedKeyring(Encrypted, Keyring):
58 +
59 + def encrypt(self, password, assoc=None):
60 + # encrypt password, ignore associated data
61 +- from Cryptodome.Random import get_random_bytes
62 ++ try:
63 ++ from Cryptodome.Random import get_random_bytes
64 ++ except ImportError:
65 ++ from Crypto.Random import get_random_bytes
66 +
67 + salt = get_random_bytes(self.block_size)
68 +- from Cryptodome.Cipher import AES
69 ++ try:
70 ++ from Cryptodome.Cipher import AES
71 ++ except ImportError:
72 ++ from Crypto.Cipher import AES
73 +
74 + IV = get_random_bytes(AES.block_size)
75 + cipher = self._create_cipher(self.keyring_key, salt, IV)
76 +diff --git a/tests/test_crypto.py b/tests/test_crypto.py
77 +index cfc782a..7396023 100644
78 +--- a/tests/test_crypto.py
79 ++++ b/tests/test_crypto.py
80 +@@ -14,7 +14,12 @@ def is_crypto_supported():
81 + __import__('Cryptodome.Protocol.KDF')
82 + __import__('Cryptodome.Random')
83 + except ImportError:
84 +- return False
85 ++ try:
86 ++ __import__('Crypto.Cipher.AES')
87 ++ __import__('Crypto.Protocol.KDF')
88 ++ __import__('Crypto.Random')
89 ++ except ImportError:
90 ++ return False
91 + return True
92 +
93 +
94 +diff --git a/tests/test_file.py b/tests/test_file.py
95 +index 62192da..3f813f0 100644
96 +--- a/tests/test_file.py
97 ++++ b/tests/test_file.py
98 +@@ -157,7 +157,14 @@ class FileKeyringTests(BackendBasicTests):
99 + class TestEncryptedFileKeyring(FileKeyringTests):
100 + @pytest.fixture(autouse=True)
101 + def crypt_fixture(self, monkeypatch):
102 +- pytest.importorskip('Cryptodome')
103 ++ try:
104 ++ import Cryptodome
105 ++ except ImportError:
106 ++ try:
107 ++ import Crypto
108 ++ except ImportError:
109 ++ pytest.skip("Neither pycryptodome nor pycryptodomex are available",
110 ++ allow_module_level=True)
111 + fake_getpass = mock.Mock(return_value='abcdef')
112 + monkeypatch.setattr(getpass, 'getpass', fake_getpass)
113 +
114
115 diff --git a/dev-python/keyrings_alt/keyrings_alt-4.1.0.ebuild b/dev-python/keyrings_alt/keyrings_alt-4.1.0-r1.ebuild
116 similarity index 73%
117 rename from dev-python/keyrings_alt/keyrings_alt-4.1.0.ebuild
118 rename to dev-python/keyrings_alt/keyrings_alt-4.1.0-r1.ebuild
119 index 247679bb6..290c2f434 100644
120 --- a/dev-python/keyrings_alt/keyrings_alt-4.1.0.ebuild
121 +++ b/dev-python/keyrings_alt/keyrings_alt-4.1.0-r1.ebuild
122 @@ -1,9 +1,11 @@
123 -# Copyright 1999-2021 Gentoo Authors
124 +# Copyright 1999-2022 Gentoo Authors
125 # Distributed under the terms of the GNU General Public License v2
126
127 EAPI=8
128
129 +DISTUTILS_USE_PEP517=setuptools
130 PYTHON_COMPAT=( pypy3 python3_{8..10} )
131 +
132 inherit distutils-r1
133
134 MY_PN="keyrings.alt"
135 @@ -21,5 +23,9 @@ DEPEND=""
136
137 S="${WORKDIR}/${MY_P}"
138
139 +# Patch sumbitted upstream:
140 +# https://github.com/jaraco/keyrings.alt/pull/46
141 +PATCHES=( "${FILESDIR}/${P}-pycryptodome.patch" )
142 +
143 distutils_enable_tests pytest
144 distutils_enable_sphinx docs
145
146 diff --git a/dev-python/keyrings_alt/metadata.xml b/dev-python/keyrings_alt/metadata.xml
147 index b2fa3d3a7..59728c331 100644
148 --- a/dev-python/keyrings_alt/metadata.xml
149 +++ b/dev-python/keyrings_alt/metadata.xml
150 @@ -20,6 +20,5 @@
151 </longdescription>
152 <upstream>
153 <remote-id type="github">jaraco/keyrings.alt</remote-id>
154 - <remote-id type="pypi">keyrings.alt</remote-id>
155 </upstream>
156 </pkgmetadata>