Yingdi Yu | 0b60e7a | 2015-07-16 21:05:11 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 5ee8ec0 | 2018-09-01 19:06:12 -0400 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2013-2018 Regents of the University of California. |
Yingdi Yu | 0b60e7a | 2015-07-16 21:05:11 -0700 | [diff] [blame] | 4 | * |
| 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 Pesavento | 5ee8ec0 | 2018-09-01 19:06:12 -0400 | [diff] [blame] | 27 | |
| 28 | #include <cstdlib> |
Yingdi Yu | 0b60e7a | 2015-07-16 21:05:11 -0700 | [diff] [blame] | 29 | |
| 30 | namespace ndn { |
| 31 | namespace security { |
| 32 | namespace tpm { |
| 33 | namespace tests { |
| 34 | |
| 35 | /** |
| 36 | * @brief A wrapper of tpm::BackEndOsx for unit test template. |
| 37 | */ |
| 38 | class BackEndWrapperOsx |
| 39 | { |
| 40 | public: |
| 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 Pesavento | 5ee8ec0 | 2018-09-01 19:06:12 -0400 | [diff] [blame] | 51 | setenv("HOME", oldHOME.data(), 1); |
Yingdi Yu | 0b60e7a | 2015-07-16 21:05:11 -0700 | [diff] [blame] | 52 | else |
| 53 | unsetenv("HOME"); |
| 54 | |
Davide Pesavento | 5ee8ec0 | 2018-09-01 19:06:12 -0400 | [diff] [blame] | 55 | m_impl = make_unique<BackEndOsx>(); |
Yingdi Yu | 0b60e7a | 2015-07-16 21:05:11 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | ~BackEndWrapperOsx() |
| 59 | { |
| 60 | if (!m_HOME.empty()) |
Davide Pesavento | 5ee8ec0 | 2018-09-01 19:06:12 -0400 | [diff] [blame] | 61 | setenv("HOME", m_HOME.data(), 1); |
Yingdi Yu | 0b60e7a | 2015-07-16 21:05:11 -0700 | [diff] [blame] | 62 | else |
| 63 | unsetenv("HOME"); |
| 64 | } |
| 65 | |
| 66 | BackEnd& |
| 67 | getTpm() |
| 68 | { |
| 69 | return *m_impl; |
| 70 | } |
| 71 | |
| 72 | std::string |
Davide Pesavento | 5ee8ec0 | 2018-09-01 19:06:12 -0400 | [diff] [blame] | 73 | getScheme() const |
Yingdi Yu | 0b60e7a | 2015-07-16 21:05:11 -0700 | [diff] [blame] | 74 | { |
| 75 | return "tpm-osxkeychain"; |
| 76 | } |
| 77 | |
| 78 | private: |
| 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 |