Skip to content

Commit

Permalink
blake3 #6
Browse files Browse the repository at this point in the history
  • Loading branch information
laktak committed Dec 19, 2023
1 parent ce914ff commit 806ceb1
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 7 deletions.
12 changes: 12 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
blake3 = ">=0.3.4"

[dev-packages]

[requires]
python_version = "3.11"
57 changes: 57 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Run `chkbit -u PATH` to create/update the chkbit index.
chkbit will

- create a `.chkbit` index in every subdirectory of the path it was given.
- update the index with md5/sha512 hashes for every file.
- update the index with md5/sha512/blake3 hashes for every file.
- report damage for files that failed the integrity check since the last run (check the exit status).

Run `chkbit PATH` to verify only.
Expand All @@ -55,7 +55,7 @@ positional arguments:
options:
-h, --help show this help message and exit
-u, --update update indices (without this chkbit will only verify files)
--algo ALGO hash algorithm: md5, sha512
--algo ALGO hash algorithm: md5, sha512, blake3
-f, --force force update of damaged items
-i, --verify-index verify files in the index only (will not report new files)
-s, --skip-symlinks do not follow symlinks
Expand Down Expand Up @@ -123,7 +123,7 @@ When you run it again it first checks the modification time,

### I wish to use a stronger hash algorithm

chkbit now supports sha512. You can specify it with `--algo sha512`.
chkbit now supports sha512 and blake3. You can specify it with `--algo sha512` or `--algo blake3`.

Note that existing index files will use the hash that they were created with. If you wish to update all hashes you need to delete your existing indexes first.

Expand Down
2 changes: 1 addition & 1 deletion chkbit/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ def __init__(self, verify_index, update, force, hash_algo, skip_symlinks):
self.hash_algo = hash_algo
self.skip_symlinks = skip_symlinks

if hash_algo not in ["md5", "sha512"]:
if hash_algo not in ["md5", "sha512", "blake3"]:
raise Exception(f"{hash_algo} is unknown.")
4 changes: 4 additions & 0 deletions chkbit/hashfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def hashfile(path, hash_algo=None):
h = hashlib.md5()
elif hash_algo == "sha512":
h = hashlib.sha512()
elif hash_algo == "blake3":
from blake3 import blake3

h = blake3()
else:
raise Exception(f"{hash_algo} is unknown.")

Expand Down
3 changes: 2 additions & 1 deletion chkbit/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def _log(self, idx, stat, path):

def _parse_args(self):
parser = argparse.ArgumentParser(
prog="chkbit",
description="Checks the data integrity of your files. See https://github.com/laktak/chkbit-py",
epilog=STATUS_CODES,
formatter_class=argparse.RawDescriptionHelpFormatter,
Expand All @@ -66,7 +67,7 @@ def _parse_args(self):
"--algo",
type=str,
default="md5",
help="hash algorithm: md5, sha512",
help="hash algorithm: md5, sha512, blake3",
)

parser.add_argument(
Expand Down
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
[project]
name = "chkbit"
version = "2.3.0"
version = "2.4.0"
description = "chkbit checks the data integrity of your files"
authors = [
{name = "Christian Zangl", email = "laktak@cdak.net"},
]
dependencies = []
dependencies = [
"blake3>=0.3.4",
]
requires-python = ">=3.6.0"
readme = "README.md"
license = {file = "LICENSE"}
Expand Down

0 comments on commit 806ceb1

Please sign in to comment.