Gentoo Archives: gentoo-commits

From: Sam James <sam@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: lib/portage/util/, lib/portage/tests/util/
Date: Sat, 31 Dec 2022 13:33:12
Message-Id: 1672493584.98f984875251f86d3a5c367765c7d6e249277a26.sam@gentoo
1 commit: 98f984875251f86d3a5c367765c7d6e249277a26
2 Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
3 AuthorDate: Fri Dec 30 10:44:10 2022 +0000
4 Commit: Sam James <sam <AT> gentoo <DOT> org>
5 CommitDate: Sat Dec 31 13:33:04 2022 +0000
6 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=98f98487
7
8 Test C whirlpool implementation separately from Python impl
9
10 Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>
11 Signed-off-by: Sam James <sam <AT> gentoo.org>
12
13 lib/portage/tests/util/test_whirlpool.py | 17 +++++++++++------
14 lib/portage/util/whirlpool.py | 2 ++
15 2 files changed, 13 insertions(+), 6 deletions(-)
16
17 diff --git a/lib/portage/tests/util/test_whirlpool.py b/lib/portage/tests/util/test_whirlpool.py
18 index d93467b21..ac156abf3 100644
19 --- a/lib/portage/tests/util/test_whirlpool.py
20 +++ b/lib/portage/tests/util/test_whirlpool.py
21 @@ -2,26 +2,31 @@
22 # Distributed under the terms of the GNU General Public License v2
23
24 from portage.tests import TestCase
25 -from portage.util.whirlpool import Whirlpool
26 +from portage.util.whirlpool import CWhirlpool, PyWhirlpool
27
28
29 class WhirlpoolTestCase(TestCase):
30 - def testBundledWhirlpool(self):
31 + def testBundledWhirlpool(self, cls=PyWhirlpool):
32 self.assertEqual(
33 - Whirlpool(b"The quick brown fox jumps over the lazy dog").hexdigest(),
34 + cls(b"The quick brown fox jumps over the lazy dog").hexdigest(),
35 "b97de512e91e3828b40d2b0fdce9ceb3c4a71f9bea8d88e75c4fa854df36725fd2b52eb6544edcacd6f8beddfea403cb55ae31f03ad62a5ef54e42ee82c3fb35",
36 )
37 self.assertEqual(
38 - Whirlpool(b"The quick brown fox jumps over the lazy eog").hexdigest(),
39 + cls(b"The quick brown fox jumps over the lazy eog").hexdigest(),
40 "c27ba124205f72e6847f3e19834f925cc666d0974167af915bb462420ed40cc50900d85a1f923219d832357750492d5c143011a76988344c2635e69d06f2d38c",
41 )
42 self.assertEqual(
43 - Whirlpool(b"").hexdigest(),
44 + cls(b"").hexdigest(),
45 "19fa61d75522a4669b44e39c1d2e1726c530232130d407f89afee0964997f7a73e83be698b288febcf88e3e03c4f0757ea8964e59b63d93708b138cc42a66eb3",
46 )
47 - w = Whirlpool()
48 + w = cls()
49 w.update(b"")
50 self.assertEqual(
51 w.hexdigest(),
52 "19fa61d75522a4669b44e39c1d2e1726c530232130d407f89afee0964997f7a73e83be698b288febcf88e3e03c4f0757ea8964e59b63d93708b138cc42a66eb3",
53 )
54 +
55 + def testCWhirlpool(self):
56 + if not CWhirlpool.is_available:
57 + self.skipTest("C Whirlpool extension is not importable")
58 + self.testBundledWhirlpool(CWhirlpool)
59
60 diff --git a/lib/portage/util/whirlpool.py b/lib/portage/util/whirlpool.py
61 index 1431c18fb..7caa20f6e 100644
62 --- a/lib/portage/util/whirlpool.py
63 +++ b/lib/portage/util/whirlpool.py
64 @@ -83,6 +83,8 @@ class CWhirlpool:
65 may be provided; if present, this string will be automatically
66 hashed."""
67
68 + is_available = WhirlpoolExt is not None
69 +
70 def __init__(self, arg=b""):
71 self.obj = WhirlpoolExt()
72 self.dig = None