blob: 08f4fa607b987b7c9ad3fd6c248ac030bf432cad [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
16using namespace std;
17using namespace ndn;
18using namespace ndn::security;
19
20ContactItem::ContactItem(const EndorseCertificate& selfEndorseCertificate,
21 const string& alias)
22 : m_selfEndorseCertificate(selfEndorseCertificate)
23{
24 Name endorsedkeyName = selfEndorseCertificate.getPublicKeyName();
25 Ptr<const signature::Sha256WithRsa> endorseSig = boost::dynamic_pointer_cast<const signature::Sha256WithRsa>(selfEndorseCertificate.getSignature());
26 const Name& signingKeyName = endorseSig->getKeyLocator().getKeyName();
27
28 if(endorsedkeyName != signingKeyName)
29 throw LnException("not a self-claimed");
30
31 m_namespace = endorsedkeyName.getSubName(0, endorsedkeyName.size() - 1);
32 m_alias = alias.empty() ? m_namespace.toUri() : alias;
33
34 Ptr<ProfileData> profileData = selfEndorseCertificate.getProfileData();
35 Ptr<const Blob> nameBlob = profileData->getProfile().getProfileEntry("name");
36 m_name = string(nameBlob->buf(), nameBlob->size());
37 Ptr<const Blob> institutionBlob = profileData->getProfile().getProfileEntry("institution");
38 m_institution = string(institutionBlob->buf(), institutionBlob->size());
39}
40