aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/test_pkcs11.h
blob: 696fcc6aec2f74af4ea4cbd36cff8aabc8cd0a6b (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* (C) 2016 Daniel Neus
* (C) 2019 Michael Boric
*
* Botan is released under the Simplified BSD License (see license.txt)
*/

#ifndef BOTAN_TESTS_PKCS11_H_
#define BOTAN_TESTS_PKCS11_H_

#include "tests.h"

#if defined(BOTAN_HAS_PKCS11)
   #include <botan/p11.h>
#endif

#include <string>
#include <vector>

namespace Botan_Tests {

#if defined(BOTAN_HAS_PKCS11)

#define STRING_AND_FUNCTION(x) #x, x

// PIN is expected to be set to "123456" prior to running the tests
const std::string PKCS11_USER_PIN = "123456";
// SO PIN is expected to be set to "12345678" prior to running the tests
const std::string PKCS11_SO_PIN = "12345678";

// These are pins that should just not match the above (valid) PINs
const std::string PKCS11_TEST_USER_PIN = "654321";
const std::string PKCS11_TEST_SO_PIN = "87654321";

inline Botan::PKCS11::secure_string to_sec_string(const std::string& str)
   {
   return Botan::PKCS11::secure_string(str.begin(), str.end());
   }

inline Botan::PKCS11::secure_string PIN()
   {
   return to_sec_string(PKCS11_USER_PIN);
   }

inline Botan::PKCS11::secure_string SO_PIN()
   {
   return to_sec_string(PKCS11_SO_PIN);
   }

inline Botan::PKCS11::secure_string TEST_PIN()
   {
   return to_sec_string(PKCS11_TEST_USER_PIN);
   }

inline Botan::PKCS11::secure_string TEST_SO_PIN()
   {
   return to_sec_string(PKCS11_TEST_SO_PIN);
   }

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

#endif
}

#endif