aboutsummaryrefslogtreecommitdiffstats
path: root/doc/examples/base.cpp
blob: eca0ccf24dcf1f9f3e7b76090d45f7e13fc8d23b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
   A simple template for Botan applications, showing startup, etc
*/
#include <botan/botan.h>
using namespace Botan;

/* This is how you can do compile-time version checking */

#if BOTAN_VERSION_CODE < BOTAN_VERSION_CODE_FOR(1,6,3)
  #error Your Botan installation is too old; upgrade to 1.6.3 or later
#endif

#include <iostream>

int main(int argc, char* argv[])
   {
   Botan::LibraryInitializer init;

   try
      {
      /* Put it inside the try block so exceptions at startup/shutdown will
         get caught.

         It will be initialized with default options
      */

      if(argc > 2)
         {
         std::cout << "Usage: " << argv[0] << "[initializer args]\n";
         return 2;
         }

      std::string args = (argc == 2) ? argv[1] : "";

      LibraryInitializer init(args);
      // your operations here
   }
   catch(std::exception& e)
      {
      std::cout << e.what() << std::endl;
      return 1;
      }
   return 0;
   }