YacaLifetime utlity class to manage YACA initialized time 35/117835/3
authorLukasz Pawelczyk <l.pawelczyk@samsung.com>
Tue, 7 Mar 2017 14:32:40 +0000 (23:32 +0900)
committerLukasz Pawelczyk <l.pawelczyk@samsung.com>
Wed, 8 Mar 2017 14:40:19 +0000 (23:40 +0900)
Change-Id: Ia46fe570b9470b1e9079ecd61c850ae2a3d382d8

src/common/CMakeLists.txt
src/common/include/yaca-lifetime.h [new file with mode: 0644]
src/common/yaca-lifetime.cpp [new file with mode: 0644]

index 4a84e02b2962bdfcbc12cc9061eed64a0803d2d7..31174dcb335ce54251629ff366b84d58977ca2cc 100644 (file)
@@ -74,6 +74,7 @@ SET(COMMON_SOURCES
     ${COMMON_PATH}/tzplatform-config.cpp
     ${COMMON_PATH}/privilege-info.cpp
     ${COMMON_PATH}/encryption-access.cpp
+    ${COMMON_PATH}/yaca-lifetime.cpp
     ${FEK_MANAGER_SOURCE}
     )
 
diff --git a/src/common/include/yaca-lifetime.h b/src/common/include/yaca-lifetime.h
new file mode 100644 (file)
index 0000000..90a04a9
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ *  Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Contact: Lukasz Pawelczyk <l.pawelczyk@samsung.com>
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+/*
+ * @file        yaca-lifetime.h
+ * @author      Lukasz Pawelczyk <l.pawelczyk@samsung.com>
+ * @brief       Class for managing lifetime of YACA initialization
+ */
+
+#pragma once
+
+namespace SecurityManager {
+
+class YacaLifetime {
+private:
+    bool m_yacaInitialized;
+
+public:
+    YacaLifetime();
+    ~YacaLifetime();
+    int initialize();
+};
+
+extern thread_local YacaLifetime g_yacaLifetime;
+
+} /* namespace SecurityManager */
diff --git a/src/common/yaca-lifetime.cpp b/src/common/yaca-lifetime.cpp
new file mode 100644 (file)
index 0000000..18f47fb
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ *  Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Contact: Lukasz Pawelczyk <l.pawelczyk@samsung.com>
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+/*
+ * @file        yaca-lifetime.cpp
+ * @author      Lukasz Pawelczyk <l.pawelczyk@samsung.com>
+ * @brief       Class for managing lifetime of YACA initialization
+ */
+
+#include "yaca-lifetime.h"
+
+#include <yaca_crypto.h>
+#include <yaca_error.h>
+
+
+namespace SecurityManager {
+
+thread_local YacaLifetime g_yacaLifetime;
+
+YacaLifetime::YacaLifetime() :
+    m_yacaInitialized(false)
+{
+}
+
+YacaLifetime::~YacaLifetime()
+{
+    if (m_yacaInitialized)
+        ::yaca_cleanup();
+}
+
+int YacaLifetime::initialize()
+{
+    if (m_yacaInitialized)
+        return YACA_ERROR_NONE;
+
+    int ret = ::yaca_initialize();
+    if (ret != YACA_ERROR_NONE)
+        return ret;
+
+    m_yacaInitialized = true;
+    return YACA_ERROR_NONE;
+}
+
+} /* namespace SecurityManager */