Yingdi Yu | 53b8a9c | 2013-10-14 09:36:31 -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 "contact-item.h" |
| 12 | #include "exception.h" |
| 13 | |
| 14 | #include <ndn.cxx/fields/signature-sha256-with-rsa.h> |
| 15 | |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 16 | #include "logging.h" |
| 17 | |
Yingdi Yu | 53b8a9c | 2013-10-14 09:36:31 -0700 | [diff] [blame] | 18 | using namespace std; |
| 19 | using namespace ndn; |
| 20 | using namespace ndn::security; |
| 21 | |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 22 | INIT_LOGGER("ContactItem"); |
| 23 | |
Yingdi Yu | 53b8a9c | 2013-10-14 09:36:31 -0700 | [diff] [blame] | 24 | ContactItem::ContactItem(const EndorseCertificate& selfEndorseCertificate, |
Yingdi Yu | 813d4e9 | 2013-11-03 16:22:05 -0800 | [diff] [blame] | 25 | bool isIntroducer, |
Yingdi Yu | 53b8a9c | 2013-10-14 09:36:31 -0700 | [diff] [blame] | 26 | const string& alias) |
| 27 | : m_selfEndorseCertificate(selfEndorseCertificate) |
Yingdi Yu | 813d4e9 | 2013-11-03 16:22:05 -0800 | [diff] [blame] | 28 | , m_isIntroducer(isIntroducer) |
Yingdi Yu | 53b8a9c | 2013-10-14 09:36:31 -0700 | [diff] [blame] | 29 | { |
| 30 | Name endorsedkeyName = selfEndorseCertificate.getPublicKeyName(); |
Yingdi Yu | 53b8a9c | 2013-10-14 09:36:31 -0700 | [diff] [blame] | 31 | |
| 32 | m_namespace = endorsedkeyName.getSubName(0, endorsedkeyName.size() - 1); |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 33 | |
Yingdi Yu | 53b8a9c | 2013-10-14 09:36:31 -0700 | [diff] [blame] | 34 | |
| 35 | Ptr<ProfileData> profileData = selfEndorseCertificate.getProfileData(); |
| 36 | Ptr<const Blob> nameBlob = profileData->getProfile().getProfileEntry("name"); |
| 37 | m_name = string(nameBlob->buf(), nameBlob->size()); |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 38 | m_alias = alias.empty() ? m_name : alias; |
Yingdi Yu | 53b8a9c | 2013-10-14 09:36:31 -0700 | [diff] [blame] | 39 | Ptr<const Blob> institutionBlob = profileData->getProfile().getProfileEntry("institution"); |
| 40 | m_institution = string(institutionBlob->buf(), institutionBlob->size()); |
| 41 | } |
| 42 | |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 43 | ContactItem::ContactItem(const ContactItem& contactItem) |
| 44 | : m_selfEndorseCertificate(contactItem.m_selfEndorseCertificate) |
| 45 | , m_namespace(contactItem.m_namespace) |
| 46 | , m_alias(contactItem.m_alias) |
| 47 | , m_name(contactItem.m_name) |
| 48 | , m_institution(contactItem.m_institution) |
Yingdi Yu | 813d4e9 | 2013-11-03 16:22:05 -0800 | [diff] [blame] | 49 | , m_isIntroducer(contactItem.m_isIntroducer) |
| 50 | , m_trustScope(contactItem.m_trustScope) |
| 51 | , m_trustScopeName(contactItem.m_trustScopeName) |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 52 | {} |
| 53 | |
Yingdi Yu | 813d4e9 | 2013-11-03 16:22:05 -0800 | [diff] [blame] | 54 | bool |
| 55 | ContactItem::canBeTrustedFor(const Name& name) |
| 56 | { |
| 57 | vector<Ptr<Regex> >::iterator it = m_trustScope.begin(); |
| 58 | |
| 59 | for(; it != m_trustScope.end(); it++) |
| 60 | if((*it)->match(name)) |
| 61 | return true; |
| 62 | return false; |
| 63 | } |