commit:     bdb13c16565fab539d46e176db6b5b1df08e3652
Author:     Horea Christian <chr <AT> chymera <DOT> eu>
AuthorDate: Wed Mar 30 14:04:21 2022 +0000
Commit:     Horea Christian <horea.christ <AT> gmail <DOT> com>
CommitDate: Wed Mar 30 14:04:21 2022 +0000
URL:        https://gitweb.gentoo.org/proj/sci.git/commit/?id=bdb13c16

dev-python/keyrings_alt: compatibility with pycryptodome

Package-Manager: Portage-3.0.30, Repoman-3.0.3
Signed-off-by: Horea Christian <chr <AT> chymera.eu>

 .../files/keyrings_alt-4.1.0-pycryptodome.patch    | 90 ++++++++++++++++++++++
 ...t-4.1.0.ebuild => keyrings_alt-4.1.0-r1.ebuild} |  8 +-
 dev-python/keyrings_alt/metadata.xml               |  1 -
 3 files changed, 97 insertions(+), 2 deletions(-)

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
new file mode 100644
index 000000000..e0ca3a012
--- /dev/null
+++ b/dev-python/keyrings_alt/files/keyrings_alt-4.1.0-pycryptodome.patch
@@ -0,0 +1,90 @@
+diff --git a/keyrings/alt/file.py b/keyrings/alt/file.py
+index 37c837f..866e8d0 100644
+--- a/keyrings/alt/file.py
++++ b/keyrings/alt/file.py
+@@ -44,8 +44,12 @@ class Encrypted:
+         """
+         Create the cipher object to encrypt or decrypt a payload.
+         """
+-        from Cryptodome.Protocol.KDF import PBKDF2
+-        from Cryptodome.Cipher import AES
++        try:
++            from Cryptodome.Protocol.KDF import PBKDF2
++            from Cryptodome.Cipher import AES
++        except ImportError:
++            from Crypto.Protocol.KDF import PBKDF2
++            from Crypto.Cipher import AES
+ 
+         pw = PBKDF2(password, salt, dkLen=self.block_size)
+         return AES.new(pw[: self.block_size], AES.MODE_CFB, IV)
+@@ -79,7 +83,12 @@ class EncryptedKeyring(Encrypted, Keyring):
+             __import__('Cryptodome.Protocol.KDF')
+             __import__('Cryptodome.Random')
+         except ImportError:  # pragma: no cover
+-            raise RuntimeError("pycryptodomex required")
++            try:
++                __import__('Crypto.Cipher.AES')
++                __import__('Crypto.Protocol.KDF')
++                __import__('Crypto.Random')
++            except ImportError:
++                raise RuntimeError("pycryptodomex or pycryptodome required")
+         if not json:  # pragma: no cover
+             raise RuntimeError("JSON implementation such as simplejson 
required.")
+         return 0.6
+@@ -190,10 +199,16 @@ class EncryptedKeyring(Encrypted, Keyring):
+ 
+     def encrypt(self, password, assoc=None):
+         # encrypt password, ignore associated data
+-        from Cryptodome.Random import get_random_bytes
++        try:
++            from Cryptodome.Random import get_random_bytes
++        except ImportError:
++            from Crypto.Random import get_random_bytes
+ 
+         salt = get_random_bytes(self.block_size)
+-        from Cryptodome.Cipher import AES
++        try:
++            from Cryptodome.Cipher import AES
++        except ImportError:
++            from Crypto.Cipher import AES
+ 
+         IV = get_random_bytes(AES.block_size)
+         cipher = self._create_cipher(self.keyring_key, salt, IV)
+diff --git a/tests/test_crypto.py b/tests/test_crypto.py
+index cfc782a..7396023 100644
+--- a/tests/test_crypto.py
++++ b/tests/test_crypto.py
+@@ -14,7 +14,12 @@ def is_crypto_supported():
+         __import__('Cryptodome.Protocol.KDF')
+         __import__('Cryptodome.Random')
+     except ImportError:
+-        return False
++        try:
++            __import__('Crypto.Cipher.AES')
++            __import__('Crypto.Protocol.KDF')
++            __import__('Crypto.Random')
++        except ImportError:
++            return False
+     return True
+ 
+ 
+diff --git a/tests/test_file.py b/tests/test_file.py
+index 62192da..3f813f0 100644
+--- a/tests/test_file.py
++++ b/tests/test_file.py
+@@ -157,7 +157,14 @@ class FileKeyringTests(BackendBasicTests):
+ class TestEncryptedFileKeyring(FileKeyringTests):
+     @pytest.fixture(autouse=True)
+     def crypt_fixture(self, monkeypatch):
+-        pytest.importorskip('Cryptodome')
++        try:
++            import Cryptodome
++        except ImportError:
++            try:
++                import Crypto
++            except ImportError:
++                pytest.skip("Neither pycryptodome nor pycryptodomex are 
available",
++                    allow_module_level=True)
+         fake_getpass = mock.Mock(return_value='abcdef')
+         monkeypatch.setattr(getpass, 'getpass', fake_getpass)
+ 

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
similarity index 73%
rename from dev-python/keyrings_alt/keyrings_alt-4.1.0.ebuild
rename to dev-python/keyrings_alt/keyrings_alt-4.1.0-r1.ebuild
index 247679bb6..290c2f434 100644
--- a/dev-python/keyrings_alt/keyrings_alt-4.1.0.ebuild
+++ b/dev-python/keyrings_alt/keyrings_alt-4.1.0-r1.ebuild
@@ -1,9 +1,11 @@
-# Copyright 1999-2021 Gentoo Authors
+# Copyright 1999-2022 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 EAPI=8
 
+DISTUTILS_USE_PEP517=setuptools
 PYTHON_COMPAT=( pypy3 python3_{8..10} )
+
 inherit distutils-r1
 
 MY_PN="keyrings.alt"
@@ -21,5 +23,9 @@ DEPEND=""
 
 S="${WORKDIR}/${MY_P}"
 
+# Patch sumbitted upstream:
+# https://github.com/jaraco/keyrings.alt/pull/46
+PATCHES=( "${FILESDIR}/${P}-pycryptodome.patch" )
+
 distutils_enable_tests pytest
 distutils_enable_sphinx docs

diff --git a/dev-python/keyrings_alt/metadata.xml 
b/dev-python/keyrings_alt/metadata.xml
index b2fa3d3a7..59728c331 100644
--- a/dev-python/keyrings_alt/metadata.xml
+++ b/dev-python/keyrings_alt/metadata.xml
@@ -20,6 +20,5 @@
        </longdescription>
        <upstream>
                <remote-id type="github">jaraco/keyrings.alt</remote-id>
-               <remote-id type="pypi">keyrings.alt</remote-id>
        </upstream>
 </pkgmetadata>

Reply via email to