Implement asynchronous encryption/decryption API
[platform/core/security/key-manager.git] / src / manager / client-async / client-manager-async-impl.cpp
index 2a37c24..fb7bc8a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2000 - 2015 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.
@@ -382,4 +382,36 @@ void ManagerAsync::Impl::observerCheck(const ManagerAsync::ObserverPtr& observer
         throw std::invalid_argument("Empty observer");
 }
 
+void ManagerAsync::Impl::crypt(
+        const ObserverPtr& observer,
+        const CryptoAlgorithm& algo,
+        const Alias& keyAlias,
+        const Password& password,
+        const RawBuffer& input,
+        bool encryption)
+{
+    observerCheck(observer);
+    if (input.empty() || keyAlias.empty())
+        return observer->ReceivedError(CKM_API_ERROR_INPUT_PARAM);
+
+    try_catch_async([&] {
+        AliasSupport helper(keyAlias);
+        CryptoAlgorithmSerializable cas(algo);
+        m_counter++;
+
+        auto send = MessageBuffer::Serialize(
+                static_cast<int>(encryption?EncryptionCommand::ENCRYPT:EncryptionCommand::DECRYPT),
+                m_counter,
+                cas,
+                helper.getName(),
+                helper.getLabel(),
+                password,
+                input);
+        thread()->sendMessage(AsyncRequest(observer,
+                                           SERVICE_SOCKET_ENCRYPTION,
+                                           send.Pop(),
+                                           m_counter));
+    }, [&observer](int error){ observer->ReceivedError(error); } );
+}
+
 } // namespace CKM