CoreComponents 3.0.0
A Modern C++ Toolkit
Loading...
Searching...
No Matches
CryptoHash Class Referencefinal

Cryptographic hash sum. More...

#include <cc/CryptoHash>

Public Types

enum class  Method : uint32_t {
  Invalid = 0 , Md5 = 0x00080 , Sha1 = 0x100A0 , Sha2_256 = 0x20100 ,
  Sha2_512 = 0x20200 , Sha3_224 = 0x300E0 , Sha3_256 = 0x30100 , Sha3_384 = 0x30180 ,
  Sha3_512 = 0x30200 , Sha256 = Sha2_256 , Sha512 = Sha2_512 , Default = Sha3_512
}
 Type of algorithm used to compute the hash sum More...
 

Public Member Functions

 CryptoHash ()=default
 Create an invalid cryptographic hash.
 
 CryptoHash (const String &text)
 Create a cryptographic hash sum by parsing text.
 
 CryptoHash (Method method, const Bytes &sum)
 Create a cryptographic hash sum.
 
Method method () const
 Type of algorithm used to compute the hash sum
 
Bytes sum () const
 Binary representation of the cryptographic hash sum
 
bool isValid () const
 Check is this is a valid cryptographic hash sum.
 
 operator bool () const
 Check is this is a valid cryptographic hash sum.
 
CryptoHashSink openSink () const
 Open an appropriate CryptoHashSink for computing a cryptographic hash sum according to method()
 
bool operator== (const CryptoHash &other) const
 Equality operator.
 
std::strong_ordering operator<=> (const CryptoHash &other) const
 Ordering operator.
 
String toString () const
 Stringify this cryptographic hash sum.
 

Static Public Member Functions

static int hashSize (Method method)
 Size of the hash sum (in bytes)
 
static String methodName (Method method)
 Convert method to human-reable hash name.
 
static Method readMethodName (const String &name)
 Read hash name.
 
static CryptoHash read (const String &text)
 Create a cryptographic hash by parsing text.
 
static CryptoHashSink openSink (Method method)
 Open an appropriate CryptoHashSink for computing a cryptographic hash sum according to method.
 
static CryptoHash compute (Method method, const Stream &source)
 Compute the cryptogaphic hash sum from all bytes readable from source according to method.
 

Detailed Description

Cryptographic hash sum.

Member Enumeration Documentation

◆ Method

enum class Method : uint32_t
strong

Type of algorithm used to compute the hash sum

Enumerator
Invalid 

Invalid hash sum.

Md5 

MD5 hash sum.

Sha1 

SHA1 hash sum.

Sha2_256 

SHA2-256 hash sum.

Sha2_512 

SHA2-512 hash sum.

Sha3_224 

SHA3-224 hash sum.

Sha3_256 

SHA3-256 hash sum.

Sha3_384 

SHA3-384 hash sum.

Sha3_512 

SHA3-512 hash sum.

Sha256 

Alt. name for SHA2-256.

Sha512 

Alt. name for SHA2-512.

Default 

Default hash method to use.

Constructor & Destructor Documentation

◆ CryptoHash() [1/3]

CryptoHash ( )
default

Create an invalid cryptographic hash.

◆ CryptoHash() [2/3]

CryptoHash ( const String & text)

Create a cryptographic hash sum by parsing text.

Parameters
textText represenation of a cryptographic hash value, e.g. "MD5:B1946AC92492D2347C6235B4D2611184"
See also
isValid()
toString()

◆ CryptoHash() [3/3]

CryptoHash ( Method method,
const Bytes & sum )

Create a cryptographic hash sum.

Parameters
methodType of algorithm used to compute the hash sum
sumBinary representation of the cryptographic hash sum

Member Function Documentation

◆ hashSize()

static int hashSize ( Method method)
static

Size of the hash sum (in bytes)

◆ methodName()

static String methodName ( Method method)
static

Convert method to human-reable hash name.

◆ readMethodName()

static Method readMethodName ( const String & name)
static

Read hash name.

◆ read()

CryptoHash read ( const String & text)
static

Create a cryptographic hash by parsing text.

Parameters
textText represenation of a cryptographic hash value, e.g. "MD5:B1946AC92492D2347C6235B4D2611184"
Returns
Cryptographic hash (will return CryptoHash{} when parsing fails)
See also
isValid()
toString()

◆ openSink() [1/2]

CryptoHashSink openSink ( Method method)
static

Open an appropriate CryptoHashSink for computing a cryptographic hash sum according to method.

◆ compute()

CryptoHash compute ( Method method,
const Stream & source )
static

Compute the cryptogaphic hash sum from all bytes readable from source according to method.

◆ method()

Method method ( ) const

Type of algorithm used to compute the hash sum

◆ sum()

Bytes sum ( ) const

Binary representation of the cryptographic hash sum

◆ isValid()

bool isValid ( ) const

Check is this is a valid cryptographic hash sum.

◆ operator bool()

operator bool ( ) const
explicit

Check is this is a valid cryptographic hash sum.

◆ openSink() [2/2]

CryptoHashSink openSink ( ) const

Open an appropriate CryptoHashSink for computing a cryptographic hash sum according to method()

◆ operator==()

bool operator== ( const CryptoHash & other) const

Equality operator.

◆ operator<=>()

std::strong_ordering operator<=> ( const CryptoHash & other) const

Ordering operator.

◆ toString()

String toString ( ) const

Stringify this cryptographic hash sum.