Yingdi Yu | ad56f1c | 2013-10-10 17:27:54 -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 "profile-data.h" |
Yingdi Yu | 38e329b | 2013-10-10 22:11:35 -0700 | [diff] [blame] | 12 | #include "exception.h" |
Yingdi Yu | 38e329b | 2013-10-10 22:11:35 -0700 | [diff] [blame] | 13 | #include <ndn.cxx/fields/signature-sha256-with-rsa.h> |
Yingdi Yu | 68aced9 | 2013-10-17 21:13:03 -0700 | [diff] [blame] | 14 | #include "logging.h" |
| 15 | |
Yingdi Yu | ad56f1c | 2013-10-10 17:27:54 -0700 | [diff] [blame] | 16 | |
Yingdi Yu | ad56f1c | 2013-10-10 17:27:54 -0700 | [diff] [blame] | 17 | using namespace ndn; |
Yingdi Yu | 5ff6210 | 2013-10-13 17:24:50 -0700 | [diff] [blame] | 18 | using namespace std; |
Yingdi Yu | ad56f1c | 2013-10-10 17:27:54 -0700 | [diff] [blame] | 19 | |
Yingdi Yu | 68aced9 | 2013-10-17 21:13:03 -0700 | [diff] [blame] | 20 | INIT_LOGGER("ProfileData"); |
| 21 | |
Yingdi Yu | e9ea5c9 | 2013-11-06 18:42:34 -0800 | [diff] [blame] | 22 | ProfileData::ProfileData(const Profile& profile) |
Yingdi Yu | ad56f1c | 2013-10-10 17:27:54 -0700 | [diff] [blame] | 23 | : Data() |
Yingdi Yu | e9ea5c9 | 2013-11-06 18:42:34 -0800 | [diff] [blame] | 24 | , m_identity(profile.getIdentityName()) |
Yingdi Yu | 5ff6210 | 2013-10-13 17:24:50 -0700 | [diff] [blame] | 25 | , m_profile(profile) |
Yingdi Yu | ad56f1c | 2013-10-10 17:27:54 -0700 | [diff] [blame] | 26 | { |
Yingdi Yu | e9ea5c9 | 2013-11-06 18:42:34 -0800 | [diff] [blame] | 27 | Name dataName = m_identity; |
Yingdi Yu | 5ff6210 | 2013-10-13 17:24:50 -0700 | [diff] [blame] | 28 | |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 29 | dataName.append("PROFILE").appendVersion(); |
Yingdi Yu | 5ff6210 | 2013-10-13 17:24:50 -0700 | [diff] [blame] | 30 | setName(dataName); |
| 31 | Ptr<Blob> profileBlob = profile.toDerBlob(); |
| 32 | setContent(Content(profileBlob->buf(), profileBlob->size())); |
Yingdi Yu | ad56f1c | 2013-10-10 17:27:54 -0700 | [diff] [blame] | 33 | } |
| 34 | |
Yingdi Yu | 5ff6210 | 2013-10-13 17:24:50 -0700 | [diff] [blame] | 35 | ProfileData::ProfileData(const ProfileData& profileData) |
Yingdi Yu | ad56f1c | 2013-10-10 17:27:54 -0700 | [diff] [blame] | 36 | : Data() |
Yingdi Yu | 5ff6210 | 2013-10-13 17:24:50 -0700 | [diff] [blame] | 37 | , m_identity(profileData.m_identity) |
| 38 | , m_profile(profileData.m_profile) |
Yingdi Yu | ad56f1c | 2013-10-10 17:27:54 -0700 | [diff] [blame] | 39 | { |
Yingdi Yu | 5ff6210 | 2013-10-13 17:24:50 -0700 | [diff] [blame] | 40 | Ptr<const signature::Sha256WithRsa> dataSig = boost::dynamic_pointer_cast<const signature::Sha256WithRsa>(profileData.getSignature()); |
| 41 | Ptr<signature::Sha256WithRsa> newSig = Ptr<signature::Sha256WithRsa>::Create(); |
| 42 | |
| 43 | Ptr<SignedBlob> newSignedBlob = NULL; |
| 44 | if(profileData.getSignedBlob() != NULL) |
| 45 | newSignedBlob = Ptr<SignedBlob>(new SignedBlob(*profileData.getSignedBlob())); |
| 46 | |
| 47 | newSig->setKeyLocator(dataSig->getKeyLocator()); |
| 48 | newSig->setPublisherKeyDigest(dataSig->getPublisherKeyDigest()); |
| 49 | newSig->setSignatureBits(dataSig->getSignatureBits()); |
| 50 | |
| 51 | setName(profileData.getName()); |
| 52 | setSignature(newSig); |
| 53 | setContent(profileData.getContent()); |
| 54 | setSignedBlob(newSignedBlob); |
Yingdi Yu | ad56f1c | 2013-10-10 17:27:54 -0700 | [diff] [blame] | 55 | } |
Yingdi Yu | 5ff6210 | 2013-10-13 17:24:50 -0700 | [diff] [blame] | 56 | |
| 57 | ProfileData::ProfileData(const Data& data) |
Yingdi Yu | 38e329b | 2013-10-10 22:11:35 -0700 | [diff] [blame] | 58 | : Data() |
Yingdi Yu | ad56f1c | 2013-10-10 17:27:54 -0700 | [diff] [blame] | 59 | { |
Yingdi Yu | 38e329b | 2013-10-10 22:11:35 -0700 | [diff] [blame] | 60 | const Name& dataName = data.getName(); |
| 61 | name::Component appFlag(string("PROFILE")); |
| 62 | |
| 63 | int profileIndex = -1; |
| 64 | for(int i = 0; i < dataName.size(); i++) |
| 65 | { |
| 66 | if(0 == dataName.get(i).compare(appFlag)) |
| 67 | { |
| 68 | profileIndex = i; |
| 69 | break; |
| 70 | } |
| 71 | } |
| 72 | |
Yingdi Yu | 5ff6210 | 2013-10-13 17:24:50 -0700 | [diff] [blame] | 73 | if(profileIndex < 0) |
Yingdi Yu | 38e329b | 2013-10-10 22:11:35 -0700 | [diff] [blame] | 74 | throw LnException("No PROFILE component in data name!"); |
Yingdi Yu | 5ff6210 | 2013-10-13 17:24:50 -0700 | [diff] [blame] | 75 | |
| 76 | m_identity = dataName.getSubName(0, profileIndex); |
| 77 | |
Yingdi Yu | 38e329b | 2013-10-10 22:11:35 -0700 | [diff] [blame] | 78 | Ptr<const signature::Sha256WithRsa> dataSig = boost::dynamic_pointer_cast<const signature::Sha256WithRsa>(data.getSignature()); |
| 79 | Ptr<signature::Sha256WithRsa> newSig = Ptr<signature::Sha256WithRsa>::Create(); |
Yingdi Yu | 5ff6210 | 2013-10-13 17:24:50 -0700 | [diff] [blame] | 80 | |
Yingdi Yu | 38e329b | 2013-10-10 22:11:35 -0700 | [diff] [blame] | 81 | Ptr<SignedBlob> newSignedBlob = NULL; |
| 82 | if(data.getSignedBlob() != NULL) |
| 83 | newSignedBlob = Ptr<SignedBlob>(new SignedBlob(*data.getSignedBlob())); |
| 84 | |
| 85 | newSig->setKeyLocator(dataSig->getKeyLocator()); |
| 86 | newSig->setPublisherKeyDigest(dataSig->getPublisherKeyDigest()); |
| 87 | newSig->setSignatureBits(dataSig->getSignatureBits()); |
| 88 | |
| 89 | setName(data.getName()); |
| 90 | setSignature(newSig); |
| 91 | setContent(data.getContent()); |
| 92 | setSignedBlob(newSignedBlob); |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 93 | |
Yingdi Yu | 5ff6210 | 2013-10-13 17:24:50 -0700 | [diff] [blame] | 94 | m_profile = *Profile::fromDerBlob(data.content()); |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 95 | |
Yingdi Yu | ad56f1c | 2013-10-10 17:27:54 -0700 | [diff] [blame] | 96 | } |