1 /** 2 * Library Initialization 3 * 4 * Copyright: 5 * (C) 1999-2008 Jack Lloyd 6 * (C) 2014-2015 Etienne Cimon 7 * 8 * License: 9 * Botan is released under the Simplified BSD License (see LICENSE.md) 10 */ 11 module botan.libstate.init; 12 13 import botan.libstate.libstate; 14 import botan.libstate.global_state; 15 16 /** 17 * This class represents the Library Initialization/Shutdown Object. It 18 * has to exceed the lifetime of any Botan object used in an 19 * application. You can call initialize/deinitialize or use 20 * LibraryInitializer in the RAII style. 21 */ 22 struct LibraryInitializer 23 { 24 public: 25 /** 26 * Initialize the library 27 */ 28 static void initialize() 29 { 30 31 try 32 { 33 setGlobalState(LibraryState.init); 34 35 globalState().initialize(); 36 } 37 catch (Exception) 38 { 39 deinitialize(); 40 throw new Exception("Library innullitialization failed"); 41 } 42 } 43 44 /** 45 * Shutdown the library 46 */ 47 static void deinitialize() { 48 setGlobalState(LibraryState.init); 49 } 50 51 /** 52 * Initialize the library 53 * Params: 54 * options = a string listing initialization options 55 */ 56 this(string options) { LibraryInitializer.initialize(); } 57 58 ~this() { LibraryInitializer.deinitialize(); } 59 }