blob: 9e574b72953c172cafa3ed26063aa9488e412041 [file] [log] [blame]
Yingdi Yuede8eaf2013-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 Yu42f66462013-10-31 17:38:22 -070012#include <boost/tokenizer.hpp>
13using boost::tokenizer;
14using boost::escaped_list_separator;
Yingdi Yuede8eaf2013-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 Yua50c3252013-11-03 15:05:26 -080024 m_isIntroducer = true;
25
Yingdi Yu42f66462013-10-31 17:38:22 -070026 tokenizer<escaped_list_separator<char> > trustScopeItems(trustScope, escaped_list_separator<char> ("\\", " \t", "'\""));
27
28 tokenizer<escaped_list_separator<char> >::iterator it = trustScopeItems.begin();
29
30 while (it != trustScopeItems.end())
Yingdi Yuede8eaf2013-10-14 14:07:03 -070031 {
Yingdi Yu42f66462013-10-31 17:38:22 -070032 m_trustScope.push_back(Regex::fromName(Name(*it)));
33 m_trustScopeName.push_back(Name(*it));
34 it++;
Yingdi Yuede8eaf2013-10-14 14:07:03 -070035 }
36}
37
Yingdi Yua50c3252013-11-03 15:05:26 -080038TrustedContact::TrustedContact(const ContactItem& contactItem)
39 : ContactItem(contactItem)
40{
41 m_isIntroducer = true;
42}
43
44TrustedContact::TrustedContact(const TrustedContact& trustedContact)
45 : ContactItem(trustedContact)
46 , m_trustScope(trustedContact.m_trustScope)
47 , m_trustScopeName(trustedContact.m_trustScopeName)
48{
49 m_isIntroducer = true;
50}
51
Yingdi Yuede8eaf2013-10-14 14:07:03 -070052bool
53TrustedContact::canBeTrustedFor(const Name& name)
54{
55 vector<Ptr<Regex> >::iterator it = m_trustScope.begin();
56
57 for(; it != m_trustScope.end(); it++)
58 if((*it)->match(name))
59 return true;
60 return false;
61}
62
63Ptr<Blob>
64TrustedContact::getTrustScopeBlob() const
65{
66 ostringstream oss;
Yingdi Yuede8eaf2013-10-14 14:07:03 -070067
Yingdi Yu42f66462013-10-31 17:38:22 -070068 vector<Name>::const_iterator it = m_trustScopeName.begin();
69 if(it != m_trustScopeName.end())
70 oss << it->toUri();
71 for(; it != m_trustScopeName.end(); it++)
72 oss << " " << it->toUri();
Yingdi Yuede8eaf2013-10-14 14:07:03 -070073
Yingdi Yuede8eaf2013-10-14 14:07:03 -070074 return Ptr<Blob>(new Blob(oss.str().c_str(), oss.str().size()));
75}
Yingdi Yua50c3252013-11-03 15:05:26 -080076