Finish ProfileData class
diff --git a/src/profile-data.cpp b/src/profile-data.cpp
index e111e54..f4b6bde 100644
--- a/src/profile-data.cpp
+++ b/src/profile-data.cpp
@@ -9,6 +9,9 @@
*/
#include "profile-data.h"
+#include "exception.h"
+
+#include <ndn.cxx/fields/signature-sha256-with-rsa.h>
using namespace std;
using namespace ndn;
@@ -34,11 +37,43 @@
setName(profile.getName());
setContent(profile.getContent());
}
-
-Ptr<ProfileData>
-ProfileData::fromData (const Data& data)
+
+ProfileData::ProfileData (const Data& data)
+ : Data()
{
- //TODO:
- return NULL;
+ const Name& dataName = data.getName();
+ name::Component appFlag(string("PROFILE"));
+
+ int profileIndex = -1;
+ for(int i = 0; i < dataName.size(); i++)
+ {
+ if(0 == dataName.get(i).compare(appFlag))
+ {
+ profileIndex = i;
+ break;
+ }
+ }
+
+ if(profileIndex < 0 || profileIndex + 1 >= dataName.size())
+ throw LnException("No PROFILE component in data name!");
+
+ 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()));
+
+ newSig->setKeyLocator(dataSig->getKeyLocator());
+ newSig->setPublisherKeyDigest(dataSig->getPublisherKeyDigest());
+ newSig->setSignatureBits(dataSig->getSignatureBits());
+
+ setName(data.getName());
+ setSignature(newSig);
+ setContent(data.getContent());
+ setSignedBlob(newSignedBlob);
+
+ m_identityName = dataName.getSubName(0, profileIndex);
+ m_profileType = dataName.get(profileIndex+1).toUri();
}