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