Search code examples
c++botan

Botan::SecureVector - Destructor called in Constructor?


When using the Botan::SecureVector in the following unit test:

void UnitTest()
{
    std::vector<byte> vbData;
    vbData.push_back(0x04);
    vbData.push_back(0x04);
    vbData.push_back(0x04);

    Botan::SecureVector<Botan::byte> svData(&vbData[0], vbData.size());
    CPPUNIT_ASSERT(vbData == std::vector<byte>(svData.begin(), svData.end()));
}

a segmentation fault occurs when trying to allocate the SecureVector as it tries to deallocate a buffer during its construction.


Solution

  • Add line:

    LibraryInitializer botanInit;
    

    to function.

    This seemed to me to be odd behavior, so I figured I should post it.