diff options
author | Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com> | 2025-01-07 16:15:13 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2025-01-11 18:35:01 +0000 |
commit | f00e8e1233e773d495413ea31000b88f67eb61ba (patch) | |
tree | 15d74bbc2996569d344f784b0943181a793fdecf /bitbake | |
parent | d60c48153df139c197301ed370407851475c12e0 (diff) | |
download | poky-f00e8e1233e773d495413ea31000b88f67eb61ba.tar.gz |
bitbake: utils: add Go mod h1 checksum support
Add support for the Go mod h1 hash. The hash is based on the Go dirhash
package. The package defines hashes over directory trees and is uses for
Go mod files and zip archives.
(Bitbake rev: deefb01592f717efba68e3997fefd04dc7611d88)
Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rw-r--r-- | bitbake/lib/bb/fetch2/__init__.py | 2 | ||||
-rw-r--r-- | bitbake/lib/bb/utils.py | 25 |
2 files changed, 26 insertions, 1 deletions
diff --git a/bitbake/lib/bb/fetch2/__init__.py b/bitbake/lib/bb/fetch2/__init__.py index d2a30c18f0..4dc94e6f2b 100644 --- a/bitbake/lib/bb/fetch2/__init__.py +++ b/bitbake/lib/bb/fetch2/__init__.py | |||
@@ -34,7 +34,7 @@ _revisions_cache = bb.checksum.RevisionsCache() | |||
34 | 34 | ||
35 | logger = logging.getLogger("BitBake.Fetcher") | 35 | logger = logging.getLogger("BitBake.Fetcher") |
36 | 36 | ||
37 | CHECKSUM_LIST = [ "md5", "sha256", "sha1", "sha384", "sha512" ] | 37 | CHECKSUM_LIST = [ "goh1", "md5", "sha256", "sha1", "sha384", "sha512" ] |
38 | SHOWN_CHECKSUM_LIST = ["sha256"] | 38 | SHOWN_CHECKSUM_LIST = ["sha256"] |
39 | 39 | ||
40 | class BBFetchException(Exception): | 40 | class BBFetchException(Exception): |
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py index e722f9113d..135c71c007 100644 --- a/bitbake/lib/bb/utils.py +++ b/bitbake/lib/bb/utils.py | |||
@@ -585,6 +585,31 @@ def sha512_file(filename): | |||
585 | import hashlib | 585 | import hashlib |
586 | return _hasher(hashlib.sha512(), filename) | 586 | return _hasher(hashlib.sha512(), filename) |
587 | 587 | ||
588 | def goh1_file(filename): | ||
589 | """ | ||
590 | Return the hex string representation of the Go mod h1 checksum of the | ||
591 | filename. The Go mod h1 checksum uses the Go dirhash package. The package | ||
592 | defines hashes over directory trees and is used by go mod for mod files and | ||
593 | zip archives. | ||
594 | """ | ||
595 | import hashlib | ||
596 | import zipfile | ||
597 | |||
598 | lines = [] | ||
599 | if zipfile.is_zipfile(filename): | ||
600 | with zipfile.ZipFile(filename) as archive: | ||
601 | for fn in sorted(archive.namelist()): | ||
602 | method = hashlib.sha256() | ||
603 | method.update(archive.read(fn)) | ||
604 | hash = method.hexdigest() | ||
605 | lines.append("%s %s\n" % (hash, fn)) | ||
606 | else: | ||
607 | hash = _hasher(hashlib.sha256(), filename) | ||
608 | lines.append("%s go.mod\n" % hash) | ||
609 | method = hashlib.sha256() | ||
610 | method.update("".join(lines).encode('utf-8')) | ||
611 | return method.hexdigest() | ||
612 | |||
588 | def preserved_envvars_exported(): | 613 | def preserved_envvars_exported(): |
589 | """Variables which are taken from the environment and placed in and exported | 614 | """Variables which are taken from the environment and placed in and exported |
590 | from the metadata""" | 615 | from the metadata""" |