2015-12-27 13 views
1

請小例子。我試過在文檔中使用這個,但我無法理解如何。如何連接兩個字節*(secblock)與運算符'secblock <T, A> :: operator + ='

消息:

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); 

在文檔是:在文件secblock.h的568線

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. 

定義。

+0

Вадим和Alan ...再次感謝您對此問題的幫助。這真的讓我很煩惱,我們沒有及時趕上。我將重新評估我們的工程過程,以期在事後分析中尋找差距。 – jww

回答

1

調用操作功能的最簡單的方式就是使用操作:如果您想直接(我不會推薦)調用它,你必須這樣調用

hash_ripemd160 += hash_ripemd160_temp; 

,因爲它是一個成員函數:

hash_ripemd160.operator += (hash_ripemd160_temp); 
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版本。

+0

謝謝你的出色工作! –

+0

結果:EEE46B312007181E9B2E48C9361A58CC26EF1EBD和EEE46B312007181E9B2E48C9361A58CC26EF1EBDEEE46B312007181E9B2E48D9481A58CC26EF1EBD。再次感謝。 –

0

卸下&之前hash_ripemd160_temp

hash_ripemd160 = SecBlock< byte , AllocatorWithCleanup<byte > >::operator+= (hash_ripemd160_temp); 

操作者接受該對象,而不是指針。