data: Converting Data packet and related fields to TLV
Change-Id: Ie7a6db7352384f14a830046e65a953a2d9bbb71c
diff --git a/src/data.cpp b/src/data.cpp
index db60f80..fa1afe9 100644
--- a/src/data.cpp
+++ b/src/data.cpp
@@ -7,131 +7,42 @@
#include <ndn-cpp/common.hpp>
#include <ndn-cpp/data.hpp>
-#include <ndn-cpp/sha256-with-rsa-signature.hpp>
-#include "c/data.h"
using namespace std;
namespace ndn {
-Signature::~Signature()
+const Block &
+Data::wireEncode() const
{
-}
+ // size_t signedPortionBeginOffset, signedPortionEndOffset;
+ // Blob encoding = wireFormat.encodeData(*this, &signedPortionBeginOffset, &signedPortionEndOffset);
+ // SignedBlob wireEncoding = SignedBlob(encoding, signedPortionBeginOffset, signedPortionEndOffset);
-void
-MetaInfo::get(struct ndn_MetaInfo& metaInfoStruct) const
+ // if (&wireFormat == WireFormat::getDefaultWireFormat())
+ // // This is the default wire encoding.
+ // const_cast<Data*>(this)->defaultWireEncoding_ = wireEncoding;
+
+ // return wireEncoding;
+ return wire_;
+}
+
+void
+Data::wireDecode(const Block &wire)
{
- metaInfoStruct.timestampMilliseconds = timestampMilliseconds_;
- metaInfoStruct.type = type_;
- metaInfoStruct.freshnessSeconds = freshnessSeconds_;
- finalBlockID_.get(metaInfoStruct.finalBlockID);
}
void
-MetaInfo::set(const struct ndn_MetaInfo& metaInfoStruct)
+Data::wireDecode(const uint8_t* input, size_t inputLength)
{
- timestampMilliseconds_ = metaInfoStruct.timestampMilliseconds;
- type_ = metaInfoStruct.type;
- freshnessSeconds_ = metaInfoStruct.freshnessSeconds;
- finalBlockID_ = Name::Component(Blob(metaInfoStruct.finalBlockID.value));
-}
-
-Data::Data()
-: signature_(new Sha256WithRsaSignature())
-{
-}
+ // size_t signedPortionBeginOffset, signedPortionEndOffset;
+ // wireFormat.decodeData(*this, input, inputLength, &signedPortionBeginOffset, &signedPortionEndOffset);
-Data::Data(const Name& name)
-: name_(name), signature_(new Sha256WithRsaSignature())
-{
-}
-
-Data::Data(const Data& data)
-: name_(data.name_), metaInfo_(data.metaInfo_), content_(data.content_), defaultWireEncoding_(data.defaultWireEncoding_)
-{
- if (data.signature_)
- signature_ = data.signature_->clone();
-}
-
-Data::~Data()
-{
-}
-
-Data& Data::operator=(const Data& data)
-{
- if (data.signature_)
- signature_ = data.signature_->clone();
- else
- signature_ = ptr_lib::shared_ptr<Signature>();
-
- name_ = data.name_;
- metaInfo_ = data.metaInfo_;
- content_ = data.content_;
- defaultWireEncoding_ = data.defaultWireEncoding_;
-
- return *this;
-}
-
-void
-Data::get(struct ndn_Data& dataStruct) const
-{
- signature_->get(dataStruct.signature);
- name_.get(dataStruct.name);
- metaInfo_.get(dataStruct.metaInfo);
- content_.get(dataStruct.content);
-}
-
-void
-Data::set(const struct ndn_Data& dataStruct)
-{
- signature_->set(dataStruct.signature);
- name_.set(dataStruct.name);
- metaInfo_.set(dataStruct.metaInfo);
- content_ = Blob(dataStruct.content);
-
- onChanged();
-}
-
-Data&
-Data::setName(const Name& name)
-{
- name_ = name;
- onChanged();
- return *this;
-}
-
-SignedBlob
-Data::wireEncode(WireFormat& wireFormat) const
-{
- size_t signedPortionBeginOffset, signedPortionEndOffset;
- Blob encoding = wireFormat.encodeData(*this, &signedPortionBeginOffset, &signedPortionEndOffset);
- SignedBlob wireEncoding = SignedBlob(encoding, signedPortionBeginOffset, signedPortionEndOffset);
-
- if (&wireFormat == WireFormat::getDefaultWireFormat())
- // This is the default wire encoding.
- const_cast<Data*>(this)->defaultWireEncoding_ = wireEncoding;
-
- return wireEncoding;
-}
-
-void
-Data::wireDecode(const uint8_t* input, size_t inputLength, WireFormat& wireFormat)
-{
- size_t signedPortionBeginOffset, signedPortionEndOffset;
- wireFormat.decodeData(*this, input, inputLength, &signedPortionBeginOffset, &signedPortionEndOffset);
-
- if (&wireFormat == WireFormat::getDefaultWireFormat())
- // This is the default wire encoding.
- defaultWireEncoding_ = SignedBlob(input, inputLength, signedPortionBeginOffset, signedPortionEndOffset);
- else
- defaultWireEncoding_ = SignedBlob();
-}
-
-void
-Data::onChanged()
-{
- // The values have changed, so the default wire encoding is invalidated.
- defaultWireEncoding_ = SignedBlob();
+ // if (&wireFormat == WireFormat::getDefaultWireFormat())
+ // // This is the default wire encoding.
+ // defaultWireEncoding_ = SignedBlob(input, inputLength, signedPortionBeginOffset, signedPortionEndOffset);
+ // else
+ // defaultWireEncoding_ = SignedBlob();
}
}
diff --git a/src/key-locator.cpp b/src/key-locator.cpp
deleted file mode 100644
index fbd7729..0000000
--- a/src/key-locator.cpp
+++ /dev/null
@@ -1,41 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#include <ndn-cpp/common.hpp>
-#include <ndn-cpp/key-locator.hpp>
-#include "c/key-locator.h"
-
-using namespace std;
-
-namespace ndn {
-
-void
-KeyLocator::get(struct ndn_KeyLocator& keyLocatorStruct) const
-{
- keyLocatorStruct.type = type_;
- keyData_.get(keyLocatorStruct.keyData);
- keyName_.get(keyLocatorStruct.keyName);
- keyLocatorStruct.keyNameType = keyNameType_;
-}
-
-void
-KeyLocator::set(const struct ndn_KeyLocator& keyLocatorStruct)
-{
- type_ = keyLocatorStruct.type;
- keyData_ = Blob(keyLocatorStruct.keyData);
- if (keyLocatorStruct.type == ndn_KeyLocatorType_KEYNAME) {
- keyName_.set(keyLocatorStruct.keyName);
- keyNameType_ = keyLocatorStruct.keyNameType;
- }
- else {
- keyName_.clear();
- keyNameType_ = (ndn_KeyNameType)-1;
- }
-}
-
-}
-
diff --git a/src/publisher-public-key-digest.cpp b/src/publisher-public-key-digest.cpp
deleted file mode 100644
index a0667fa..0000000
--- a/src/publisher-public-key-digest.cpp
+++ /dev/null
@@ -1,27 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#include "c/publisher-public-key-digest.h"
-#include <ndn-cpp/publisher-public-key-digest.hpp>
-
-using namespace std;
-
-namespace ndn {
-
-void
-PublisherPublicKeyDigest::get(struct ndn_PublisherPublicKeyDigest& publisherPublicKeyDigestStruct) const
-{
- publisherPublicKeyDigest_.get(publisherPublicKeyDigestStruct.publisherPublicKeyDigest);
-}
-
-void
-PublisherPublicKeyDigest::set(const struct ndn_PublisherPublicKeyDigest& publisherPublicKeyDigestStruct)
-{
- publisherPublicKeyDigest_ = Blob(publisherPublicKeyDigestStruct.publisherPublicKeyDigest);
-}
-
-}
diff --git a/src/sha256-with-rsa-signature.cpp b/src/sha256-with-rsa-signature.cpp
deleted file mode 100644
index ccf0230..0000000
--- a/src/sha256-with-rsa-signature.cpp
+++ /dev/null
@@ -1,41 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
- * See COPYING for copyright and distribution information.
- */
-
-#include "c/data.h"
-#include <ndn-cpp/sha256-with-rsa-signature.hpp>
-
-using namespace std;
-
-namespace ndn {
-
-ptr_lib::shared_ptr<Signature>
-Sha256WithRsaSignature::clone() const
-{
- return ptr_lib::shared_ptr<Signature>(new Sha256WithRsaSignature(*this));
-}
-
-void
-Sha256WithRsaSignature::get(struct ndn_Signature& signatureStruct) const
-{
- digestAlgorithm_.get(signatureStruct.digestAlgorithm);
- witness_.get(signatureStruct.witness);
- signature_.get(signatureStruct.signature);
- publisherPublicKeyDigest_.get(signatureStruct.publisherPublicKeyDigest);
- keyLocator_.get(signatureStruct.keyLocator);
-}
-
-void
-Sha256WithRsaSignature::set(const struct ndn_Signature& signatureStruct)
-{
- digestAlgorithm_ = Blob(signatureStruct.digestAlgorithm);
- witness_ = Blob(signatureStruct.witness);
- signature_ = Blob(signatureStruct.signature);
- publisherPublicKeyDigest_.set(signatureStruct.publisherPublicKeyDigest);
- keyLocator_.set(signatureStruct.keyLocator);
-}
-
-}