CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
Loading...
Searching...
No Matches
hash::SHA1 Class Reference

compute SHA1 hash More...

#include <sha1.h>

Public Types

enum  { BlockSize = 512 / 8 , HashBytes = 20 }
 split into 64 byte blocks (=> 512 bits), hash is 20 bytes long More...

Public Member Functions

 SHA1 ()
 same as reset()
std::string operator() (const void *data, size_t numBytes)
 compute SHA1 of a memory block
std::string operator() (const std::string &text)
 compute SHA1 of a string, excluding final zero
void add (const void *data, size_t numBytes)
 add arbitrary number of bytes
std::string getHash ()
 return latest hash as 40 hex characters
std::string getHashRaw ()
 return latest hash as raw characters
void getHash (unsigned char buffer[HashBytes])
 return latest hash as bytes
void reset ()
 restart

Detailed Description

compute SHA1 hash

Usage: SHA1 sha1; std::string myHash = sha1("Hello World"); // std::string std::string myHash2 = sha1("How are you", 11); // arbitrary data, 11 bytes

or in a streaming fashion:

SHA1 sha1;
while (more data available)
    sha1.add(pointer to fresh data, number of new bytes);
std::string myHash3 = sha1.getHash();

Definition at line 44 of file sha1.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

split into 64 byte blocks (=> 512 bits), hash is 20 bytes long

Enumerator
BlockSize 
HashBytes 

Definition at line 48 of file sha1.h.

Constructor & Destructor Documentation

◆ SHA1()

hash::SHA1::SHA1 ( )

same as reset()

Member Function Documentation

◆ add()

void hash::SHA1::add ( const void * data,
size_t numBytes )

add arbitrary number of bytes

Referenced by cmlabs::HTTPReply::createWebsocketHTTPReply(), and cmlabs::Hash_UnitTest().

◆ getHash() [1/2]

std::string hash::SHA1::getHash ( )

return latest hash as 40 hex characters

◆ getHash() [2/2]

void hash::SHA1::getHash ( unsigned char buffer[HashBytes])

return latest hash as bytes

References HashBytes.

◆ getHashRaw()

std::string hash::SHA1::getHashRaw ( )

return latest hash as raw characters

Referenced by cmlabs::HTTPReply::createWebsocketHTTPReply(), and cmlabs::Hash_UnitTest().

◆ operator()() [1/2]

std::string hash::SHA1::operator() ( const std::string & text)

compute SHA1 of a string, excluding final zero

◆ operator()() [2/2]

std::string hash::SHA1::operator() ( const void * data,
size_t numBytes )

compute SHA1 of a memory block

◆ reset()

void hash::SHA1::reset ( )

restart

References BlockSize, and HashBytes.

Referenced by cmlabs::HTTPReply::createWebsocketHTTPReply().


The documentation for this class was generated from the following file:
  • /home/ubuntu/c/partner/psyclone2/CMSDK/include/hash/sha1.h