Introduce Key class in tz backend 39/190039/1
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Wed, 26 Sep 2018 15:14:20 +0000 (17:14 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Wed, 26 Sep 2018 15:14:20 +0000 (17:14 +0200)
Add an intermediate Key class that removes the need to keep
credentials from binary data object (BData).

Change-Id: I638de81aedf47bc51421a7c362459ced801fd650

src/manager/crypto/tz-backend/obj.h
src/manager/crypto/tz-backend/store.cpp

index f3459c1..32c6444 100644 (file)
@@ -59,15 +59,25 @@ private:
 
 class BData : public GObj {
 public:
-       BData(int scheme, RawBuffer buffer, Pwd pwd, DataType keyType):
-               m_scheme(scheme), m_raw(std::move(buffer)), m_password(std::move(pwd)),
-               m_type(keyType) {}
+       explicit BData(RawBuffer buffer) : m_raw(std::move(buffer)) {}
 
        virtual RawBuffer getBinary() const override
        {
                return m_raw;
        }
 
+protected:
+       RawBuffer m_raw;
+};
+
+class Key : public BData {
+public:
+       Key(int scheme, RawBuffer buffer, Pwd pwd, DataType dataType) :
+               BData(std::move(buffer)),
+               m_scheme(scheme),
+               m_password(std::move(pwd)),
+               m_type(dataType) {}
+
        virtual int getScheme() const
        {
                return m_scheme;
@@ -80,24 +90,23 @@ public:
 
 protected:
        int m_scheme;
-       RawBuffer m_raw;
        Pwd m_password;
        DataType m_type;
 };
 
-class SKey : public BData {
+class SKey : public Key {
 public:
-       SKey(int scheme, RawBuffer buffer, Pwd pwd, DataType keyType) :
-               BData(scheme, std::move(buffer), std::move(pwd), keyType) {}
+       SKey(int scheme, RawBuffer buffer, Pwd pwd, DataType dataType) :
+               Key(scheme, std::move(buffer), std::move(pwd), dataType) {}
 
        virtual RawBuffer encrypt(const CryptoAlgorithm &, const RawBuffer &);
        virtual RawBuffer decrypt(const CryptoAlgorithm &, const RawBuffer &);
 };
 
-class AKey : public BData {
+class AKey : public Key {
 public:
        AKey(int scheme, RawBuffer buffer, Pwd pwd, DataType dataType) :
-               BData(scheme, std::move(buffer), std::move(pwd), dataType) {}
+               Key(scheme, std::move(buffer), std::move(pwd), dataType) {}
 
        virtual RawBuffer sign(const CryptoAlgorithm &alg, const RawBuffer &message);
        virtual int verify(const CryptoAlgorithm &alg, const RawBuffer &message,
index 3d0179b..92aaad5 100644 (file)
@@ -115,7 +115,7 @@ GObjUPtr Store::getObject(const Token &token, const Password &pass)
 
        if (token.dataType.isBinaryData()) {
                RawBuffer exported_data = Internals::getData(id, Pwd(pass, iv, tag));
-               return make_unique<BData>(scheme, exported_data, Pwd(pass, iv, tag), token.dataType);
+               return make_unique<BData>(std::move(exported_data));
        }
 
        ThrowErr(Exc::Crypto::DataTypeNotSupported,