CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
Loading...
Searching...
No Matches
crc32.h
Go to the documentation of this file.
1
6// //////////////////////////////////////////////////////////
7// crc32.h
8// Copyright (c) 2014,2015 Stephan Brumme. All rights reserved.
9// see http://create.stephan-brumme.com/disclaimer.html
10//
11
12#pragma once
13
14//#include "hash.h"
15#include <string>
16
17// define fixed size integer types
18#ifdef _MSC_VER
19// Windows
20typedef unsigned __int8 uint8_t;
21typedef unsigned __int32 uint32_t;
22#else
23// GCC
24#include <stdint.h>
25#endif
26
27// Added namespace to avoid clash with OpenSSL
28namespace hash {
29
31
48class CRC32 //: public Hash
49{
50public:
52 enum { HashBytes = 4 };
53
56
58 std::string operator()(const void* data, size_t numBytes);
60 std::string operator()(const std::string& text);
61
63 void add(const void* data, size_t numBytes);
64
66 std::string getHash();
68 void getHash(unsigned char buffer[HashBytes]);
69
71 void reset();
72
73private:
75 uint32_t m_hash;
76};
77
78} // namespace hash
std::string getHash()
return latest hash as 8 hex characters
std::string operator()(const std::string &text)
compute CRC32 of a string, excluding final zero
CRC32()
same as reset()
void add(const void *data, size_t numBytes)
add arbitrary number of bytes
@ HashBytes
Definition crc32.h:52
void reset()
restart
std::string operator()(const void *data, size_t numBytes)
compute CRC32 of a memory block
void getHash(unsigned char buffer[HashBytes])
return latest hash as bytes
Usage: std::string msg = "The quick brown fox jumps over the lazy dog"; std::string key = "key"; std:...
Definition crc32.h:28