aboutsummaryrefslogtreecommitdiff
path: root/openssl/agent/pkcs11/pkcs11.hxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2018-10-15 21:08:04 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2018-10-17 15:02:42 +0300
commitde91921561092689369b56c54950474e0a86e66f (patch)
treea9949058021d911db1106b1a2e4d9e0e9281de16 /openssl/agent/pkcs11/pkcs11.hxx
parentfb65c93daaf369157bd712f2c4c20161c4840b94 (diff)
Add implementation
Diffstat (limited to 'openssl/agent/pkcs11/pkcs11.hxx')
-rw-r--r--openssl/agent/pkcs11/pkcs11.hxx63
1 files changed, 63 insertions, 0 deletions
diff --git a/openssl/agent/pkcs11/pkcs11.hxx b/openssl/agent/pkcs11/pkcs11.hxx
new file mode 100644
index 0000000..e1c90b1
--- /dev/null
+++ b/openssl/agent/pkcs11/pkcs11.hxx
@@ -0,0 +1,63 @@
+// file : openssl/agent/pkcs11/pkcs11.hxx -*- C++ -*-
+// copyright : Copyright (c) 2014-2018 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#ifndef OPENSSL_AGENT_PKCS11_PKCS11_HXX
+#define OPENSSL_AGENT_PKCS11_PKCS11_HXX
+
+// PKCS#11 API (Cryptoki) definitions.
+//
+#include <openssl/agent/pkcs11/pkcs11.h>
+
+#include <openssl/types.hxx>
+#include <openssl/utility.hxx>
+
+namespace openssl
+{
+ namespace agent
+ {
+ namespace pkcs11
+ {
+ // For simplicity we will not handle multiple PKCS#11 modules
+ // simultaneously. The first one loaded will stay till the end of the
+ // process lifetime.
+ //
+
+ // Return the PKCS#11 API pointer. If requested, ignore non-existent
+ // module returning NULL.
+ //
+ // On the first call load the PKCS#11 module using the specified path
+ // and initialize the API. Return the same pointer on the subsequent
+ // calls regardless of the path. Throw runtime_error if anything goes
+ // wrong.
+ //
+ CK_FUNCTION_LIST*
+ api (const path&, bool ignore_nonexistent = false);
+
+ // Return a pointer to the previously initialized PKCS#11 API.
+ //
+ CK_FUNCTION_LIST*
+ api ();
+
+ // Throw runtime_error describing a PKCS#11 API error.
+ //
+ [[noreturn]] void
+ throw_api_error (CK_RV error, string what);
+
+ // Convert API string representation to a regular one.
+ //
+ // PKCS#11 API struct string members are fixed-sized unsigned character
+ // arrays right-padded with the space character. Return such a string
+ // with the trailing spaces stripped.
+ //
+ inline string
+ api_string (const unsigned char* s, size_t n)
+ {
+ for (; n != 0 && s[n - 1] == ' '; --n) ;
+ return string (reinterpret_cast<const char*> (s), n);
+ }
+ }
+ }
+}
+
+#endif // OPENSSL_AGENT_PKCS11_PKCS11_HXX