blob: c71b369606ee88b23b77f2017d2666c9a609f5c0 [file] [log] [blame]
tylerliu01d63ca2020-10-06 16:29:23 -07001//
2// Created by Tyler on 10/6/20.
3//
4
5#include "assignment-hash.hpp"
6#include <ndn-cxx/util/sha256.hpp>
7
8namespace ndn {
9namespace ndncert {
10
tylerliu01d63ca2020-10-06 16:29:23 -070011NDNCERT_REGISTER_FUNCFACTORY(AssignmentHash, "hash");
12
Zhiyi Zhang8683ec92020-10-07 18:18:35 -070013AssignmentHash::AssignmentHash(const std::string& format)
14 : NameAssignmentFuncFactory("hash", format)
15{}
16
17std::vector<PartialName>
18AssignmentHash::assignName(const std::vector<std::tuple<std::string, std::string>>& params)
tylerliu01d63ca2020-10-06 16:29:23 -070019{
Zhiyi Zhang8683ec92020-10-07 18:18:35 -070020 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());
tylerliu01d63ca2020-10-06 16:29:23 -070029 }
Zhiyi Zhang8683ec92020-10-07 18:18:35 -070030 else {
31 return resultList;
tylerliu01d63ca2020-10-06 16:29:23 -070032 }
Zhiyi Zhang8683ec92020-10-07 18:18:35 -070033 }
34 resultList.push_back(std::move(result));
35 return resultList;
tylerliu01d63ca2020-10-06 16:29:23 -070036}
37
Zhiyi Zhang8683ec92020-10-07 18:18:35 -070038} // namespace ndncert
39} // namespace ndn