1# -*- coding: utf-8 -*-
3"""
4interfaces around python-apt
6@copyright: 2020 😸 <😸@43-1.org>
7@license: GNU General Public License version 2 or later
8"""
10# This program is free software; you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation; either version 2 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program. If not, see <https://www.gnu.org/licenses/>.
23import apt_pkg
26class DakHashes:
27 """
28 wrapper around `apt_pkg.Hashes`
29 """
30 def __init__(self, *args, **kwargs):
31 self._apt_hashes = apt_pkg.Hashes(*args, **kwargs)
33 # python-apt in Debian 10 (buster) uses
34 # `apt_pkg.Hashes(...).md5`
35 # but in Debian bullseye it switched to
36 # `apt_pkg.Hashes(...).find('md5sum').hashvalue`
37 def _hashvalue(self, name):
38 h = self._apt_hashes.hashes.find(name)
39 try:
40 return h.hashvalue
41 except AttributeError:
42 return str(h)[len(name) + 1:]
44 @property
45 def md5(self) -> str:
46 return self._hashvalue('md5sum')
48 @property
49 def sha1(self) -> str:
50 return self._hashvalue('sha1')
52 @property
53 def sha256(self) -> str:
54 return self._hashvalue('sha256')