Cipherpack v1.2.0-dirty
A Cryprographic Stream Processor
Functions
cipherpack::hash_util Namespace Reference

Hash utility functions to produce a hash file compatible to sha256sum as well as to produce the hash value itself for validation. More...

Functions

bool append_to_file (const std::string &out_file, const std::string &hashed_file, const std::string_view &hash_algo, const std::vector< uint8_t > &hash_value) noexcept
 Append the hash signature to the text file out_file. More...
 
std::unique_ptr< std::vector< uint8_t > > calc (const std::string_view &algo, const std::string &path_or_uri, uint64_t &bytes_hashed, jau::fraction_i64 timeout=20_s) noexcept
 Return the calculated hash value using given algo name and the bytes of a single file or all files if denoting a directory. More...
 
std::unique_ptr< std::vector< uint8_t > > calc (const std::string_view &algo, jau::io::ByteInStream &source) noexcept
 Return the calculated hash value using given algo name and byte input stream. More...
 
std::string file_suffix (const std::string &algo) noexcept
 Return a lower-case file suffix used to store a sha256sum compatible hash signature w/o dot and w/o dashes. More...
 

Detailed Description

Hash utility functions to produce a hash file compatible to sha256sum as well as to produce the hash value itself for validation.

Function Documentation

◆ file_suffix()

std::string cipherpack::hash_util::file_suffix ( const std::string &  algo)
noexcept

Return a lower-case file suffix used to store a sha256sum compatible hash signature w/o dot and w/o dashes.

Examples
test_01_cipherpack.cpp.

Definition at line 348 of file crypto0.cpp.

◆ append_to_file()

bool cipherpack::hash_util::append_to_file ( const std::string &  out_file,
const std::string &  hashed_file,
const std::string_view &  hash_algo,
const std::vector< uint8_t > &  hash_value 
)
noexcept

Append the hash signature to the text file out_file.

The hash signature is composed as follows

  • hash algo name
  • space
  • hash value
  • space
  • * to denote binary processing
  • hashed file name

The hash signature is similar to sha256sum output, but the added hash algo name upfront.

Parameters
out_filethe text file to append hash signature of hashed_file.
hashed_filethe file of the hash signature
hash_algothe hash algo name used
hash_valuethe hash value of hashed_file
Returns
true if successful, otherwise false
Examples
commandline.cpp, and test_01_cipherpack.cpp.

Definition at line 358 of file crypto0.cpp.

Here is the caller graph for this function:

◆ calc() [1/2]

std::unique_ptr< std::vector< uint8_t > > cipherpack::hash_util::calc ( const std::string_view &  algo,
jau::io::ByteInStream &  source 
)
noexcept

Return the calculated hash value using given algo name and byte input stream.

Parameters
algothe hash algo name
sourcethe byte input stream
Returns
the calculated hash value or nullptr in case of error
Examples
commandline.cpp, and test_01_cipherpack.cpp.

Definition at line 386 of file crypto0.cpp.

Here is the caller graph for this function:

◆ calc() [2/2]

std::unique_ptr< std::vector< uint8_t > > cipherpack::hash_util::calc ( const std::string_view &  algo,
const std::string &  path_or_uri,
uint64_t &  bytes_hashed,
jau::fraction_i64  timeout = 20_s 
)
noexcept

Return the calculated hash value using given algo name and the bytes of a single file or all files if denoting a directory.

Parameters
algothe hash algo name
path_or_urigiven path or uri, either a URI denoting a single file, a single file path or directory path for which all files (not symbolic links) are considered
bytes_hashedreturns overall bytes hashed
timeoutin case path_or_uri refers to an URI, timeout is being used as maximum duration to wait for next bytes. Defaults to 20_s.
Returns
the calculated hash value or nullptr in case of error

Definition at line 411 of file crypto0.cpp.