blob: 7db842a00988f6cfcfcb2382531f05dadead229d [file] [log] [blame]
Yingdi Yud04ed1a2013-10-14 14:07:03 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2013, Regents of the University of California
4 * Yingdi Yu
5 *
6 * BSD license, See the LICENSE file for more information
7 *
8 * Author: Yingdi Yu <yingdi@cs.ucla.edu>
9 */
10
11#include "trusted-contact.h"
Yingdi Yu7989eb22013-10-31 17:38:22 -070012#include <boost/tokenizer.hpp>
13using boost::tokenizer;
14using boost::escaped_list_separator;
Yingdi Yud04ed1a2013-10-14 14:07:03 -070015
16using namespace std;
17using namespace ndn;
18
19TrustedContact::TrustedContact(const EndorseCertificate& selfEndorseCertificate,
20 const string& trustScope,
21 const string& alias)
22 : ContactItem(selfEndorseCertificate, alias)
23{
Yingdi Yu7989eb22013-10-31 17:38:22 -070024 tokenizer<escaped_list_separator<char> > trustScopeItems(trustScope, escaped_list_separator<char> ("\\", " \t", "'\""));
25
26 tokenizer<escaped_list_separator<char> >::iterator it = trustScopeItems.begin();
27
28 while (it != trustScopeItems.end())
Yingdi Yud04ed1a2013-10-14 14:07:03 -070029 {
Yingdi Yu7989eb22013-10-31 17:38:22 -070030 m_trustScope.push_back(Regex::fromName(Name(*it)));
31 m_trustScopeName.push_back(Name(*it));
32 it++;
Yingdi Yud04ed1a2013-10-14 14:07:03 -070033 }
34}
35
36bool
37TrustedContact::canBeTrustedFor(const Name& name)
38{
39 vector<Ptr<Regex> >::iterator it = m_trustScope.begin();
40
41 for(; it != m_trustScope.end(); it++)
42 if((*it)->match(name))
43 return true;
44 return false;
45}
46
47Ptr<Blob>
48TrustedContact::getTrustScopeBlob() const
49{
50 ostringstream oss;
Yingdi Yud04ed1a2013-10-14 14:07:03 -070051
Yingdi Yu7989eb22013-10-31 17:38:22 -070052 vector<Name>::const_iterator it = m_trustScopeName.begin();
53 if(it != m_trustScopeName.end())
54 oss << it->toUri();
55 for(; it != m_trustScopeName.end(); it++)
56 oss << " " << it->toUri();
Yingdi Yud04ed1a2013-10-14 14:07:03 -070057
Yingdi Yud04ed1a2013-10-14 14:07:03 -070058 return Ptr<Blob>(new Blob(oss.str().c_str(), oss.str().size()));
59}