# hashguard
[](https://github.com/javaLux/hashguard/actions)
[](https://deps.rs/repo/github/javaLux/hashguard)
[](https://github.com/javaLux/hashguard/blob/main/LICENSE)
[](https://crates.io/crates/hashguard)

Command-Line tool for ensuring the integrity of files using hash sums
```
___ ___ .__ ________ .___
* For example:
````shell
SHA2-256 Hash with prefix
"sha256:9e2a73027d72a28e5cb05cf9e87e71d5f5850d047a8b163f92f2189e5e8f42ac"
````
<br>
**Supported prefixes:**
| `sha224`, `sha2-224`, `sha2_224` | SHA2-224 |
| `sha256`, `sha2-256`, `sha2_256` | SHA2-256 *(Default)* |
| `sha384`, `sha2-384`, `sha2_384` | SHA2-384 |
| `sha512`, `sha2-512`, `sha2_512` | SHA2-512 |
| `sha3-224`, `sha3_224` | SHA3-224 |
| `sha3-256`, `sha3_256` | SHA3-256 |
| `sha3-384`, `sha3_384` | SHA3-384 |
| `sha3-512`, `sha3_512` | SHA3-512 |
> **Note:**
> If neither a prefix nor the option ``[-a, --algorithm]`` is specified, **SHA2-256** is automatically used as the default algorithm.
> If a hash is passed with a prefix, the ``[-a, --algorithm]`` option is ignored by default.
### Usage Examples
**Common**
* Get version info:
````shell
hashguard --version
````
* Get general help:
````shell
hashguard --help
````
* Get help on a specific command:
````shell
hashguard download --help
````
````shell
hashguard local --help
````
**Download-Command**
* Download a file and verify it with a hash sum by using the default hash algorithm SHA2-256:
````shell
hashguard download "https://example.com/file.zip" a1b2c3d4e5f6
````
* Download a file and calculate a hash sum with a specific hash algorithm:
````shell
hashguard download "https://example.com/file.zip" -a sha2-512
````
* Download a file and use a prefixed hash to specify the algorithm:
````shell
hashguard download "https://example.com/file.zip" sha224:a1b2c3d4e5f6
````
* Use a specific output directory for the downloaded file:
````shell
hashguard download "https://example.com/image.jpg" a1b2c3d4e5f6 -o /path/to/output_directory
````
* Use the --rename option to rename the file to be downloaded:
````shell
hashguard download "https://example.com/image.jpg" a1b2c3d4e5f6 -r "my_fancy_new_file.jpg"
````
**Local-Command**
* Verify a local file with a hash sum using SHA-3:
````shell
hashguard local -p /path/to/local_file.txt a1b2c3d4e5f6 -a sha3-256
````
* Calculate a hash sum from a given ``String``:
````shell
hashguard local -b "Hello my eager young Padawan"
````
* Calculate a hash sum from a local directory with the default hash algorithm:
````shell
hashguard local -p /path/to/test_dir
````
* Calculate a hash sum from a local file and save the calculated hash sum as a file:
````shell
hashguard local -s -p /path/to/local_file.txt
````
* The file containing the hash sum is stored in the application data directory
**Use Logging**
* Enable `debug` log level:
````shell
hashguard -l debug download "https://example.com/file.zip" a1b2c3d4e5f6
````
* Enable `info` log level
````shell
hashguard -l info local -p /path/to/local_file.txt
````
* All logs are written to a log file stored in the application's data directory.
* You can find out the application data directory with the [ `-V`, `--version` ] command
### Supported Hash Algorithms
* SHA2-224
* SHA2-256
* SHA2-384
* SHA2-512
* SHA3-224
* SHA3-256
* SHA3-384
* SHA3-512
## Notice
**_No colored console output under windows?_**
<br>
HashGuard of course also works with colored console output (errors = red, hints = yellow, success = green).<br>
If no colored text is displayed in the CMD or PowerShell, instead the ANSI escape sequences before and after an output,<br>
then enabling ANSI escape sequence support may help. Open a CMD or PowerShell as admin and execute following command:<br>
```
reg add HKCU\Console /v VirtualTerminalLevel /t REG_DWORD /d 1
```
This command adds a registry key that enables the conpty feature, which provides ANSI escape sequence support in the Windows console.<br>
Please re-open the terminal and the colored output should work.
## Contributing
Contributions are very welcome! Whether it's a bug fix, improvement, or new feature — your help is appreciated. To contribute, follow these simple steps:
1. **Fork** this repository.
2. **Create a new branch** for your changes.
3. Make your changes, ensuring they are clean and well-documented.
4. **Commit** your changes with a meaningful message.
5. **Push** your branch to your fork.
6. Open a pull request from your branch to the main repository.
Please ensure your code passes any tests and follows the existing style. If you're not sure where to start, feel free to open an issue and ask!
## License
HashGuard is released under the MIT License.
## Disclaimer
While HashGuard aims to provide reliable file verification, it is essential to exercise caution when downloading files from the internet or using local files for verification. Always ensure that you trust the source and the provided hash sum before proceeding.