Metadata-Version: 2.1
Name: fsverity-hash
Version: 0.0.2
Summary: fs-verity digest implementation for Python
Author-email: Alex Willmer <alex@moreati.org.uk>
Maintainer-email: Alex Willmer <alex@moreati.org.uk>
License: Copyright (c) Alex Willmer <alex@moreati.org.uk>
        
        Permission is hereby granted, free of charge, to any person obtaining a copy of
        this software and associated documentation files (the "Software"), to deal in
        the Software without restriction, including without limitation the rights to
        use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
        of the Software, and to permit persons to whom the Software is furnished to do
        so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/moreati/fsverity-hash
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Topic :: Security :: Cryptography
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE.txt

# fsverity-hash

Python implementation of [fs-verity] hash scheme.

## Installation

```
python -mpip install fsverity-hash
```

## Usage

`FSVerityHash` exposes a [hashlib] like interface
```python
>>> import fsverity_hash
>>> m = fsverity_hash.FSVerityHash()
>>> m.update(b"Nobody inspects the spammish repetition")
>>> m.digest()
b'>\xd6s\xd52<\x9e\x1c`\x82\x0f td\xb0\xb8X\xa9\x0b\xa4\xff\x94\x0b\x12=\xd1kBV\x99\xce\xbe'
>>> m.hexdigest()
'3ed673d5323c9e1c60820f207464b0b858a90ba4ff940b123dd16b425699cebe'
```

the `fsverity digest` command produces the same digest

```
$ echo -n "Nobody inspects the spammish repetition" > file.txt
$ fsverity digest file.txt
sha256:3ed673d5323c9e1c60820f207464b0b858a90ba4ff940b123dd16b425699cebe file.txt
```

## Limitations

- Upto 8 GiB can be hashed. This is an implementation limit, not a limitation of fs-verity hashes in general.
- Salted hashes aren't implemented.
- No automated tests.
- No testing of custom block sizes or SHA512 algorithm.
- `FSVerityHash` objects cannot be copied.

## Other implementations
- https://git.kernel.org/pub/scm/fs/fsverity/fsverity-utils.git
  reference libfsverity implementation and `fsverity` command
- https://github.com/rvolgers/fs-verity-rs Rust crate

## Further reading
- https://manpages.debian.org/testing/fsverity/fsverity.1.en.html
- https://www.kernel.org/doc/html/v6.1/filesystems/fsverity.html

[fs-verity]: https://www.kernel.org/doc/html/v6.1/filesystems/fsverity.html#file-digest-computation
[hashlib]: https://docs.python.org/3/library/hashlib.html
