blob: 9ce1b66ccaae32654249efdaa1cb2bca65f5bfed [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");
40 m_institution = string(institutionBlob->buf(), institutionBlob->size());
41}
42
Yingdi Yua50c3252013-11-03 15:05:26 -080043ContactItem::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 Yu813d4e92013-11-03 16:22:05 -080049 , m_isIntroducer(contactItem.m_isIntroducer)
50 , m_trustScope(contactItem.m_trustScope)
51 , m_trustScopeName(contactItem.m_trustScopeName)
Yingdi Yua50c3252013-11-03 15:05:26 -080052{}
53
Yingdi Yu813d4e92013-11-03 16:22:05 -080054bool
55ContactItem::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}