本文整理汇总了C++中Hash::update方法的典型用法代码示例。如果您正苦于以下问题:C++ Hash::update方法的具体用法?C++ Hash::update怎么用?C++ Hash::update使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hash
的用法示例。
在下文中一共展示了Hash::update方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: write
size_t write(const void *buf, size_t count)
{
// Hash, then write
hash.update(buf, count);
summed += count;
return src->write(buf,count);
}
示例2: sum
/* Directly sum an entire stream. The stream is read in increments,
to avoid loading large files into memory. You can specify the
buffer size as the second parameter, the default is 16 Kb.
The algorithm does not depend on size() for non-pointer streams.
Pointer streams are hashed in one go, and do not advance the file
pointer.
Since the position of the file pointer after this operation
depends on the type of stream given, it is considered undefined.
*/
static Hash sum(Mangle::Stream::Stream &str, int bufsize = DEFSIZE)
{
assert(str.isReadable);
// Is this a memory stream?
if(str.hasPtr)
{
assert(str.hasSize);
// Pointer streams makes life easy
return Hash(str.getPtr(), str.size());
}
// No pointers today. Create a buffer and hash in increments.
char *buf = new char[bufsize];
Hash result;
// We do not depend on the stream size, only on eof().
while(!str.eof())
{
size_t num = str.read(buf, bufsize);
// If we read less than expected, we should be at the
// end of the stream
assert(num == bufsize || (num < bufsize && str.eof()));
// Hash the data
result.update(buf, num);
}
// Clean up and return
delete[] buf;
return result.finish();
}
示例3: read
size_t read(void *buf, size_t count)
{
// Read, then hash
size_t res = src->read(buf, count);
// And make sure to only hash actual bytes read
hash.update(buf, res);
summed += res;
return res;
}
示例4:
Hmac (const unsigned char* arg_key, size_t arg_key_len =KEY_LENGTH)
{
if (arg_key_len > Hash::BLOCK_LENGTH) {
Hash::compute(key, Hash::BLOCK_LENGTH, arg_key, arg_key_len);
key_len = Hash::LENGTH;
} else {
std::memcpy(key, arg_key, arg_key_len);
key_len = arg_key_len;
}
unsigned char k_ipad[Hash::BLOCK_LENGTH];
std::memset(k_ipad, 0, Hash::BLOCK_LENGTH);
std::memcpy(k_ipad, key, key_len);
for (size_t i = 0; i < Hash::BLOCK_LENGTH; ++i) {
k_ipad[i] ^= 0x36;
}
hash.update(k_ipad, Hash::BLOCK_LENGTH);
explicit_memzero(k_ipad, Hash::BLOCK_LENGTH);
}