Sane C++ Libraries
C++ Platform Abstraction Libraries
Hashing

Table of Contents

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

The Hashing library abstracts OS API to compute MD5, SHA1 and SHA256 hashes.

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()));
Hashing::Result res;
SC_TEST_EXPECT(hash.getHash(res));
String test;
SC_TEST_EXPECT(StringBuilder(test).appendHex(res.toBytesSpan(), StringBuilder::AppendHexCase::UpperCase));
SC_TEST_EXPECT(test == "098F6BCD4621D373CADE4E832627B4F6"_a8);
report.console.printLine(test.view());
#define SC_TEST_EXPECT(e)
Records a test expectation (eventually aborting or breaking o n failed test)
Definition: Testing.h:113

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()));
Hashing::Result res;
SC_TEST_EXPECT(hash.getHash(res));
String test;
SC_TEST_EXPECT(StringBuilder(test).appendHex(res.toBytesSpan(), StringBuilder::AppendHexCase::UpperCase));
SC_TEST_EXPECT(test == "05A671C66AEFEA124CC08B76EA6D30BB"_a8);

Roadmap

🟦 Complete Features:

  • None for now

💡 Unplanned Features:

  • None for now