Yingdi Yu | 0b60e7a | 2015-07-16 21:05:11 -0700 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2013-2016 Regents of the University of California. |
| 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" |
| 27 | #include <Availability.h> |
| 28 | |
| 29 | namespace ndn { |
| 30 | namespace security { |
| 31 | namespace tpm { |
| 32 | namespace tests { |
| 33 | |
| 34 | /** |
| 35 | * @brief A wrapper of tpm::BackEndOsx for unit test template. |
| 36 | */ |
| 37 | class BackEndWrapperOsx |
| 38 | { |
| 39 | public: |
| 40 | BackEndWrapperOsx() |
| 41 | { |
| 42 | std::string oldHOME; |
| 43 | if (std::getenv("OLD_HOME")) |
| 44 | oldHOME = std::getenv("OLD_HOME"); |
| 45 | |
| 46 | if (std::getenv("HOME")) |
| 47 | m_HOME = std::getenv("HOME"); |
| 48 | |
| 49 | if (!oldHOME.empty()) |
| 50 | setenv("HOME", oldHOME.c_str(), 1); |
| 51 | else |
| 52 | unsetenv("HOME"); |
| 53 | |
| 54 | m_impl = unique_ptr<BackEnd>(new BackEndOsx); |
| 55 | } |
| 56 | |
| 57 | ~BackEndWrapperOsx() |
| 58 | { |
| 59 | if (!m_HOME.empty()) |
| 60 | setenv("HOME", m_HOME.c_str(), 1); |
| 61 | else |
| 62 | unsetenv("HOME"); |
| 63 | } |
| 64 | |
| 65 | BackEnd& |
| 66 | getTpm() |
| 67 | { |
| 68 | return *m_impl; |
| 69 | } |
| 70 | |
| 71 | std::string |
| 72 | getScheme() |
| 73 | { |
| 74 | return "tpm-osxkeychain"; |
| 75 | } |
| 76 | |
| 77 | private: |
| 78 | std::string m_HOME; |
| 79 | unique_ptr<BackEnd> m_impl; |
| 80 | }; |
| 81 | |
| 82 | } // namespace tests |
| 83 | } // namespace tpm |
| 84 | } // namespace security |
| 85 | } // namespace ndn |
| 86 | |
| 87 | #endif // NDN_TESTS_SECURITY_TPM_BACK_END_WRAPPER_OSX_HPP |