Sane C++ Libraries
C++ Platform Abstraction Libraries
Loading...
Searching...
No Matches
Hashing

🟩 Compute MD5, SHA1 or SHA256 hashes for a stream of bytes

SaneCppHashing.h library abstracts OS API to compute MD5, SHA1 and SHA256 hashes.

Dependencies

  • Dependencies: (none)
  • All dependencies: (none)

Dependency Graph

Features

Hashing Algorithm Description
SC::Hashing::TypeMD5 Compute MD5 hash for the incoming stream of bytes.
SC::Hashing::TypeSHA1 Compute SHA1 hash for the incoming stream of bytes.
SC::Hashing::TypeSHA256 Compute SHA256 hash for the incoming stream of bytes.

Status

🟩 Usable
The library is very simple it it has what is needed so far (mainly by Build).

Description

Compute MD5, SHA1 or SHA256 hash for stream of data.


Data can be added until needed with SC::Hashing::add call. SC::Hashing::getHash will generate an actual SC::Hashing::Result holding the computed hash.

Example:

Hashing hash;
SC_TEST_EXPECT(hash.setType(Hashing::TypeMD5));
SC_TEST_EXPECT(hash.add("test"_a8.toBytesSpan()));
SC_TEST_EXPECT(hash.getHash(res));
String test;
StringBuilder::create(test).appendHex(res.toBytesSpan(), StringBuilder::AppendHexCase::UpperCase));
SC_TEST_EXPECT(test == "098F6BCD4621D373CADE4E832627B4F6"_a8);
report.console.printLine(test.view());

Example with update (for hashing longer streams of data):

Hashing hash;
SC_TEST_EXPECT(hash.setType(Hashing::TypeMD5));
SC_TEST_EXPECT(hash.add("test"_a8.toBytesSpan()));
SC_TEST_EXPECT(hash.add("test"_a8.toBytesSpan()));
SC_TEST_EXPECT(hash.getHash(res));
String test;
StringBuilder::create(test).appendHex(res.toBytesSpan(), StringBuilder::AppendHexCase::UpperCase));
SC_TEST_EXPECT(test == "05A671C66AEFEA124CC08B76EA6D30BB"_a8);

Roadmap

🟦 Complete Features:

  • None for now

💡 Unplanned Features:

  • None for now

Statistics

LOC counts exclude comments. Library counts files physically under Libraries/Hashing. Single File counts SaneCppHashing.h. Standalone counts SaneCppHashingStandalone.h and intentionally includes dependency payloads.

Metric Header Source Sum
Library 95 292 387
Single File 404 372 776
Standalone 404 372 776