Yingdi Yu | d04ed1a | 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 | 7989eb2 | 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 | d04ed1a | 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 | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame^] | 24 | 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 Yu | d04ed1a | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 29 | { |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame^] | 30 | m_trustScope.push_back(Regex::fromName(Name(*it))); |
| 31 | m_trustScopeName.push_back(Name(*it)); |
| 32 | it++; |
Yingdi Yu | d04ed1a | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 33 | } |
| 34 | } |
| 35 | |
| 36 | bool |
| 37 | TrustedContact::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 | |
| 47 | Ptr<Blob> |
| 48 | TrustedContact::getTrustScopeBlob() const |
| 49 | { |
| 50 | ostringstream oss; |
Yingdi Yu | d04ed1a | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 51 | |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame^] | 52 | 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 Yu | d04ed1a | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 57 | |
Yingdi Yu | d04ed1a | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 58 | return Ptr<Blob>(new Blob(oss.str().c_str(), oss.str().size())); |
| 59 | } |