tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 1 | // |
| 2 | // Created by Tyler on 10/6/20. |
| 3 | // |
| 4 | |
| 5 | #include "assignment-hash.hpp" |
| 6 | #include <ndn-cxx/util/sha256.hpp> |
| 7 | |
| 8 | namespace ndn { |
| 9 | namespace ndncert { |
| 10 | |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 11 | NDNCERT_REGISTER_FUNCFACTORY(AssignmentHash, "hash"); |
| 12 | |
Zhiyi Zhang | 8683ec9 | 2020-10-07 18:18:35 -0700 | [diff] [blame^] | 13 | AssignmentHash::AssignmentHash(const std::string& format) |
| 14 | : NameAssignmentFuncFactory("hash", format) |
| 15 | {} |
| 16 | |
| 17 | std::vector<PartialName> |
| 18 | AssignmentHash::assignName(const std::vector<std::tuple<std::string, std::string>>& params) |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 19 | { |
Zhiyi Zhang | 8683ec9 | 2020-10-07 18:18:35 -0700 | [diff] [blame^] | 20 | std::vector<PartialName> resultList; |
| 21 | Name result; |
| 22 | for (const auto& item : m_nameFormat) { |
| 23 | auto it = std::find_if(params.begin(), params.end(), |
| 24 | [&](const std::tuple<std::string, std::string>& e) { return std::get<0>(e) == item; }); |
| 25 | if (it != params.end()) { |
| 26 | util::Sha256 digest; |
| 27 | digest << std::get<1>(*it); |
| 28 | result.append(digest.toString()); |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 29 | } |
Zhiyi Zhang | 8683ec9 | 2020-10-07 18:18:35 -0700 | [diff] [blame^] | 30 | else { |
| 31 | return resultList; |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 32 | } |
Zhiyi Zhang | 8683ec9 | 2020-10-07 18:18:35 -0700 | [diff] [blame^] | 33 | } |
| 34 | resultList.push_back(std::move(result)); |
| 35 | return resultList; |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 36 | } |
| 37 | |
Zhiyi Zhang | 8683ec9 | 2020-10-07 18:18:35 -0700 | [diff] [blame^] | 38 | } // namespace ndncert |
| 39 | } // namespace ndn |