请小例子。我尝试在文档中使用它,但我无法理解如何。
消息:
main.cpp|97|error: no matching function for call to
'CryptoPP::SecBlock<unsigned char>::operator+=(CryptoPP::SecBlock<unsigned char>*)'
secblock.h|568|note: candidate:
CryptoPP::SecBlock<T, A>& CryptoPP::SecBlock<T, A>::operator+=(const CryptoPP::SecBlock<T, A>&)
[with T = unsigned char; A = CryptoPP::AllocatorWithCleanup<unsigned char>]
secblock.h|568|note:
no known conversion for argument 1 from 'CryptoPP::SecBlock<unsigned char>*'
to 'const CryptoPP::SecBlock<unsigned char>&'
我的代码:
SecBlock<byte, AllocatorWithCleanup<byte> > hash_ripemd160_temp;
RIPEMD160().CalculateDigest(hash_ripemd160_temp, hash_sha256, 32);
SecBlock<byte, AllocatorWithCleanup<byte> > hash_ripemd160 = L0_byte;
hash_ripemd160 = SecBlock< byte , AllocatorWithCleanup<byte > >::operator+= (&hash_ripemd160_temp);
在Docs中如下:
SecBlock<byte , AllocatorWithCleanup<byte > >& SecBlock< byte , AllocatorWithCleanup<byte > >::operator+= (const SecBlock< byte , AllocatorWithCleanup<byte > > &t)
Append contents from another SecBlock.
Parameters
t the other SecBlock
Internally, this SecBlock calls Grow and then copies the new content.
If the memory block is reduced in size, then the unused area is set to 0.
文件secblock.h的第568行定义。
答案 0 :(得分:1)
调用操作符函数的最简单方法是使用运算符:
hash_ripemd160 += hash_ripemd160_temp;
如果你想直接调用它(我不推荐),你必须像这样调用它,因为它是一个成员函数:
hash_ripemd160.operator += (hash_ripemd160_temp);
答案 1 :(得分:0)
如何将两个字节*(secblock)与
连接起来operator 'secblock<T, A>::operator+='
在拉出commit 605744d8260c6ada后尝试以下。 (或者使用git clone https://github.com/weidai11/cryptopp.git
执行新的结帐。)
$ cat test.cxx
#include "ripemd.h"
#include "files.h"
#include "hex.h"
using namespace CryptoPP;
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
SecByteBlock digest(RIPEMD160::DIGESTSIZE);
RIPEMD160 hash;
std::string message("now is the time for all good men to come to the aide of their country");
HexEncoder hexer(new FileSink(cout));
// RIPEMD-160
hash.Update((const byte*)message.data(), message.size());
hash.TruncatedFinal(digest, digest.size());
cout << "RIPEMD-160: ";
hexer.Put(digest, digest.size());
cout << endl;
// Double it
digest += digest;
cout << "RIPEMD-160 (x2): ";
hexer.Put(digest, digest.size());
cout << endl;
return 0;
}
你和艾伦在assert
中发现了拼写错误。我不知道自测没有运用代码路径。现在已经修复了,我们打开了另一个问题来解决工程流程中的缺陷:Need a Code Coverage tool added to the Release Process。
你还在自我连接中发现了一个令人讨厌的小错误(即digest += digest
)。它已被更改为以下内容以检测它:
SecBlock<T, A>& operator+=(const SecBlock<T, A> &t)
{
assert((!t.m_ptr && !t.m_size) || (t.m_ptr && t.m_size));
if(t.m_size)
{
if(this != &t) // s += t
{
const size_type oldSize = m_size;
Grow(m_size+t.m_size);
memcpy_s(m_ptr+oldSize, (m_size-oldSize)*sizeof(T), t.m_ptr, t.m_size*sizeof(T));
}
else // t += t
{
SecBlock result(m_size+t.m_size);
if(m_size) {memcpy_s(result.m_ptr, result.m_size*sizeof(T), m_ptr, m_size*sizeof(T));}
memcpy_s(result.m_ptr+m_size, (result.m_size-m_size)*sizeof(T), t.m_ptr, t.m_size*sizeof(T));
swap(result);
}
}
return *this;
}
在修复/提交之前,它看起来应该在大多数情况下触发InvalidArgument
异常。但是,在Windows上存在一些我们不太确定哪些可能导致静默截断的极端情况。
静默截断令人担忧,我们正在讨论Crypto ++ 5.6.4版本。
答案 2 :(得分:0)
删除&
hash_ripemd160_temp
hash_ripemd160 = SecBlock< byte , AllocatorWithCleanup<byte > >::operator+= (hash_ripemd160_temp);
操作符接受对象,而不是指针。