--- /dev/null
+/*
+ * 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 */
--- /dev/null
+/*
+ * 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 */