blob: 6d7d35bd5af90413dab7c65d37e214dfe52f9cb7 [file] [log] [blame]
Yingdi Yu0b60e7a2015-07-16 21:05:11 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento5ee8ec02018-09-01 19:06:12 -04002/*
3 * Copyright (c) 2013-2018 Regents of the University of California.
Yingdi Yu0b60e7a2015-07-16 21:05:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20 */
21
22#ifndef NDN_TESTS_SECURITY_TPM_BACK_END_WRAPPER_OSX_HPP
23#define NDN_TESTS_SECURITY_TPM_BACK_END_WRAPPER_OSX_HPP
24
25#include "security/tpm/back-end-osx.hpp"
26#include "security/tpm/key-handle-osx.hpp"
Davide Pesavento5ee8ec02018-09-01 19:06:12 -040027
28#include <cstdlib>
Yingdi Yu0b60e7a2015-07-16 21:05:11 -070029
30namespace ndn {
31namespace security {
32namespace tpm {
33namespace tests {
34
35/**
36 * @brief A wrapper of tpm::BackEndOsx for unit test template.
37 */
38class BackEndWrapperOsx
39{
40public:
41 BackEndWrapperOsx()
42 {
43 std::string oldHOME;
44 if (std::getenv("OLD_HOME"))
45 oldHOME = std::getenv("OLD_HOME");
46
47 if (std::getenv("HOME"))
48 m_HOME = std::getenv("HOME");
49
50 if (!oldHOME.empty())
Davide Pesavento5ee8ec02018-09-01 19:06:12 -040051 setenv("HOME", oldHOME.data(), 1);
Yingdi Yu0b60e7a2015-07-16 21:05:11 -070052 else
53 unsetenv("HOME");
54
Davide Pesavento5ee8ec02018-09-01 19:06:12 -040055 m_impl = make_unique<BackEndOsx>();
Yingdi Yu0b60e7a2015-07-16 21:05:11 -070056 }
57
58 ~BackEndWrapperOsx()
59 {
60 if (!m_HOME.empty())
Davide Pesavento5ee8ec02018-09-01 19:06:12 -040061 setenv("HOME", m_HOME.data(), 1);
Yingdi Yu0b60e7a2015-07-16 21:05:11 -070062 else
63 unsetenv("HOME");
64 }
65
66 BackEnd&
67 getTpm()
68 {
69 return *m_impl;
70 }
71
72 std::string
Davide Pesavento5ee8ec02018-09-01 19:06:12 -040073 getScheme() const
Yingdi Yu0b60e7a2015-07-16 21:05:11 -070074 {
75 return "tpm-osxkeychain";
76 }
77
78private:
79 std::string m_HOME;
80 unique_ptr<BackEnd> m_impl;
81};
82
83} // namespace tests
84} // namespace tpm
85} // namespace security
86} // namespace ndn
87
88#endif // NDN_TESTS_SECURITY_TPM_BACK_END_WRAPPER_OSX_HPP