security: Implement IdentityCertificate.
diff --git a/Makefile.am b/Makefile.am
index 3928da1..c0975d7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -126,6 +126,7 @@
ndn-cpp/security/security-exception.cpp \
ndn-cpp/security/certificate/certificate-extension.cpp \
ndn-cpp/security/certificate/certificate-subject-description.cpp \
+ ndn-cpp/security/certificate/identity-certificate.cpp \
ndn-cpp/security/certificate/public-key.cpp \
ndn-cpp/security/identity/basic-identity-storage.cpp \
ndn-cpp/security/identity/identity-manager.cpp \
diff --git a/Makefile.in b/Makefile.in
index 49bb6e2..46239d2 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -185,6 +185,7 @@
ndn-cpp/security/security-exception.lo \
ndn-cpp/security/certificate/certificate-extension.lo \
ndn-cpp/security/certificate/certificate-subject-description.lo \
+ ndn-cpp/security/certificate/identity-certificate.lo \
ndn-cpp/security/certificate/public-key.lo \
ndn-cpp/security/identity/basic-identity-storage.lo \
ndn-cpp/security/identity/identity-manager.lo \
@@ -665,6 +666,7 @@
ndn-cpp/security/security-exception.cpp \
ndn-cpp/security/certificate/certificate-extension.cpp \
ndn-cpp/security/certificate/certificate-subject-description.cpp \
+ ndn-cpp/security/certificate/identity-certificate.cpp \
ndn-cpp/security/certificate/public-key.cpp \
ndn-cpp/security/identity/basic-identity-storage.cpp \
ndn-cpp/security/identity/identity-manager.cpp \
@@ -906,6 +908,9 @@
ndn-cpp/security/certificate/certificate-subject-description.lo: \
ndn-cpp/security/certificate/$(am__dirstamp) \
ndn-cpp/security/certificate/$(DEPDIR)/$(am__dirstamp)
+ndn-cpp/security/certificate/identity-certificate.lo: \
+ ndn-cpp/security/certificate/$(am__dirstamp) \
+ ndn-cpp/security/certificate/$(DEPDIR)/$(am__dirstamp)
ndn-cpp/security/certificate/public-key.lo: \
ndn-cpp/security/certificate/$(am__dirstamp) \
ndn-cpp/security/certificate/$(DEPDIR)/$(am__dirstamp)
@@ -1085,6 +1090,7 @@
@AMDEP_TRUE@@am__include@ @am__quote@ndn-cpp/security/$(DEPDIR)/security-exception.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@ndn-cpp/security/certificate/$(DEPDIR)/certificate-extension.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@ndn-cpp/security/certificate/$(DEPDIR)/certificate-subject-description.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@ndn-cpp/security/certificate/$(DEPDIR)/identity-certificate.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@ndn-cpp/security/certificate/$(DEPDIR)/public-key.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@ndn-cpp/security/identity/$(DEPDIR)/basic-identity-storage.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@ndn-cpp/security/identity/$(DEPDIR)/identity-manager.Plo@am__quote@
diff --git a/include/ndn-cpp/security/certificate/certificate-extension.hpp b/include/ndn-cpp/security/certificate/certificate-extension.hpp
index 5990cd4..d71086b 100644
--- a/include/ndn-cpp/security/certificate/certificate-extension.hpp
+++ b/include/ndn-cpp/security/certificate/certificate-extension.hpp
@@ -1,6 +1,7 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
/**
* Copyright (C) 2013 Regents of the University of California.
+ * @author: Yingdi Yu <yingdi@cs.ucla.edu>
* @author: Jeff Thompson <jefft0@remap.ucla.edu>
* See COPYING for copyright and distribution information.
*/
diff --git a/include/ndn-cpp/security/certificate/identity-certificate.hpp b/include/ndn-cpp/security/certificate/identity-certificate.hpp
index 1dff7e9..8cb244d 100644
--- a/include/ndn-cpp/security/certificate/identity-certificate.hpp
+++ b/include/ndn-cpp/security/certificate/identity-certificate.hpp
@@ -19,7 +19,9 @@
/**
* The default constructor.
*/
- IdentityCertificate();
+ IdentityCertificate()
+ {
+ }
/**
* Create an IdentityCertificate from the content in the data packet.
@@ -32,11 +34,12 @@
*/
virtual
~IdentityCertificate();
- Data &
- setName (const Name& name);
+
+ Data &
+ setName(const Name& name);
virtual Name
- getPublicKeyName () const;
+ getPublicKeyName() const;
static bool
isIdentityCertificate(const Certificate& certificate);
diff --git a/ndn-cpp/security/certificate/certificate-extension.cpp b/ndn-cpp/security/certificate/certificate-extension.cpp
index 9f6c39a..f0fed8b 100644
--- a/ndn-cpp/security/certificate/certificate-extension.cpp
+++ b/ndn-cpp/security/certificate/certificate-extension.cpp
@@ -1,6 +1,7 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
/**
* Copyright (C) 2013 Regents of the University of California.
+ * @author: Yingdi Yu <yingdi@cs.ucla.edu>
* @author: Jeff Thompson <jefft0@remap.ucla.edu>
* See COPYING for copyright and distribution information.
*/
diff --git a/ndn-cpp/security/certificate/identity-certificate.cpp b/ndn-cpp/security/certificate/identity-certificate.cpp
new file mode 100644
index 0000000..72e9531
--- /dev/null
+++ b/ndn-cpp/security/certificate/identity-certificate.cpp
@@ -0,0 +1,68 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/**
+ * Copyright (C) 2013 Regents of the University of California.
+ * @author: Yingdi Yu <yingdi@cs.ucla.edu>
+ * @author: Jeff Thompson <jefft0@remap.ucla.edu>
+ * See COPYING for copyright and distribution information.
+ */
+
+#include <ndn-cpp/security/security-exception.hpp>
+#include <ndn-cpp/security/certificate/identity-certificate.hpp>
+
+using namespace std;
+
+namespace ndn {
+
+IdentityCertificate::IdentityCertificate(const Data& data)
+ : Certificate(data)
+{
+ if (!isCorrectName(data.getName()))
+ throw SecurityException("Wrong Identity Certificate Name!");
+}
+
+bool
+IdentityCertificate::isCorrectName(const Name& name)
+{
+ int i = name.size() - 1;
+
+ for (; i >= 0; i--) {
+ if(name.get(i).toEscapedString() == string("ID-CERT"))
+ break;
+ }
+
+ if (i < 0)
+ return false;
+
+ return true;
+}
+
+Data&
+IdentityCertificate::setName(const Name& name)
+{
+ if (!isCorrectName(name))
+ throw SecurityException("Wrong Identity Certificate Name!");
+
+ Data::setName(name);
+ return *this;
+}
+
+Name
+IdentityCertificate::getPublicKeyName() const
+{
+ const Name& certificateName = getName();
+ int i = certificateName.size() - 1;
+
+ for (; i >= 0; i--)
+ if(certificateName.get(i).toEscapedString() == string("ID-CERT"))
+ break;
+
+ return certificateName.getSubName(0, i);
+}
+
+bool
+IdentityCertificate::isIdentityCertificate(const Certificate& certificate)
+{
+ return isCorrectName(certificate.getName());
+}
+
+}