How bh-altsysrq/hasher-cli works
Purpose and Entry Point
hasher-cli is a native command-line utility that computes a file’s SHA-256 digest. Its executable entry point and all runtime logic are in hasher-cli.c; users invoke it with one file-path argument.
Paths:
• hasher-cli.c
• README.md
Build and Runtime Boundary
The project is compiled through make, with build rules defined in Makefile. It requires OpenSSL development headers and links against OpenSSL’s crypto facilities. The produced binary runs directly on the host; there is no server, persistent storage, or application framework.
Paths:
• Makefile
• hasher-cli.c
Command-Line Input Stage
The program receives the target filename from process arguments. Argument handling establishes the primary user boundary: an invalid invocation or inaccessible path should terminate before digest output. The supplied path is treated as a local filesystem resource.
Paths:
• hasher-cli.c
File Streaming Stage
The target file is opened and read from the operating system filesystem. Content is expected to be processed incrementally rather than modeled as application-domain data, keeping memory use independent of file size and separating file I/O failures from cryptographic failures.
Paths:
• hasher-cli.c
SHA-256 Digest Stage
Hash computation is delegated to the OpenSSL EVP API, rather than implementing SHA-256 internally. The EVP context lifecycle—creation, SHA-256 initialization, repeated updates from file chunks, and finalization—forms the central control flow.
Paths:
• hasher-cli.c
Output and Error Boundaries
After finalization, the binary digest is rendered as a human-readable hexadecimal SHA-256 value and written to standard output. Usage, file-access, allocation, and OpenSSL operation failures are command-line error boundaries and should be reported through standard error with a non-success exit status.
Paths:
• hasher-cli.c
External Dependencies
OpenSSL is the only material external service/library dependency, specifically its EVP cryptographic interface and development headers. Host filesystem access supplies the hashed bytes; shell invocation and standard streams provide the interface contract.
Paths:
• hasher-cli.c
• Makefile
Main entry points: hasher-cli.c Argument validation · Makefile make
Components 13
Build
- make
Makefile - CLI source · Contains the executable entry point and runtime logic.
hasher-cli.c - OpenSSL headers
CLI runtime
- hasher-cli · Host-run SHA-256 command-line utility.
hasher-cli.c - Shell user
- File-path argument
hasher-cli.c - Argument validation · Rejects invalid invocation before digest output.
hasher-cli.c - Host filesystem · Supplies target file bytes.
- Chunked file reader · Streams file content with memory use independent of file size.
hasher-cli.c - OpenSSL EVP API · Owns SHA-256 context creation, updates, and finalization.
- SHA-256 digest
hasher-cli.c - Standard output · Receives the hexadecimal digest.
hasher-cli.c - Standard error and exit · Reports usage, I/O, allocation, and OpenSSL failures with non-success status.
hasher-cli.c
Connections 15
- make → CLI source: compiles
- make → OpenSSL headers: requires
- CLI source → hasher-cli: produces
- hasher-cli → OpenSSL EVP API: links against
- Shell user → hasher-cli: invokes
- Shell user → File-path argument: supplies
- File-path argument → Argument validation: validated by
- Argument validation → Host filesystem: opens path
- Argument validation → Standard error and exit: invalid invocation
- Host filesystem → Chunked file reader: reads bytes
- Host filesystem → Standard error and exit: access failure
- Chunked file reader → OpenSSL EVP API: updates with chunks
- OpenSSL EVP API → SHA-256 digest: finalizes
- OpenSSL EVP API → Standard error and exit: operation failure
- SHA-256 digest → Standard output: renders as hexadecimal