Add ProfileData
diff --git a/src/profile-data.cpp b/src/profile-data.cpp
index f4b6bde..b779adc 100644
--- a/src/profile-data.cpp
+++ b/src/profile-data.cpp
@@ -10,35 +10,51 @@
#include "profile-data.h"
#include "exception.h"
-
#include <ndn.cxx/fields/signature-sha256-with-rsa.h>
-using namespace std;
using namespace ndn;
+using namespace std;
-ProfileData::ProfileData (const Name& identityName,
- const string& profileType,
- const Blob& profileValue)
+ProfileData::ProfileData(const Name& identity,
+ const Profile& profile)
: Data()
- , m_identityName(identityName)
- , m_profileType(profileType)
+ , m_identity(identity)
+ , m_profile(profile)
{
- Name tmpName = identityName;
- setName(tmpName.append(profileType));
- setContent(Content(profileValue.buf(), profileValue.size()));
+ Name dataName = identity;
+ TimeInterval ti = time::NowUnixTimestamp();
+ ostringstream oss;
+ oss << ti.total_seconds();
+
+ dataName.append("PROFILE").append(oss.str());
+ setName(dataName);
+ Ptr<Blob> profileBlob = profile.toDerBlob();
+ setContent(Content(profileBlob->buf(), profileBlob->size()));
}
-
-ProfileData::ProfileData (const ProfileData& profile)
+ProfileData::ProfileData(const ProfileData& profileData)
: Data()
- , m_identityName(profile.m_identityName)
- , m_profileType(profile.m_profileType)
+ , m_identity(profileData.m_identity)
+ , m_profile(profileData.m_profile)
{
- setName(profile.getName());
- setContent(profile.getContent());
+ Ptr<const signature::Sha256WithRsa> dataSig = boost::dynamic_pointer_cast<const signature::Sha256WithRsa>(profileData.getSignature());
+ Ptr<signature::Sha256WithRsa> newSig = Ptr<signature::Sha256WithRsa>::Create();
+
+ Ptr<SignedBlob> newSignedBlob = NULL;
+ if(profileData.getSignedBlob() != NULL)
+ newSignedBlob = Ptr<SignedBlob>(new SignedBlob(*profileData.getSignedBlob()));
+
+ newSig->setKeyLocator(dataSig->getKeyLocator());
+ newSig->setPublisherKeyDigest(dataSig->getPublisherKeyDigest());
+ newSig->setSignatureBits(dataSig->getSignatureBits());
+
+ setName(profileData.getName());
+ setSignature(newSig);
+ setContent(profileData.getContent());
+ setSignedBlob(newSignedBlob);
}
-
-ProfileData::ProfileData (const Data& data)
+
+ProfileData::ProfileData(const Data& data)
: Data()
{
const Name& dataName = data.getName();
@@ -54,12 +70,14 @@
}
}
- if(profileIndex < 0 || profileIndex + 1 >= dataName.size())
+ if(profileIndex < 0)
throw LnException("No PROFILE component in data name!");
-
+
+ m_identity = dataName.getSubName(0, profileIndex);
+
Ptr<const signature::Sha256WithRsa> dataSig = boost::dynamic_pointer_cast<const signature::Sha256WithRsa>(data.getSignature());
Ptr<signature::Sha256WithRsa> newSig = Ptr<signature::Sha256WithRsa>::Create();
-
+
Ptr<SignedBlob> newSignedBlob = NULL;
if(data.getSignedBlob() != NULL)
newSignedBlob = Ptr<SignedBlob>(new SignedBlob(*data.getSignedBlob()));
@@ -73,7 +91,5 @@
setContent(data.getContent());
setSignedBlob(newSignedBlob);
- m_identityName = dataName.getSubName(0, profileIndex);
- m_profileType = dataName.get(profileIndex+1).toUri();
+ m_profile = *Profile::fromDerBlob(data.content());
}
-