*/
#include <memory>
-#include <dpl/log/log.h>
-
#include <generic-backend/exception.h>
#include <sw-backend/key.h>
#include <sw-backend/store.h>
+#include <sw-backend/internals.h>
+
+namespace {
+
+template <typename T, typename ...Args>
+std::unique_ptr<T> make_unique(Args&& ...args) {
+ return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
+}
+
+} // namespace anonymous
namespace CKM {
namespace Crypto {
namespace SW {
-GKeyShPtr Store::getKey(const Token &token) {
+Store::Store(CryptoBackend backendId)
+ : GStore(backendId)
+{
+ // initialize openssl internals
+ Internals::initialize();
+}
+
+GKeyUPtr Store::getKey(const Token &token) {
if (token.backendId != m_backendId) {
- LogError("Decider choose wrong backend!");
- ThrowMsg(Exception::WrongBackend, "Decider choose wrong backend!");
+ ThrowErr(Exc::Crypto::WrongBackend, "Decider choose wrong backend!");
}
if (token.dataType.isKeyPrivate() || token.dataType.isKeyPublic()) {
- return std::make_shared<AKey>(token.data, token.dataType);
+ return make_unique<AKey>(token.data, token.dataType);
}
if (token.dataType == DataType(DataType::KEY_AES)) {
- return std::make_shared<SKey>(token.data, token.dataType);
+ return make_unique<SKey>(token.data, token.dataType);
}
if (token.dataType.isCertificate()) {
- return std::make_shared<Cert>(token.data, token.dataType);
+ return make_unique<Cert>(token.data, token.dataType);
}
- LogDebug(
- "This type of data is not supported by openssl backend: " << (int)token.dataType);
- ThrowMsg(Exception::KeyNotSupported,
- "This type of data is not supported by openssl backend: " << (int)token.dataType);
+ ThrowErr(Exc::Crypto::KeyNotSupported,
+ "This type of data is not supported by openssl backend: ", (int)token.dataType);
+}
+
+TokenPair Store::generateAKey(const CryptoAlgorithm &algorithm)
+{
+ return Internals::generateAKey(m_backendId, algorithm);
+}
+
+Token Store::generateSKey(const CryptoAlgorithm &algorithm)
+{
+ return Internals::generateSKey(m_backendId, algorithm);
}
Token Store::import(DataType dataType, const RawBuffer &buffer) {