aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/test_pkcs11.cpp
blob: 70861cef726e6aaa26020c6be6001b9fa2442f6c (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
/*
* (C) 2016 Daniel Neus
*
* Botan is released under the Simplified BSD License (see license.txt)
*/

#include "test_pkcs11.h"

namespace Botan_Tests {

#if defined(BOTAN_HAS_PKCS11)

std::vector<Test::Result> PKCS11_Test::run_pkcs11_tests(const std::string& name,
      std::vector<std::function<Test::Result()>>& fns)
   {
   std::vector<Test::Result> results;

   for(size_t i = 0; i != fns.size(); ++i)
      {
      try
         {
         results.push_back(fns[ i ]());
         }
      catch(Botan::PKCS11::PKCS11_ReturnError& e)
         {
         results.push_back(Test::Result::Failure(name + " test " + std::to_string(i), e.what()));

         if(e.get_return_value() == Botan::PKCS11::ReturnValue::PinIncorrect)
            {
            break; // Do not continue to not potentially lock the token
            }
         }
      catch(std::exception& e)
         {
         results.push_back(Test::Result::Failure(name + " test " + std::to_string(i), e.what()));
         }
      }

   return results;
   }

#endif

}