blob: 60e9a9397b494deae881a7a6ba827e4ce87bd4c0 [file] [log] [blame]
Yingdi Yu53b8a9c2013-10-14 09:36:31 -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 "contact-item.h"
12#include "exception.h"
13
14#include <ndn.cxx/fields/signature-sha256-with-rsa.h>
15
Yingdi Yu79c25a22013-10-21 13:38:38 -070016#include "logging.h"
17
Yingdi Yu53b8a9c2013-10-14 09:36:31 -070018using namespace std;
19using namespace ndn;
20using namespace ndn::security;
21
Yingdi Yu79c25a22013-10-21 13:38:38 -070022INIT_LOGGER("ContactItem");
23
Yingdi Yu53b8a9c2013-10-14 09:36:31 -070024ContactItem::ContactItem(const EndorseCertificate& selfEndorseCertificate,
Yingdi Yu813d4e92013-11-03 16:22:05 -080025 bool isIntroducer,
Yingdi Yu53b8a9c2013-10-14 09:36:31 -070026 const string& alias)
27 : m_selfEndorseCertificate(selfEndorseCertificate)
Yingdi Yu813d4e92013-11-03 16:22:05 -080028 , m_isIntroducer(isIntroducer)
Yingdi Yu53b8a9c2013-10-14 09:36:31 -070029{
30 Name endorsedkeyName = selfEndorseCertificate.getPublicKeyName();
Yingdi Yu53b8a9c2013-10-14 09:36:31 -070031
32 m_namespace = endorsedkeyName.getSubName(0, endorsedkeyName.size() - 1);
Yingdi Yub35b8652013-11-07 11:32:40 -080033
Yingdi Yu53b8a9c2013-10-14 09:36:31 -070034
35 Ptr<ProfileData> profileData = selfEndorseCertificate.getProfileData();
36 Ptr<const Blob> nameBlob = profileData->getProfile().getProfileEntry("name");
37 m_name = string(nameBlob->buf(), nameBlob->size());
Yingdi Yub35b8652013-11-07 11:32:40 -080038 m_alias = alias.empty() ? m_name : alias;
Yingdi Yu53b8a9c2013-10-14 09:36:31 -070039 Ptr<const Blob> institutionBlob = profileData->getProfile().getProfileEntry("institution");
Yingdi Yu8fb16a42013-11-10 18:35:09 -080040 if(institutionBlob != NULL)
41 m_institution = string(institutionBlob->buf(), institutionBlob->size());
42 else
43 m_institution = string();
Yingdi Yu53b8a9c2013-10-14 09:36:31 -070044}
45
Yingdi Yua50c3252013-11-03 15:05:26 -080046ContactItem::ContactItem(const ContactItem& contactItem)
47 : m_selfEndorseCertificate(contactItem.m_selfEndorseCertificate)
48 , m_namespace(contactItem.m_namespace)
49 , m_alias(contactItem.m_alias)
50 , m_name(contactItem.m_name)
51 , m_institution(contactItem.m_institution)
Yingdi Yu813d4e92013-11-03 16:22:05 -080052 , m_isIntroducer(contactItem.m_isIntroducer)
53 , m_trustScope(contactItem.m_trustScope)
54 , m_trustScopeName(contactItem.m_trustScopeName)
Yingdi Yua50c3252013-11-03 15:05:26 -080055{}
56
Yingdi Yu813d4e92013-11-03 16:22:05 -080057bool
58ContactItem::canBeTrustedFor(const Name& name)
59{
60 vector<Ptr<Regex> >::iterator it = m_trustScope.begin();
61
62 for(; it != m_trustScope.end(); it++)
63 if((*it)->match(name))
64 return true;
65 return false;
66}