Remove unnecessary casts and use type deduction.
Change-Id: I88d8ae4b8060a509984a6883289c4bb05a9c1015
AliasSupport aliasHelper(keyAlias);
sendToStorage(LogicCommand::CREATE_KEY_AES, observer,
- static_cast<int>(size), PolicySerializable(policyKey),
+ size, PolicySerializable(policyKey),
aliasHelper.getName(), aliasHelper.getOwner());
});
}
CryptoAlgorithmSerializable cas(algo);
m_counter++;
- auto command = static_cast<int>(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<int>(command)));
});
}
void sendToStorage(LogicCommand command, const ObserverPtr &observer, Args &&... args)
{
m_counter++;
- auto send = SerializeMessage(static_cast<int>(command), m_counter, std::forward<Args>(args)...);
+ auto send = SerializeMessage(command, m_counter, std::forward<Args>(args)...);
thread()->sendMessage(AsyncRequest(observer, SERVICE_SOCKET_CKM_STORAGE,
std::move(send), m_counter, static_cast<int>(command)));
}
return CKM_API_ERROR_INPUT_PARAM;
MessageBuffer recv;
- auto send = SerializeMessage(static_cast<int>(ControlCommand::UNLOCK_USER_KEY),
- user,
- password);
+ auto send = SerializeMessage(ControlCommand::UNLOCK_USER_KEY, user, password);
int retCode = m_controlConnection.processRequest(send, recv);
return CKM_API_ERROR_INPUT_PARAM;
MessageBuffer recv;
- auto send = SerializeMessage(static_cast<int>(ControlCommand::LOCK_USER_KEY), user);
+ auto send = SerializeMessage(ControlCommand::LOCK_USER_KEY, user);
int retCode = m_controlConnection.processRequest(send, recv);
return CKM_API_ERROR_INPUT_PARAM;
MessageBuffer recv;
- auto send = SerializeMessage(static_cast<int>(ControlCommand::REMOVE_USER_DATA), user);
+ auto send = SerializeMessage(ControlCommand::REMOVE_USER_DATA, user);
int retCode = m_controlConnection.processRequest(send, recv);
return CKM_API_ERROR_INPUT_PARAM;
MessageBuffer recv;
- auto send = SerializeMessage(static_cast<int>(ControlCommand::CHANGE_USER_PASSWORD),
+ auto send = SerializeMessage(ControlCommand::CHANGE_USER_PASSWORD,
user,
oldPassword,
newPassword);
return CKM_API_ERROR_INPUT_PARAM;
MessageBuffer recv;
- auto send = SerializeMessage(static_cast<int>(ControlCommand::RESET_USER_PASSWORD),
+ auto send = SerializeMessage(ControlCommand::RESET_USER_PASSWORD,
user,
newPassword);
return CKM_API_ERROR_INPUT_PARAM;
MessageBuffer recv;
- auto send = SerializeMessage(static_cast<int>(ControlCommand::REMOVE_APP_DATA), owner);
+ auto send = SerializeMessage(ControlCommand::REMOVE_APP_DATA, owner);
int retCode = m_controlConnection.processRequest(send, recv);
EXCEPTION_GUARD_START_CPPAPI
MessageBuffer recv;
- auto send = SerializeMessage(static_cast<int>(ControlCommand::UPDATE_CC_MODE));
+ auto send = SerializeMessage(ControlCommand::UPDATE_CC_MODE);
int retCode = m_controlConnection.processRequest(send, recv);
MessageBuffer recv;
AliasSupport helper(alias);
- auto send = SerializeMessage(static_cast<int>(ControlCommand::SET_PERMISSION),
- static_cast<int>(user),
+ auto send = SerializeMessage(ControlCommand::SET_PERMISSION,
+ user,
helper.getName(),
helper.getOwner(),
accessor,
{
static_assert(sizeof cmd <= sizeof(int));
const auto msgId = m_msgId = ++impl.m_counter;
- m_retCode = doRequest(m_recv, conn, static_cast<int>(cmd), msgId, std::forward<T>(t)...);
+ m_retCode = doRequest(m_recv, conn, cmd, msgId, std::forward<T>(t)...);
}
Manager::Impl::Request::operator bool() const {
int msgId = ++m_counter;
MessageBuffer recv;
- int retCode = doRequest(recv, m_storageConnection,
- static_cast<int>(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)
AliasSupport aliasHelper(keyAlias);
return Request(*this, LogicCommand::CREATE_KEY_AES, m_storageConnection,
- static_cast<int>(size), PolicySerializable(policyKey),
+ size, PolicySerializable(policyKey),
aliasHelper.getName(), aliasHelper.getOwner()
).maybeDeserialize();
MessageSerializer::Writer::Writer(size_t size)
{
m_buffer.reserve(sizeof(size_t) + size);
- Serializer<size_t>::Serialize(*this, size);
+ Serialization::Serialize(*this, size);
}
void MessageSerializer::Writer::Read(size_t, void*)
{
Serialization::Serialize(stream, password);
Serialization::Serialize(stream, extractable);
- Serialization::Serialize(stream, static_cast<int>(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>(policyBackend);
+ Deserialization::Deserialize(stream, backend);
}
PKCS12Serializable::PKCS12Serializable()
void CryptoAlgorithmSerializable::Deserialize(IStream &stream)
{
size_t plen = 0;
- Deserializer<size_t>::Deserialize(stream, plen);
+ Deserialization::Deserialize(stream, plen);
while (plen) {
ParamName name;
uint64_t integer;
RawBuffer buffer;
- int tmpName;
- Deserializer<int>::Deserialize(stream, tmpName);
- name = static_cast<ParamName>(tmpName);
+ Deserialization::Deserialize(stream, name);
switch (name) {
case ParamName::ED_IV:
case ParamName::KBKDF_CONTEXT:
case ParamName::KBKDF_FIXED_INPUT:
case ParamName::ECDH_PUBKEY:
- Deserializer<RawBuffer>::Deserialize(stream, buffer);
+ Deserialization::Deserialize(stream, buffer);
setParam(name, buffer);
break;
case ParamName::KBKDF_LLEN:
case ParamName::KBKDF_COUNTER_LOCATION:
case ParamName::KBKDF_NO_SEPARATOR:
- Deserializer<uint64_t>::Deserialize(stream, integer);
+ Deserialization::Deserialize(stream, integer);
setParam(name, integer);
break;
void CryptoAlgorithmSerializable::Serialize(IStream &stream) const
{
- Serializer<size_t>::Serialize(stream, m_params.size());
+ Serialization::Serialize(stream, m_params.size());
for (const auto &it : m_params) {
- Serializer<int>::Serialize(stream, static_cast<int>(it.first));
+ Serialization::Serialize(stream, it.first);
uint64_t integer;
RawBuffer buffer;
if (it.second->getInt(integer))
- Serializer<uint64_t>::Serialize(stream, integer);
+ Serialization::Serialize(stream, integer);
else if (it.second->getBuffer(buffer))
- Serializer<RawBuffer>::Serialize(stream, buffer);
+ Serialization::Serialize(stream, buffer);
else
ThrowMsg(UnsupportedParam, "Unsupported param type");
}
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<int>(command));
std::function<RawBuffer(void)> logicFunc;
- cc = static_cast<ControlCommand>(command);
-
- switch (cc) {
+ switch (command) {
case ControlCommand::UNLOCK_USER_KEY:
buffer.Deserialize(user, newPass);
logicFunc = [&]() {
RawBuffer CKMService::ProcessStorage(Credentials &cred, MessageBuffer &buffer)
{
- int command = 0;
+ LogicCommand command;
int msgId = 0;
DataType tmpDataType;
Name name;
Password nullPassword("");
m_logic->unlockUserKey(cred.clientUid, nullPassword);
- LogDebug("Process storage. Command: " << command);
+ LogDebug("Process storage. Command: " << static_cast<int>(command));
- switch (static_cast<LogicCommand>(command)) {
+ switch (command) {
case LogicCommand::SAVE: {
RawBuffer rawData;
PolicySerializable policy;