Identifier "unlock" is undefined

537 Views Asked by At

In this example code

http://botan.randombit.net/manual/fpe.html

there is a method that I am trying to use in a Visual C++ managed wrapper, but I keep getting compile error on the 'unlock' What is this? (could it be mutex::unlock) And how can i resolve the error?

std::vector<byte> sha1(const std::string& acct_name)
   {
   SHA_160 hash;
   hash.update(acct_name);
   return unlock(hash.final());
   }

Error 16 error C3861: 'unlock': identifier not found

EDIT: My Stdafx.h file now looks like this but it is still not compiling (even after including secmem.h)

#pragma once

#include <botan/botan.h>
#include <botan/fpe_fe1.h>
#include <botan/sha160.h>
#include <botan/secmem.h>
#include <stdexcept>
#include <vector>

EDIT: Additional information - version of Botan library I'm using is Version 1.10.9 (latest Stable). I compiled using the python script and did not exclude any modules (built it with everything) in debug mode.

2

There are 2 best solutions below

6
On BEST ANSWER

I just checked and looks like Botan v. 1.10.9 doesn’t have unlock. You have two options.

The version 1.10.9 has another final method where you can pass a vector of byte as reference to get the return.

Something like:

byte out[hash.output_length()];
hash.final(out);

Another option is to convert from SecureVector to std::vector.

SecureVector<byte> temp = hash.final();
std::vector<byte> ret(temp.begin(), temp.end());

Depending of my application, I would chose one over the other.

.

Just in case someone come to this question and is using Botan 1.11.

The method unlock to convert from SecureVector to std::vector is in the header secman.h. In addition, the class SHA_160 has another final method where you can pass as a parameter a std::vector<byte> to get the output. With this method, you wouldnt need the unlock function.

0
On

The tutorial uses this

using namespace Botan;

Maybe it is a namespace problem. Either you also declare the Botan namespace as "using", or you use Botan::unlock instead of unlock.

I'd recommend the second one, even if it seems longer. It's worth it!