From: Lukasz Pawelczyk Date: Tue, 7 Mar 2017 14:32:40 +0000 (+0900) Subject: YacaLifetime utlity class to manage YACA initialized time X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6ea7801ec4f6be2d5e04c87a87109ed2a4dba773;p=platform%2Fcore%2Fsecurity%2Fsecurity-manager.git YacaLifetime utlity class to manage YACA initialized time Change-Id: Ia46fe570b9470b1e9079ecd61c850ae2a3d382d8 --- diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 4a84e02b..31174dcb 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -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 index 00000000..90a04a92 --- /dev/null +++ b/src/common/include/yaca-lifetime.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Lukasz Pawelczyk + * + * 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 + * @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 index 00000000..18f47fbc --- /dev/null +++ b/src/common/yaca-lifetime.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Lukasz Pawelczyk + * + * 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 + * @brief Class for managing lifetime of YACA initialization + */ + +#include "yaca-lifetime.h" + +#include +#include + + +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 */