Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 1 | /* -*- 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 Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 12 | #include <boost/tokenizer.hpp> |
| 13 | using boost::tokenizer; |
| 14 | using boost::escaped_list_separator; |
Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 15 | |
| 16 | using namespace std; |
| 17 | using namespace ndn; |
| 18 | |
| 19 | TrustedContact::TrustedContact(const EndorseCertificate& selfEndorseCertificate, |
| 20 | const string& trustScope, |
| 21 | const string& alias) |
| 22 | : ContactItem(selfEndorseCertificate, alias) |
| 23 | { |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 24 | m_isIntroducer = true; |
| 25 | |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 26 | 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 Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 31 | { |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 32 | m_trustScope.push_back(Regex::fromName(Name(*it))); |
| 33 | m_trustScopeName.push_back(Name(*it)); |
| 34 | it++; |
Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 35 | } |
| 36 | } |
| 37 | |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 38 | TrustedContact::TrustedContact(const ContactItem& contactItem) |
| 39 | : ContactItem(contactItem) |
| 40 | { |
| 41 | m_isIntroducer = true; |
| 42 | } |
| 43 | |
| 44 | TrustedContact::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 Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 52 | bool |
| 53 | TrustedContact::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 | |
| 63 | Ptr<Blob> |
| 64 | TrustedContact::getTrustScopeBlob() const |
| 65 | { |
| 66 | ostringstream oss; |
Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 67 | |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 68 | 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 Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 73 | |
Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 74 | return Ptr<Blob>(new Blob(oss.str().c_str(), oss.str().size())); |
| 75 | } |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 76 | |