[Botan-devel] SQLite3 encryption codec with Botan

Jack Lloyd lloyd at randombit.net
Mon Apr 20 17:09:15 EDT 2009


On Sun, Apr 19, 2009 at 12:27:34PM +0800, Mr Diggilin wrote:
> Hi Jack,
> I've got another question in regards to this codec... how should I deal
> with the LibraryInitializer?
> Obviously I don't have a main function to put it in. There can be
> multiple "codecs" loaded at once so constructor/destructor is also out.
> Also... there's the possibility of the user using botan in their own
> code.
> Is there a way to check the state of the LibraryInitializer?

Yes, though it's a bit ugly:

There is a function declared in libstate.h, swap_global_state():

Library_State* swap_global_state(Library_State*);

It sets a new state and returns the old one. So one way to detect
if botan is initialized is

bool is_initialized = false;
Library_State* state = swap_global_state(0);
if(state)
  {
  is_initialized = true;
  swap_global_state(state); // should return NULL
  }

The problem: if any access to botan is made between the swaps (for
instance in another thread) the state will be reinitialized. This
case could be detected by checking the return value of the second
swap_global_state.

-Jack



More information about the botan-devel mailing list