jsonhash
A command-line tool to compute hash of file content and filepath, returning the result as JSON.
Supported hashing algorithms
- SHA256: Recommended to avoid collision. By default.
- MD5: Fast (but unsafe) - suitable for files - provided for compatibility/legacy purposes
Features
- Supports both SHA256 and MD5 hash algorithms
- Computes hash of file content
- Computes hash of absolute filepath
- Computes hash of short path (relative to current directory). Useful to create bucket/file ids.
- Returns all information in JSON format
Usage
- The -a|--alg flag is optional. SHA256 by default
Compute SHA256 hash (default)
Compute MD5 hash
Compute SHA256 hash (explicit)
Output Format
The tool returns a JSON object with the following fields:
absfilepath: Absolute path of the filehash: Hash of the file contentfilename: Name of the fileshortpath: Short path relative to current directoryalg: Algorithm used (sha256 or md5)pathid: Hash of the absolute filepathshortpathid: Hash of the short pathstatus: Status of the operation (OK or ERROR)message: Error message if status is ERROR. Empty if successful.
Example
Returns:
Error messages
- Error messages are provided in json format
- Error messages:
- HASH-DIGEST-COMPUTATION-ERROR: An error occured during the computation of the hash digest
- HASH-ALGORITHM-INVALID: You are specifying an incorrect hash algorithm
- NOT-A-FILE: The filepath is not a file (is a directory)
- FILE-DOES-NOT-EXIST : The file does not exist
- FILE-OPENING-ERROR : The file cannot be opened
Dependencies
- Rust
- sha2 crate for SHA256 hashing
- md5 crate for MD5 hashing
- clap for command-line argument parsing
- serde for JSON serialization
- tempfile for testing
Building
Testing
## License
) )
## Author
)