Refactor DataType related code 22/232722/6
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Thu, 7 May 2020 08:27:08 +0000 (10:27 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Mon, 18 May 2020 08:22:59 +0000 (10:22 +0200)
* Remove unnecessary DataType methods.
* Remove unnecessary Type enumeration scope.
* Make DataType serializable to avoid static casts.
* Use DataType checker methods instead of explicit DataType::Type comparison.

Change-Id: I01dc355050326ad1e40c34c869acbc07613c57db

16 files changed:
src/manager/client-async/client-manager-async-impl.cpp
src/manager/client-async/storage-receiver.cpp
src/manager/client/client-manager-impl.cpp
src/manager/common/data-type.cpp
src/manager/common/data-type.h
src/manager/crypto/sw-backend/obj.cpp
src/manager/crypto/sw-backend/store.cpp
src/manager/crypto/tz-backend/internals.cpp
src/manager/crypto/tz-backend/obj.cpp
src/manager/crypto/tz-backend/store.cpp
src/manager/service/ckm-logic.cpp
src/manager/service/ckm-service.cpp
src/manager/service/db-crypto.cpp
tests/encryption-scheme/scheme-test.h
tests/test_crypto-logic.cpp
tests/test_data-type.cpp

index b02106e..19479f0 100644 (file)
@@ -96,7 +96,7 @@ void ManagerAsync::Impl::saveBinaryData(const ManagerAsync::ObserverPtr
                AliasSupport helper(alias);
 
                sendToStorage(observer, static_cast<int>(LogicCommand::SAVE), m_counter,
-                                         static_cast<int>(dataType), helper.getName(), helper.getOwner(), rawData,
+                                         dataType, helper.getName(), helper.getOwner(), rawData,
                                          PolicySerializable(policy));
        }, [&observer](int error) {
                observer->ReceivedError(error);
@@ -155,7 +155,7 @@ void ManagerAsync::Impl::getBinaryData(const ManagerAsync::ObserverPtr
                AliasSupport helper(alias);
 
                sendToStorage(observer, static_cast<int>(LogicCommand::GET), m_counter,
-                                         static_cast<int>(sendDataType), helper.getName(), helper.getOwner(), password);
+                                         sendDataType, helper.getName(), helper.getOwner(), password);
        }, [&observer](int error) {
                observer->ReceivedError(error);
        });
@@ -289,8 +289,7 @@ void ManagerAsync::Impl::getBinaryDataAliasVector(const
 {
        observerCheck(observer);
        try_catch_async([&]() {
-               sendToStorage(observer, static_cast<int>(LogicCommand::GET_LIST), m_counter,
-                                         static_cast<int>(dataType));
+               sendToStorage(observer, static_cast<int>(LogicCommand::GET_LIST), m_counter, dataType);
        }, [&observer](int error) {
                observer->ReceivedError(error);
        });
index 4888cdc..6095d09 100644 (file)
@@ -115,7 +115,8 @@ void StorageReceiver::processResponse()
 void StorageReceiver::parseGetCommand()
 {
        RawBuffer rawData;
-       int dataType = 0, retCode = 0;
+       DataType dataType;
+       int retCode = 0;
        m_buffer.Deserialize(retCode, dataType, rawData);
 
        // check error code
@@ -124,14 +125,13 @@ void StorageReceiver::parseGetCommand()
                return;
        }
 
-       DataType type(dataType);
-       if (type.isSKey())
+       if (dataType.isSKey())
                m_observer->ReceivedKey(KeyAESImpl(rawData));
-       else if (type.isKey())
+       else if (dataType.isKey())
                m_observer->ReceivedKey(KeyImpl(rawData));
-       else if (type.isCertificate())
+       else if (dataType.isCertificate())
                m_observer->ReceivedCertificate(CertificateImpl(rawData, DataFormat::FORM_DER));
-       else if (type.isBinaryData())
+       else if (dataType.isBinaryData())
                m_observer->ReceivedData(std::move(rawData));
        else
                m_observer->ReceivedError(CKM_API_ERROR_BAD_RESPONSE);
@@ -154,7 +154,8 @@ void StorageReceiver::parseGetPKCS12Command()
 
 void StorageReceiver::parseGetListCommand()
 {
-       int dataType = 0, retCode = 0;
+       DataType dataType;
+       int retCode = 0;
        OwnerNameVector ownerNameVector;
        m_buffer.Deserialize(retCode, dataType, ownerNameVector);
 
@@ -169,13 +170,11 @@ void StorageReceiver::parseGetListCommand()
        for (const auto &it : ownerNameVector)
                aliasVector.push_back(AliasSupport::merge(it.first, it.second));
 
-       DataType type(dataType);
-
-       if (type.isKey())
+       if (dataType.isKey())
                m_observer->ReceivedKeyAliasVector(std::move(aliasVector));
-       else if (type.isCertificate())
+       else if (dataType.isCertificate())
                m_observer->ReceivedCertificateAliasVector(std::move(aliasVector));
-       else if (type.isBinaryData())
+       else if (dataType.isBinaryData())
                m_observer->ReceivedDataAliasVector(std::move(aliasVector));
        else
                m_observer->ReceivedError(CKM_API_ERROR_BAD_RESPONSE);
@@ -183,7 +182,8 @@ void StorageReceiver::parseGetListCommand()
 
 void StorageReceiver::parseSaveCommand()
 {
-       int dataType = 0, retCode = 0;
+       DataType dataType;
+       int retCode = 0;
        m_buffer.Deserialize(retCode, dataType);
 
        // check error code
@@ -192,13 +192,11 @@ void StorageReceiver::parseSaveCommand()
                return;
        }
 
-       DataType type(dataType);
-
-       if (type.isKey())
+       if (dataType.isKey())
                m_observer->ReceivedSaveKey();
-       else if (type.isCertificate())
+       else if (dataType.isCertificate())
                m_observer->ReceivedSaveCertificate();
-       else if (type.isBinaryData())
+       else if (dataType.isBinaryData())
                m_observer->ReceivedSaveData();
        else
                m_observer->ReceivedError(CKM_API_ERROR_BAD_RESPONSE);
index 0728c62..a1f70af 100644 (file)
@@ -115,7 +115,7 @@ int Manager::Impl::saveBinaryData(
        AliasSupport helper(alias);
        auto send = MessageBuffer::Serialize(static_cast<int>(LogicCommand::SAVE),
                                                                                 msgId,
-                                                                                static_cast<int>(dataType),
+                                                                                dataType,
                                                                                 helper.getName(),
                                                                                 helper.getOwner(),
                                                                                 rawData,
@@ -307,7 +307,7 @@ int Manager::Impl::getBinaryData(
        AliasSupport helper(alias);
        auto send = MessageBuffer::Serialize(static_cast<int>(LogicCommand::GET),
                                                                                 msgId,
-                                                                                static_cast<int>(sendDataType),
+                                                                                sendDataType,
                                                                                 helper.getName(),
                                                                                 helper.getOwner(),
                                                                                 password);
@@ -318,9 +318,7 @@ int Manager::Impl::getBinaryData(
                return retCode;
 
        int retMsgId;
-       int tmpDataType;
-       recv.Deserialize(retMsgId, retCode, tmpDataType, rawData);
-       recvDataType = DataType(tmpDataType);
+       recv.Deserialize(retMsgId, retCode, recvDataType, rawData);
 
        if (retMsgId != msgId)
                return CKM_API_ERROR_UNKNOWN;
@@ -345,7 +343,7 @@ int Manager::Impl::getBinaryDataEncryptionStatus(const DataType sendDataType,
        AliasSupport helper(alias);
        auto send = MessageBuffer::Serialize(static_cast<int>(LogicCommand::GET_PROTECTION_STATUS),
                                                                                 msgId,
-                                                                                static_cast<int>(sendDataType),
+                                                                                sendDataType,
                                                                                 helper.getName(),
                                                                                 helper.getOwner());
 
@@ -355,7 +353,7 @@ int Manager::Impl::getBinaryDataEncryptionStatus(const DataType sendDataType,
                return retCode;
 
        int retMsgId;
-       int tmpDataType;
+       DataType tmpDataType;
        bool passwordProtectionStatus;
        recv.Deserialize(retMsgId, retCode, tmpDataType, passwordProtectionStatus);
 
@@ -389,7 +387,7 @@ int Manager::Impl::getKey(const Alias &alias, const Password &password,
 
        KeyShPtr keyParsed;
 
-       if (DataType::KEY_AES == recvDataType)
+       if (recvDataType.isSKey())
                keyParsed = KeyShPtr(new KeyAESImpl(rawData));
        else
                keyParsed = KeyShPtr(new KeyImpl(rawData));
@@ -420,7 +418,7 @@ int Manager::Impl::getCertificate(const Alias &alias, const Password &password,
        if (retCode != CKM_API_SUCCESS)
                return retCode;
 
-       if (recvDataType != DataType::CERTIFICATE)
+       if (!recvDataType.isCertificate())
                return CKM_API_ERROR_BAD_RESPONSE;
 
        CertificateShPtr certParsed(new CertificateImpl(rawData, DataFormat::FORM_DER));
@@ -448,7 +446,7 @@ int Manager::Impl::getData(const Alias &alias, const Password &password,
        if (retCode != CKM_API_SUCCESS)
                return retCode;
 
-       if (recvDataType != DataType::BINARY_DATA)
+       if (!recvDataType.isBinaryData())
                return CKM_API_ERROR_BAD_RESPONSE;
 
        return CKM_API_SUCCESS;
@@ -462,7 +460,7 @@ int Manager::Impl::getBinaryDataAliasVectorHelper(DataType dataType,
        MessageBuffer recv;
        auto send = MessageBuffer::Serialize(static_cast<int>(LogicCommand::GET_LIST),
                                                                                 msgId,
-                                                                                static_cast<int>(dataType));
+                                                                                dataType);
 
        int retCode = m_storageConnection.processRequest(send.Pop(), recv);
 
@@ -470,7 +468,7 @@ int Manager::Impl::getBinaryDataAliasVectorHelper(DataType dataType,
                return retCode;
 
        int retMsgId;
-       int tmpDataType;
+       DataType tmpDataType;
        recv.Deserialize(retMsgId, retCode, tmpDataType, ownerNameVector);
 
        if (retMsgId != msgId)
index 8de9e15..c70175f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2000 - 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2015 - 2020 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
 
 namespace CKM {
 
-DataType::DataType() :
-       m_dataType(BINARY_DATA)
+void DataType::checkRange() const
 {
+       if (m_dataType >= DB_FIRST && m_dataType <= DB_LAST)
+               return;
+
+       ThrowErr(Exc::InputParam, "Invalid data type value=", m_dataType);
 }
 
-DataType::DataType(Type data)
-       : m_dataType(data)
+DataType::DataType() :
+       m_dataType(BINARY_DATA)
 {
-       if (!isInRange(data))
-               ThrowErr(Exc::InputParam,
-                                "Invalid conversion from DataType=", static_cast<int>(data),
-                                " to DBDataType");
 }
 
 DataType::DataType(KeyType key)
 {
        switch (key) {
        case KeyType::KEY_RSA_PUBLIC:
-               m_dataType = DataType::KEY_RSA_PUBLIC;
+               m_dataType = KEY_RSA_PUBLIC;
                break;
 
        case KeyType::KEY_RSA_PRIVATE:
-               m_dataType = DataType::KEY_RSA_PRIVATE;
+               m_dataType = KEY_RSA_PRIVATE;
                break;
 
        case KeyType::KEY_DSA_PUBLIC:
-               m_dataType = DataType::KEY_DSA_PUBLIC;
+               m_dataType = KEY_DSA_PUBLIC;
                break;
 
        case KeyType::KEY_DSA_PRIVATE:
-               m_dataType = DataType::KEY_DSA_PRIVATE;
+               m_dataType = KEY_DSA_PRIVATE;
                break;
 
        case KeyType::KEY_ECDSA_PUBLIC:
-               m_dataType = DataType::KEY_ECDSA_PUBLIC;
+               m_dataType = KEY_ECDSA_PUBLIC;
                break;
 
        case KeyType::KEY_ECDSA_PRIVATE:
-               m_dataType = DataType::KEY_ECDSA_PRIVATE;
+               m_dataType = KEY_ECDSA_PRIVATE;
                break;
 
        case KeyType::KEY_AES:
-               m_dataType = DataType::KEY_AES;
+               m_dataType = KEY_AES;
                break;
 
        default:
@@ -76,52 +75,27 @@ DataType::DataType(KeyType key)
        }
 }
 
-DataType::DataType(int data) :
-       m_dataType(static_cast<Type>(data))
+DataType::DataType(Type data) :
+       m_dataType(data)
 {
-       if (!isInRange(data))
-               ThrowErr(Exc::InputParam, "Invalid conversion from int=", data, " to DBDataType");
+       checkRange();
 }
 
-DataType::operator int () const
+DataType::DataType(IStream &stream)
 {
-       return static_cast<int>(m_dataType);
+       stream.Read(sizeof(m_dataType), &m_dataType);
+
+       checkRange();
 }
 
-DataType::operator KeyType() const
+void DataType::Serialize(IStream &stream) const
 {
-       switch (m_dataType) {
-       case DataType::KEY_RSA_PUBLIC:
-               return KeyType::KEY_RSA_PUBLIC;
-
-       case DataType::KEY_RSA_PRIVATE:
-               return KeyType::KEY_RSA_PRIVATE;
-
-       case DataType::KEY_DSA_PUBLIC:
-               return KeyType::KEY_DSA_PUBLIC;
-
-       case DataType::KEY_DSA_PRIVATE:
-               return KeyType::KEY_DSA_PRIVATE;
-
-       case DataType::KEY_ECDSA_PRIVATE:
-               return KeyType::KEY_ECDSA_PRIVATE;
-
-       case DataType::KEY_ECDSA_PUBLIC:
-               return KeyType::KEY_ECDSA_PUBLIC;
-
-       case DataType::KEY_AES:
-               return KeyType::KEY_AES;
-
-       default:
-               ThrowErr(Exc::InputParam,
-                                "Invalid conversion from DBDataType=", static_cast<int>(m_dataType),
-                                " to KeyType");
-       }
+       stream.Write(sizeof(m_dataType), &m_dataType);
 }
 
-bool DataType::operator==(const DataType &second) const
+DataType::operator int() const
 {
-       return m_dataType == second.m_dataType;
+       return static_cast<int>(m_dataType);
 }
 
 bool DataType::isKey() const
@@ -186,20 +160,9 @@ bool DataType::isEllipticCurve() const
        return (m_dataType == KEY_ECDSA_PRIVATE) || (m_dataType == KEY_ECDSA_PUBLIC);
 }
 
-bool DataType::isInRange(int data)
-{
-       if (data < static_cast<int>(DB_FIRST))
-               return false;
-
-       if (data > static_cast<int>(DB_LAST))
-               return false;
-
-       return true;
-}
-
 DataType DataType::getChainDatatype(unsigned int index)
 {
-       DataType result(static_cast<int>(index) + DB_CHAIN_FIRST);
+       DataType result(static_cast<Type>(DB_CHAIN_FIRST + index));
 
        if (!result.isChainCert())
                ThrowErr(Exc::InputParam, "Certificate number is out of range");
index 014869f..58dde1b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2000 - 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2015 - 2020 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
 #include <ckm/ckm-type.h>
 #include <exception.h>
 #include <symbol-visibility.h>
+#include <dpl/serialization.h>
 
 namespace CKM {
 
-class COMMON_API DataType {
+class COMMON_API DataType final : public ISerializable {
 public:
-
        enum Type {
                KEY_RSA_PUBLIC,
                KEY_RSA_PRIVATE,
@@ -68,14 +68,15 @@ public:
 
        DataType();
        DataType(Type data);
-       explicit DataType(int data);
+
+       explicit DataType(IStream &stream);
+       void Serialize(IStream &stream) const override;
+
        explicit DataType(KeyType key);
        DataType(const DataType &) = default;
        DataType &operator=(const DataType &) = default;
 
-       operator int () const;
-       operator KeyType() const;
-       bool operator==(const DataType &second) const;
+       operator int() const;
 
        bool isKey() const;
        bool isSKey() const;
@@ -86,13 +87,11 @@ public:
        bool isBinaryData() const;
        bool isEllipticCurve() const;
 
-       static bool isInRange(int data);
        static DataType getChainDatatype(unsigned int index);
 
-       // it's not virtual for a reason!
-       ~DataType() {}
-
 private:
+       void checkRange() const;
+
        Type m_dataType;
 };
 
index f5bb466..fb8d007 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2000 - 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2015 - 2020 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -38,17 +38,17 @@ namespace {
 
 AlgoType key2algo(DataType type)
 {
-       switch (static_cast<int>(type)) {
-       case DataType::Type::KEY_RSA_PRIVATE:
-       case DataType::Type::KEY_RSA_PUBLIC:
+       switch (type) {
+       case DataType::KEY_RSA_PRIVATE:
+       case DataType::KEY_RSA_PUBLIC:
                return AlgoType::RSA_SV;
 
-       case DataType::Type::KEY_DSA_PRIVATE:
-       case DataType::Type::KEY_DSA_PUBLIC:
+       case DataType::KEY_DSA_PRIVATE:
+       case DataType::KEY_DSA_PUBLIC:
                return AlgoType::DSA_SV;
 
-       case DataType::Type::KEY_ECDSA_PRIVATE:
-       case DataType::Type::KEY_ECDSA_PUBLIC:
+       case DataType::KEY_ECDSA_PRIVATE:
+       case DataType::KEY_ECDSA_PUBLIC:
                return AlgoType::ECDSA_SV;
 
        default:
index 62dd580..98ae2bf 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2015 - 2018 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2015 - 2020 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -160,7 +160,7 @@ GObjUPtr Store::getObject(const Token &token, const Password &pass)
        if (token.dataType.isKeyPrivate() || token.dataType.isKeyPublic())
                return std::make_unique<AKey>(data, token.dataType);
 
-       if (token.dataType == DataType(DataType::KEY_AES))
+       if (token.dataType.isSKey())
                return std::make_unique<SKey>(data, token.dataType);
 
        if (token.dataType.isCertificate() || token.dataType.isChainCert())
@@ -170,7 +170,7 @@ GObjUPtr Store::getObject(const Token &token, const Password &pass)
                return std::make_unique<BData>(data, token.dataType);
 
        ThrowErr(Exc::Crypto::DataTypeNotSupported,
-                        "This type of data is not supported by openssl backend: ", (int)token.dataType);
+                        "This type of data is not supported by openssl backend: ", token.dataType);
 }
 
 TokenPair Store::generateAKey(const CryptoAlgorithm &algorithm,
index be96f1f..b5a3dc1 100644 (file)
@@ -95,13 +95,13 @@ void generateDSAParams(const int sizeBits, CKM::RawBuffer &prime,
 }
 
 tz_data_type toTzDataType(const CKM::DataType dataType) {
-       switch (int(dataType)) {
-       case CKM::DataType::Type::BINARY_DATA:       return TYPE_GENERIC_SECRET;
-       case CKM::DataType::Type::KEY_AES:           return TYPE_SKEY;
-       case CKM::DataType::Type::KEY_DSA_PRIVATE:   return TYPE_AKEY_PRIVATE_DSA;
-       case CKM::DataType::Type::KEY_RSA_PRIVATE:   return TYPE_AKEY_PRIVATE_RSA;
-       case CKM::DataType::Type::KEY_DSA_PUBLIC:    return TYPE_AKEY_PUBLIC_DSA;
-       case CKM::DataType::Type::KEY_RSA_PUBLIC:    return TYPE_AKEY_PUBLIC_RSA;
+       switch (dataType) {
+       case CKM::DataType::BINARY_DATA:       return TYPE_GENERIC_SECRET;
+       case CKM::DataType::KEY_AES:           return TYPE_SKEY;
+       case CKM::DataType::KEY_DSA_PRIVATE:   return TYPE_AKEY_PRIVATE_DSA;
+       case CKM::DataType::KEY_RSA_PRIVATE:   return TYPE_AKEY_PRIVATE_RSA;
+       case CKM::DataType::KEY_DSA_PUBLIC:    return TYPE_AKEY_PUBLIC_DSA;
+       case CKM::DataType::KEY_RSA_PUBLIC:    return TYPE_AKEY_PUBLIC_RSA;
        default:
                ThrowErr(CKM::Exc::Crypto::DataTypeNotSupported,
                        "Data type could not be imported by tz-backend");
index 351f24e..e6a91ee 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2015-2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2015 - 2020 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -29,17 +29,17 @@ namespace TZ {
 namespace {
 AlgoType key2algo(DataType type)
 {
-       switch (static_cast<int>(type)) {
-       case DataType::Type::KEY_RSA_PRIVATE:
-       case DataType::Type::KEY_RSA_PUBLIC:
+       switch (type) {
+       case DataType::KEY_RSA_PRIVATE:
+       case DataType::KEY_RSA_PUBLIC:
                return AlgoType::RSA_SV;
 
-       case DataType::Type::KEY_DSA_PRIVATE:
-       case DataType::Type::KEY_DSA_PUBLIC:
+       case DataType::KEY_DSA_PRIVATE:
+       case DataType::KEY_DSA_PUBLIC:
                return AlgoType::DSA_SV;
 
-       case DataType::Type::KEY_ECDSA_PRIVATE:
-       case DataType::Type::KEY_ECDSA_PUBLIC:
+       case DataType::KEY_ECDSA_PRIVATE:
+       case DataType::KEY_ECDSA_PUBLIC:
                return AlgoType::ECDSA_SV;
 
        default:
index e5402ea..56ca699 100644 (file)
@@ -123,7 +123,7 @@ GObjUPtr Store::getObject(const Token &token, const Password &pass)
        }
 
        ThrowErr(Exc::Crypto::DataTypeNotSupported,
-                        "This type of data is not supported by trustzone backend: ", (int)token.dataType);
+                        "This type of data is not supported by trustzone backend: ", token.dataType);
 }
 
 TokenPair Store::generateAKey(const CryptoAlgorithm &alg, const Password &privPass,
index 3f0387b..269b64f 100644 (file)
@@ -523,7 +523,7 @@ RawBuffer CKMLogic::saveData(
        const PolicySerializable &policy)
 {
        int retCode = verifyAndSaveDataHelper(cred, name, explicitOwner, data, policy);
-       auto response = MessageBuffer::Serialize(msgId, retCode, static_cast<int>(data.type));
+       auto response = MessageBuffer::Serialize(msgId, retCode, data.type);
        return response.Pop();
 }
 
@@ -966,9 +966,9 @@ RawBuffer CKMLogic::getData(
                rowData.clear();
 
        auto response = MessageBuffer::Serialize(msgId,
-                                                retCode,
-                                                static_cast<int>(objDataType),
-                                                rowData);
+                                       retCode,
+                                       objDataType,
+                                       rowData);
        return response.Pop();
 }
 
@@ -1002,9 +1002,9 @@ RawBuffer CKMLogic::getDataProtectionStatus(
        }
 
        auto response = MessageBuffer::Serialize(msgId,
-                                                retCode,
-                                                static_cast<int>(objDataType),
-                                                status);
+                                       retCode,
+                                       objDataType,
+                                       status);
        return response.Pop();
 }
 
@@ -1181,9 +1181,9 @@ RawBuffer CKMLogic::getDataList(
        }
 
        auto response = MessageBuffer::Serialize(msgId,
-                                                retCode,
-                                                static_cast<int>(dataType),
-                                                ownerNameVector);
+                                       retCode,
+                                       dataType,
+                                       ownerNameVector);
        return response.Pop();
 }
 
index fd54b88..3e32c2c 100644 (file)
@@ -215,7 +215,7 @@ RawBuffer CKMService::ProcessStorage(Credentials &cred, MessageBuffer &buffer)
 {
        int command = 0;
        int msgId = 0;
-       int tmpDataType = 0;
+       DataType tmpDataType;
        Name name;
        ClientId explicitOwner, accessor;
 
@@ -242,7 +242,7 @@ RawBuffer CKMService::ProcessStorage(Credentials &cred, MessageBuffer &buffer)
                                   msgId,
                                   name,
                                   explicitOwner,
-                                  Crypto::Data(DataType(tmpDataType), std::move(rawData)),
+                                  Crypto::Data(tmpDataType, std::move(rawData)),
                                   policy);
        }
 
@@ -276,7 +276,7 @@ RawBuffer CKMService::ProcessStorage(Credentials &cred, MessageBuffer &buffer)
                return m_logic->getData(
                                   cred,
                                   msgId,
-                                  DataType(tmpDataType),
+                                  tmpDataType,
                                   name,
                                   explicitOwner,
                                   password);
@@ -300,7 +300,7 @@ RawBuffer CKMService::ProcessStorage(Credentials &cred, MessageBuffer &buffer)
                return m_logic->getDataProtectionStatus(
                                        cred,
                                        msgId,
-                                       DataType(tmpDataType),
+                                       tmpDataType,
                                        name,
                                        explicitOwner);
        }
@@ -310,7 +310,7 @@ RawBuffer CKMService::ProcessStorage(Credentials &cred, MessageBuffer &buffer)
                return m_logic->getDataList(
                                   cred,
                                   msgId,
-                                  DataType(tmpDataType));
+                                  tmpDataType);
        }
 
        case LogicCommand::CREATE_KEY_AES: {
index ce85bcf..f7c09c1 100644 (file)
@@ -515,7 +515,7 @@ Row Crypto::getRow(
        row.name = selectCommand->GetColumnString(0);
        row.owner = selectCommand->GetColumnString(1);
        row.exportable = selectCommand->GetColumnInteger(2);
-       row.dataType = DataType(selectCommand->GetColumnInteger(3));
+       row.dataType = static_cast<DataType::Type>(selectCommand->GetColumnInteger(3));
        row.algorithmType =
                static_cast<DBCMAlgType>(selectCommand->GetColumnInteger(4));
        row.encryptionScheme = selectCommand->GetColumnInteger(5);
@@ -659,8 +659,8 @@ void Crypto::listNames(
                Transaction transaction(this);
                SqlConnection::DataCommandUniquePtr selectCommand =
                        m_connection->PrepareDataCommand(DB_CMD_NAME_SELECT_BY_TYPE_AND_PERMISSION);
-               selectCommand->BindInteger(1, static_cast<int>(typeRangeStart));
-               selectCommand->BindInteger(2, static_cast<int>(typeRangeStop));
+               selectCommand->BindInteger(1, typeRangeStart);
+               selectCommand->BindInteger(2, typeRangeStop);
                selectCommand->BindString(104, owner.c_str());
                selectCommand->BindInteger(4,
                                                                   static_cast<int>(Permission::READ | Permission::REMOVE));
@@ -682,8 +682,8 @@ void Crypto::listNames(
 
        ThrowErr(Exc::DatabaseFailed,
                         "Couldn't list names of type <",
-                        static_cast<int>(typeRangeStart), ",",
-                        static_cast<int>(typeRangeStop), ">",
+                        typeRangeStart, ",",
+                        typeRangeStop, ">",
                         " accessible to client ", owner);
 }
 
@@ -905,7 +905,7 @@ void Crypto::ObjectTable::addRow(const Row &row)
        SqlConnection::DataCommandUniquePtr insertObjectCommand =
                m_connection->PrepareDataCommand(DB_CMD_OBJECT_INSERT);
        insertObjectCommand->BindInteger(1, row.exportable);
-       insertObjectCommand->BindInteger(2, static_cast<int>(row.dataType));
+       insertObjectCommand->BindInteger(2, row.dataType);
        insertObjectCommand->BindInteger(3, static_cast<int>(row.algorithmType));
        insertObjectCommand->BindInteger(4, row.encryptionScheme);
        insertObjectCommand->BindBlob(5, row.iv);
@@ -925,7 +925,7 @@ void Crypto::ObjectTable::updateRow(const Row &row)
 {
        SqlConnection::DataCommandUniquePtr updateObjectCommand =
                m_connection->PrepareDataCommand(DB_CMD_OBJECT_UPDATE);
-       updateObjectCommand->BindInteger(2, static_cast<int>(row.dataType));
+       updateObjectCommand->BindInteger(2, row.dataType);
        updateObjectCommand->BindInteger(3, static_cast<int>(row.algorithmType));
        updateObjectCommand->BindInteger(4, row.encryptionScheme);
        updateObjectCommand->BindBlob(5, row.iv);
index cd4f1a6..1ec178e 100644 (file)
@@ -37,7 +37,7 @@ class Crypto;
 } // CKM
 
 struct Item {
-       Item() : type(CKM::DataType::Type::DB_LAST)
+       Item() : type(CKM::DataType::DB_LAST)
        {
        }
 
index 84bed8b..907c766 100644 (file)
@@ -133,7 +133,7 @@ NEGATIVE_TEST_CASE(push_key)
 POSITIVE_TEST_CASE(row_encryption)
 {
        Policy policy("", true);
-       Crypto::Data data(DataType(DataType::Type::BINARY_DATA), TEST_DATA);
+       Crypto::Data data(DataType::BINARY_DATA, TEST_DATA);
        Crypto::Decider decider;
        Crypto::GStore &store = decider.getStore(data.type, policy);
        Token token = store.import(data, policy.password, Crypto::EncryptionParams());
@@ -159,7 +159,7 @@ POSITIVE_TEST_CASE(row_encryption)
 NEGATIVE_TEST_CASE(row_encryption)
 {
        const Policy policy("", true);
-       Crypto::Data data(DataType(DataType::Type::BINARY_DATA), TEST_DATA);
+       Crypto::Data data(DataType::BINARY_DATA, TEST_DATA);
        Crypto::Decider decider;
        Crypto::GStore &store = decider.getStore(data.type, policy);
        Token token = store.import(data, policy.password, Crypto::EncryptionParams());
index 410489b..e420bde 100644 (file)
@@ -55,7 +55,7 @@ POSITIVE_TEST_CASE(KEY_TYPE_CASTING)
        pairs.emplace_back(DataType::KEY_AES, KeyType::KEY_AES);
 
        for (auto &p : pairs)
-               BOOST_REQUIRE(p.second == DataType(static_cast<KeyType>(p.first)));
+               BOOST_REQUIRE(p.first == DataType(p.second));
 }
 
 POSITIVE_TEST_CASE(UNARY_OPERATIONS)