Commit 1e5b99a5 authored by Cyril Roelandt's avatar Cyril Roelandt
Browse files

New checksum: SHA512.

parent 827069af
......@@ -7,6 +7,7 @@ Based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
### Added
- A man page is now available
- New option: -r/--recursive, to recursively package all requirements
- New checksum available: SHA512
## [0.9] - 2019-06-19
### Added
......
......@@ -47,12 +47,17 @@ def _compute_sha256_base64_checksum(filepath):
return base64.b64encode(binascii.a2b_hex(sha256)).decode('ascii')
def _compute_sha512_checksum(filepath):
return _compute_checksum(hashlib.sha512, filepath)
def compute_checksum(filepath, hash_name):
hash_functions = {
'md5': _compute_md5_checksum,
'rmd160': _compute_rmd160_checksum,
'sha256': _compute_sha256_checksum,
'sha256_base64': _compute_sha256_base64_checksum,
'sha512': _compute_sha512_checksum,
}
try:
return hash_functions[hash_name](filepath)
......
......@@ -12,6 +12,7 @@ class TestChecksum(unittest.TestCase):
MD5 = '3858f62230ac3c915f300c664312c63f'
SHA256 = 'c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2'
SHA256_BASE64 = 'w6uP8Tcg6K2QR905Rms8iXTlksL6OD1KOWBxTK7wxPI='
SHA512 = '0a50261ebd1a390fed2bf326f2673c145582a6342d523204973d0219337f81616a8069b012587cf5635f6925f1b56c360230c19b273500ee013e030601bf2425' # noqa
def setUp(self):
self.path = '/fake/path'
......@@ -27,6 +28,10 @@ class TestChecksum(unittest.TestCase):
self.assertEqual(checksum._compute_sha256_base64_checksum(self.path),
self.SHA256_BASE64)
def test_sha512_checksum(self, open_fn):
self.assertEqual(checksum._compute_sha512_checksum(self.path),
self.SHA512)
def test_compute_checksum(self, open_fn):
self.assertEqual(checksum.compute_checksum(self.path, 'md5'), self.MD5)
......
......@@ -325,11 +325,13 @@ class TestArchive(unittest.TestCase):
@mock.patch('upt.checksum.compute_checksum', return_value='hash-output')
def test_checksums_provided(self, compute_checksum_fn):
archive = upt.Archive('url', md5='md5', rmd160='rmd160',
sha256='sha256', sha256_base64='sha256_base64')
sha256='sha256', sha256_base64='sha256_base64',
sha512='sha512')
self.assertEqual(archive.md5, 'md5')
self.assertEqual(archive.rmd160, 'rmd160')
self.assertEqual(archive.sha256, 'sha256')
self.assertEqual(archive.sha256_base64, 'sha256_base64')
self.assertEqual(archive.sha512, 'sha512')
compute_checksum_fn.assert_not_called()
......
......@@ -77,7 +77,8 @@ class Archive(object):
This can be a source tarball, a Python wheel, a Ruby gem, a binary, etc.
'''
def __init__(self, url, archive_type=ArchiveType.SOURCE_TARGZ, size=0,
md5=None, sha256=None, rmd160=None, sha256_base64=None):
md5=None, sha256=None, rmd160=None, sha256_base64=None,
sha512=None):
self.url = url
self.archive_type = archive_type
self._size = size
......@@ -92,6 +93,8 @@ class Archive(object):
self.rmd160 = rmd160
if sha256_base64 is not None:
self.sha256_base64 = sha256_base64
if sha512 is not None:
self.sha512 = sha512
@property
def filepath(self):
......@@ -152,6 +155,14 @@ class Archive(object):
def sha256_base64(self, value):
self._hashes['sha256_base64'] = value
@property
def sha512(self):
return self._checksum('sha512')
@sha512.setter
def sha512(self, value):
self._hashes['sha512'] = value
class PackageRequirement(object):
"""Package Requirement.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment