Replace shared ptr with unique ptr. 22/42322/1
authorBartlomiej Grzelewski <b.grzelewski@samsung.com>
Thu, 25 Jun 2015 15:48:19 +0000 (17:48 +0200)
committerBartlomiej Grzelewski <b.grzelewski@samsung.com>
Thu, 25 Jun 2015 15:58:53 +0000 (17:58 +0200)
Change-Id: I7542c03078dc449dfb925824e8e89d11fcffcde9

src/manager/crypto/generic-backend/gkey.h
src/manager/crypto/generic-backend/gstore.h
src/manager/crypto/sw-backend/store.cpp
src/manager/crypto/sw-backend/store.h
src/manager/crypto/tz-backend/store.cpp
src/manager/crypto/tz-backend/store.h

index f153f3e..530842d 100644 (file)
@@ -56,7 +56,7 @@ public:
     virtual ~GKey () {}
 };
 
-typedef std::shared_ptr<GKey> GKeyShPtr;
+typedef std::unique_ptr<GKey> GKeyUPtr;
 
 } // namespace Crypto
 } // namespace CKM
index 13c7d26..2c8aca7 100644 (file)
@@ -33,7 +33,7 @@ namespace Crypto {
 
 class GStore {
 public:
-    virtual GKeyShPtr getKey(const Token &) { ThrowErr(Exc::Crypto::OperationNotSupported); }
+    virtual GKeyUPtr getKey(const Token &) { ThrowErr(Exc::Crypto::OperationNotSupported); }
     virtual TokenPair generateAKey(const CryptoAlgorithm &) { ThrowErr(Exc::Crypto::OperationNotSupported); }
     virtual Token generateSKey(const CryptoAlgorithm &) { ThrowErr(Exc::Crypto::OperationNotSupported); }
     virtual Token import(DataType, const RawBuffer &) { ThrowErr(Exc::Crypto::OperationNotSupported); }
index 9f18575..8888ea9 100644 (file)
 #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 {
@@ -36,21 +45,21 @@ Store::Store(CryptoBackend backendId)
     Internals::initialize();
 }
 
-GKeyShPtr Store::getKey(const Token &token) {
+GKeyUPtr Store::getKey(const Token &token) {
     if (token.backendId != m_backendId) {
         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);
     }
 
     ThrowErr(Exc::Crypto::KeyNotSupported,
index 09350e8..cb23155 100644 (file)
@@ -31,7 +31,7 @@ class Store : public GStore {
 public:
     explicit Store(CryptoBackend backendId);
 
-    virtual GKeyShPtr getKey(const Token &token);
+    virtual GKeyUPtr getKey(const Token &token);
     virtual TokenPair generateAKey(const CryptoAlgorithm &);
     virtual Token generateSKey(const CryptoAlgorithm &);
     virtual Token import(DataType dataType, const RawBuffer &buffer);
index 100ca6f..11ac0b0 100644 (file)
@@ -30,7 +30,7 @@ Store::Store(CryptoBackend backendId)
   : GStore(backendId)
 {}
 
-GKeyShPtr Store::getKey(const Token &) {
+GKeyUPtr Store::getKey(const Token &) {
     ThrowErr(Exc::Crypto::OperationNotSupported, "Trust zone backend is not implemented!");
 }
 
index bbfb34e..ee5d24b 100644 (file)
@@ -31,7 +31,7 @@ class Store : public GStore {
 public:
     explicit Store(CryptoBackend backendId);
 
-    virtual GKeyShPtr getKey(const Token &token);
+    virtual GKeyUPtr getKey(const Token &token);
     virtual TokenPair generateAKey(const CryptoAlgorithm &);
     virtual Token import(DataType dataType, const RawBuffer &buffer);
     virtual void destroy(const Token &){}