blob: f4b6bdef5ef408870070071a4e4eea2cad57d618 [file] [log] [blame]
Yingdi Yuad56f1c2013-10-10 17:27:54 -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 "profile-data.h"
Yingdi Yu38e329b2013-10-10 22:11:35 -070012#include "exception.h"
13
14#include <ndn.cxx/fields/signature-sha256-with-rsa.h>
Yingdi Yuad56f1c2013-10-10 17:27:54 -070015
16using namespace std;
17using namespace ndn;
18
19ProfileData::ProfileData (const Name& identityName,
20 const string& profileType,
21 const Blob& profileValue)
22 : Data()
23 , m_identityName(identityName)
24 , m_profileType(profileType)
25{
26 Name tmpName = identityName;
27 setName(tmpName.append(profileType));
28 setContent(Content(profileValue.buf(), profileValue.size()));
29}
30
31
32ProfileData::ProfileData (const ProfileData& profile)
33 : Data()
34 , m_identityName(profile.m_identityName)
35 , m_profileType(profile.m_profileType)
36{
37 setName(profile.getName());
38 setContent(profile.getContent());
39}
Yingdi Yu38e329b2013-10-10 22:11:35 -070040
41ProfileData::ProfileData (const Data& data)
42 : Data()
Yingdi Yuad56f1c2013-10-10 17:27:54 -070043{
Yingdi Yu38e329b2013-10-10 22:11:35 -070044 const Name& dataName = data.getName();
45 name::Component appFlag(string("PROFILE"));
46
47 int profileIndex = -1;
48 for(int i = 0; i < dataName.size(); i++)
49 {
50 if(0 == dataName.get(i).compare(appFlag))
51 {
52 profileIndex = i;
53 break;
54 }
55 }
56
57 if(profileIndex < 0 || profileIndex + 1 >= dataName.size())
58 throw LnException("No PROFILE component in data name!");
59
60 Ptr<const signature::Sha256WithRsa> dataSig = boost::dynamic_pointer_cast<const signature::Sha256WithRsa>(data.getSignature());
61 Ptr<signature::Sha256WithRsa> newSig = Ptr<signature::Sha256WithRsa>::Create();
62
63 Ptr<SignedBlob> newSignedBlob = NULL;
64 if(data.getSignedBlob() != NULL)
65 newSignedBlob = Ptr<SignedBlob>(new SignedBlob(*data.getSignedBlob()));
66
67 newSig->setKeyLocator(dataSig->getKeyLocator());
68 newSig->setPublisherKeyDigest(dataSig->getPublisherKeyDigest());
69 newSig->setSignatureBits(dataSig->getSignatureBits());
70
71 setName(data.getName());
72 setSignature(newSig);
73 setContent(data.getContent());
74 setSignedBlob(newSignedBlob);
75
76 m_identityName = dataName.getSubName(0, profileIndex);
77 m_profileType = dataName.get(profileIndex+1).toUri();
Yingdi Yuad56f1c2013-10-10 17:27:54 -070078}
79