From: Krzysztof Jackiewicz Date: Tue, 13 Jun 2023 14:47:07 +0000 (+0200) Subject: Simplify serialization calls X-Git-Tag: accepted/tizen/6.0/unified/20230630.050042~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=45cf0c035909249b49b20242a863ae5f9162436a;p=platform%2Fcore%2Fsecurity%2Fkey-manager.git Simplify serialization calls Remove unnecessary casts and use type deduction. Change-Id: I88d8ae4b8060a509984a6883289c4bb05a9c1015 --- diff --git a/src/manager/client-async/client-manager-async-impl.cpp b/src/manager/client-async/client-manager-async-impl.cpp index f5082ec..92a18e4 100644 --- a/src/manager/client-async/client-manager-async-impl.cpp +++ b/src/manager/client-async/client-manager-async-impl.cpp @@ -314,7 +314,7 @@ void ManagerAsync::Impl::createKeyAES(const ObserverPtr &observer, AliasSupport aliasHelper(keyAlias); sendToStorage(LogicCommand::CREATE_KEY_AES, observer, - static_cast(size), PolicySerializable(policyKey), + size, PolicySerializable(policyKey), aliasHelper.getName(), aliasHelper.getOwner()); }); } @@ -341,13 +341,12 @@ void ManagerAsync::Impl::crypt( CryptoAlgorithmSerializable cas(algo); m_counter++; - auto command = static_cast(encryption ? - EncryptionCommand::ENCRYPT : EncryptionCommand::DECRYPT); + auto command = encryption ? EncryptionCommand::ENCRYPT : EncryptionCommand::DECRYPT; auto send = SerializeMessage(command, m_counter, cas, helper.getName(), helper.getOwner(), password, input); thread()->sendMessage(AsyncRequest(observer, SERVICE_SOCKET_ENCRYPTION, - std::move(send), m_counter, command)); + std::move(send), m_counter, static_cast(command))); }); } diff --git a/src/manager/client-async/client-manager-async-impl.h b/src/manager/client-async/client-manager-async-impl.h index eb354ef..3caf47c 100644 --- a/src/manager/client-async/client-manager-async-impl.h +++ b/src/manager/client-async/client-manager-async-impl.h @@ -155,7 +155,7 @@ private: void sendToStorage(LogicCommand command, const ObserverPtr &observer, Args &&... args) { m_counter++; - auto send = SerializeMessage(static_cast(command), m_counter, std::forward(args)...); + auto send = SerializeMessage(command, m_counter, std::forward(args)...); thread()->sendMessage(AsyncRequest(observer, SERVICE_SOCKET_CKM_STORAGE, std::move(send), m_counter, static_cast(command))); } diff --git a/src/manager/client/client-control.cpp b/src/manager/client/client-control.cpp index d0a4d18..50c1870 100644 --- a/src/manager/client/client-control.cpp +++ b/src/manager/client/client-control.cpp @@ -46,9 +46,7 @@ public: return CKM_API_ERROR_INPUT_PARAM; MessageBuffer recv; - auto send = SerializeMessage(static_cast(ControlCommand::UNLOCK_USER_KEY), - user, - password); + auto send = SerializeMessage(ControlCommand::UNLOCK_USER_KEY, user, password); int retCode = m_controlConnection.processRequest(send, recv); @@ -70,7 +68,7 @@ public: return CKM_API_ERROR_INPUT_PARAM; MessageBuffer recv; - auto send = SerializeMessage(static_cast(ControlCommand::LOCK_USER_KEY), user); + auto send = SerializeMessage(ControlCommand::LOCK_USER_KEY, user); int retCode = m_controlConnection.processRequest(send, recv); @@ -92,7 +90,7 @@ public: return CKM_API_ERROR_INPUT_PARAM; MessageBuffer recv; - auto send = SerializeMessage(static_cast(ControlCommand::REMOVE_USER_DATA), user); + auto send = SerializeMessage(ControlCommand::REMOVE_USER_DATA, user); int retCode = m_controlConnection.processRequest(send, recv); @@ -115,7 +113,7 @@ public: return CKM_API_ERROR_INPUT_PARAM; MessageBuffer recv; - auto send = SerializeMessage(static_cast(ControlCommand::CHANGE_USER_PASSWORD), + auto send = SerializeMessage(ControlCommand::CHANGE_USER_PASSWORD, user, oldPassword, newPassword); @@ -140,7 +138,7 @@ public: return CKM_API_ERROR_INPUT_PARAM; MessageBuffer recv; - auto send = SerializeMessage(static_cast(ControlCommand::RESET_USER_PASSWORD), + auto send = SerializeMessage(ControlCommand::RESET_USER_PASSWORD, user, newPassword); @@ -164,7 +162,7 @@ public: return CKM_API_ERROR_INPUT_PARAM; MessageBuffer recv; - auto send = SerializeMessage(static_cast(ControlCommand::REMOVE_APP_DATA), owner); + auto send = SerializeMessage(ControlCommand::REMOVE_APP_DATA, owner); int retCode = m_controlConnection.processRequest(send, recv); @@ -183,7 +181,7 @@ public: EXCEPTION_GUARD_START_CPPAPI MessageBuffer recv; - auto send = SerializeMessage(static_cast(ControlCommand::UPDATE_CC_MODE)); + auto send = SerializeMessage(ControlCommand::UPDATE_CC_MODE); int retCode = m_controlConnection.processRequest(send, recv); @@ -206,8 +204,8 @@ public: MessageBuffer recv; AliasSupport helper(alias); - auto send = SerializeMessage(static_cast(ControlCommand::SET_PERMISSION), - static_cast(user), + auto send = SerializeMessage(ControlCommand::SET_PERMISSION, + user, helper.getName(), helper.getOwner(), accessor, diff --git a/src/manager/client/client-manager-impl.cpp b/src/manager/client/client-manager-impl.cpp index 4d6e59e..0204028 100644 --- a/src/manager/client/client-manager-impl.cpp +++ b/src/manager/client/client-manager-impl.cpp @@ -101,7 +101,7 @@ Manager::Impl::Request::Request(Manager::Impl &impl, Cmd cmd, CKM::ServiceConnec { static_assert(sizeof cmd <= sizeof(int)); const auto msgId = m_msgId = ++impl.m_counter; - m_retCode = doRequest(m_recv, conn, static_cast(cmd), msgId, std::forward(t)...); + m_retCode = doRequest(m_recv, conn, cmd, msgId, std::forward(t)...); } Manager::Impl::Request::operator bool() const { @@ -216,8 +216,7 @@ int Manager::Impl::getPKCS12(const Alias &alias, const Password &keyPass, int msgId = ++m_counter; MessageBuffer recv; - int retCode = doRequest(recv, m_storageConnection, - static_cast(LogicCommand::GET_PKCS12), msgId, + int retCode = doRequest(recv, m_storageConnection, LogicCommand::GET_PKCS12, msgId, helper.getName(), helper.getOwner(), keyPass, certPass); if (CKM_API_SUCCESS != retCode) @@ -476,7 +475,7 @@ int Manager::Impl::createKeyAES( AliasSupport aliasHelper(keyAlias); return Request(*this, LogicCommand::CREATE_KEY_AES, m_storageConnection, - static_cast(size), PolicySerializable(policyKey), + size, PolicySerializable(policyKey), aliasHelper.getName(), aliasHelper.getOwner() ).maybeDeserialize(); diff --git a/src/manager/common/message-buffer.cpp b/src/manager/common/message-buffer.cpp index 237f716..4dc5c16 100644 --- a/src/manager/common/message-buffer.cpp +++ b/src/manager/common/message-buffer.cpp @@ -80,7 +80,7 @@ void MessageSerializer::Sizer::Write(size_t num, const void*) MessageSerializer::Writer::Writer(size_t size) { m_buffer.reserve(sizeof(size_t) + size); - Serializer::Serialize(*this, size); + Serialization::Serialize(*this, size); } void MessageSerializer::Writer::Read(size_t, void*) diff --git a/src/manager/common/protocols.cpp b/src/manager/common/protocols.cpp index d402548..d270f0c 100644 --- a/src/manager/common/protocols.cpp +++ b/src/manager/common/protocols.cpp @@ -51,16 +51,14 @@ void PolicySerializable::Serialize(IStream &stream) const { Serialization::Serialize(stream, password); Serialization::Serialize(stream, extractable); - Serialization::Serialize(stream, static_cast(backend)); + Serialization::Serialize(stream, backend); } void PolicySerializable::Deserialize(IStream &stream) { - int policyBackend; Deserialization::Deserialize(stream, password); Deserialization::Deserialize(stream, extractable); - Deserialization::Deserialize(stream, policyBackend); - backend = static_cast(policyBackend); + Deserialization::Deserialize(stream, backend); } PKCS12Serializable::PKCS12Serializable() @@ -212,15 +210,13 @@ CryptoAlgorithmSerializable::CryptoAlgorithmSerializable(IStream &stream) void CryptoAlgorithmSerializable::Deserialize(IStream &stream) { size_t plen = 0; - Deserializer::Deserialize(stream, plen); + Deserialization::Deserialize(stream, plen); while (plen) { ParamName name; uint64_t integer; RawBuffer buffer; - int tmpName; - Deserializer::Deserialize(stream, tmpName); - name = static_cast(tmpName); + Deserialization::Deserialize(stream, name); switch (name) { case ParamName::ED_IV: @@ -230,7 +226,7 @@ void CryptoAlgorithmSerializable::Deserialize(IStream &stream) case ParamName::KBKDF_CONTEXT: case ParamName::KBKDF_FIXED_INPUT: case ParamName::ECDH_PUBKEY: - Deserializer::Deserialize(stream, buffer); + Deserialization::Deserialize(stream, buffer); setParam(name, buffer); break; @@ -248,7 +244,7 @@ void CryptoAlgorithmSerializable::Deserialize(IStream &stream) case ParamName::KBKDF_LLEN: case ParamName::KBKDF_COUNTER_LOCATION: case ParamName::KBKDF_NO_SEPARATOR: - Deserializer::Deserialize(stream, integer); + Deserialization::Deserialize(stream, integer); setParam(name, integer); break; @@ -262,17 +258,17 @@ void CryptoAlgorithmSerializable::Deserialize(IStream &stream) void CryptoAlgorithmSerializable::Serialize(IStream &stream) const { - Serializer::Serialize(stream, m_params.size()); + Serialization::Serialize(stream, m_params.size()); for (const auto &it : m_params) { - Serializer::Serialize(stream, static_cast(it.first)); + Serialization::Serialize(stream, it.first); uint64_t integer; RawBuffer buffer; if (it.second->getInt(integer)) - Serializer::Serialize(stream, integer); + Serialization::Serialize(stream, integer); else if (it.second->getBuffer(buffer)) - Serializer::Serialize(stream, buffer); + Serialization::Serialize(stream, buffer); else ThrowMsg(UnsupportedParam, "Unsupported param type"); } diff --git a/src/manager/service/ckm-service.cpp b/src/manager/service/ckm-service.cpp index 7bfebbe..1803635 100644 --- a/src/manager/service/ckm-service.cpp +++ b/src/manager/service/ckm-service.cpp @@ -116,21 +116,18 @@ bool CKMService::ProcessOne( RawBuffer CKMService::ProcessControl(MessageBuffer &buffer, bool allowed) { - int command = 0; uid_t user = 0; - ControlCommand cc; + ControlCommand command; Password newPass, oldPass; ClientId explicitOwner; buffer.Deserialize(command); - LogDebug("Process control. Command: " << command); + LogDebug("Process control. Command: " << static_cast(command)); std::function logicFunc; - cc = static_cast(command); - - switch (cc) { + switch (command) { case ControlCommand::UNLOCK_USER_KEY: buffer.Deserialize(user, newPass); logicFunc = [&]() { @@ -213,7 +210,7 @@ RawBuffer CKMService::ProcessControl(MessageBuffer &buffer, bool allowed) RawBuffer CKMService::ProcessStorage(Credentials &cred, MessageBuffer &buffer) { - int command = 0; + LogicCommand command; int msgId = 0; DataType tmpDataType; Name name; @@ -230,9 +227,9 @@ RawBuffer CKMService::ProcessStorage(Credentials &cred, MessageBuffer &buffer) Password nullPassword(""); m_logic->unlockUserKey(cred.clientUid, nullPassword); - LogDebug("Process storage. Command: " << command); + LogDebug("Process storage. Command: " << static_cast(command)); - switch (static_cast(command)) { + switch (command) { case LogicCommand::SAVE: { RawBuffer rawData; PolicySerializable policy;