security: Porting security elements to the updated framework
Change-Id: Ie9ad6ee34f94fc520b9d3c8adf871e2557eaa9b6
diff --git a/include/ndn-cpp/security/certificate/certificate.hpp b/include/ndn-cpp/security/certificate/certificate.hpp
index 0c7323b..c2fd95a 100644
--- a/include/ndn-cpp/security/certificate/certificate.hpp
+++ b/include/ndn-cpp/security/certificate/certificate.hpp
@@ -18,11 +18,13 @@
namespace ndn {
-typedef std::vector<CertificateSubjectDescription> SubjectDescriptionList;
-typedef std::vector<CertificateExtension> ExtensionList;
-
class Certificate : public Data {
public:
+ struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} };
+
+ typedef std::vector<CertificateSubjectDescription> SubjectDescriptionList;
+ typedef std::vector<CertificateExtension> ExtensionList;
+
/**
* The default constructor.
*/
@@ -40,6 +42,9 @@
virtual
~Certificate();
+ inline void
+ wireDecode(const Block &wire);
+
/**
* encode certificate info into content
*/
@@ -117,7 +122,7 @@
isTooLate();
void
- printCertificate();
+ printCertificate(std::ostream &os) const;
protected:
void
@@ -131,6 +136,21 @@
ExtensionList extensionList_;
};
+inline void
+Certificate::wireDecode(const Block &wire)
+{
+ Data::wireDecode(wire);
+ decode();
}
+
+inline std::ostream&
+operator <<(std::ostream &os, const Certificate &cert)
+{
+ cert.printCertificate(os);
+ return os;
+}
+
+} // namespace ndn
+
#endif
diff --git a/include/ndn-cpp/security/certificate/identity-certificate.hpp b/include/ndn-cpp/security/certificate/identity-certificate.hpp
index 4d3a9db..85c8e72 100644
--- a/include/ndn-cpp/security/certificate/identity-certificate.hpp
+++ b/include/ndn-cpp/security/certificate/identity-certificate.hpp
@@ -16,12 +16,13 @@
class IdentityCertificate : public Certificate
{
public:
+ struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} };
+
/**
* The default constructor.
*/
- IdentityCertificate()
- {
- }
+ inline
+ IdentityCertificate();
// Note: The copy constructor works because publicKeyName_ has a copy constructor.
@@ -29,29 +30,20 @@
* Create an IdentityCertificate from the content in the data packet.
* @param data The data packet with the content to decode.
*/
+ inline
IdentityCertificate(const Data& data);
/**
- * The copy constructor.
- */
- IdentityCertificate(const IdentityCertificate& identityCertificate);
-
- /**
* The virtual destructor.
*/
- virtual
+ inline virtual
~IdentityCertificate();
- /**
- * Override the base class method to check that the name is a valid identity certificate name.
- * @param name The identity certificate name which is copied.
- * @return This Data so that you can chain calls to update values.
- */
- virtual Data &
- setName(const Name& name);
-
- Name
- getPublicKeyName () const { return publicKeyName_; }
+ inline void
+ wireDecode(const Block &wire);
+
+ inline const Name &
+ getPublicKeyName () const;
static bool
isIdentityCertificate(const Certificate& certificate);
@@ -75,6 +67,36 @@
Name publicKeyName_;
};
+inline
+IdentityCertificate::IdentityCertificate()
+{
+}
+
+inline
+IdentityCertificate::IdentityCertificate(const Data& data)
+ : Certificate(data)
+{
+ setPublicKeyName();
+}
+
+inline
+IdentityCertificate::~IdentityCertificate()
+{
+}
+
+inline void
+IdentityCertificate::wireDecode(const Block &wire)
+{
+ Certificate::wireDecode(wire);
+ setPublicKeyName();
+}
+
+inline const Name &
+IdentityCertificate::getPublicKeyName () const
+{
+ return publicKeyName_;
+}
+
}
#endif
diff --git a/include/ndn-cpp/security/certificate/public-key.hpp b/include/ndn-cpp/security/certificate/public-key.hpp
index 43e1223..1fac1ec 100644
--- a/include/ndn-cpp/security/certificate/public-key.hpp
+++ b/include/ndn-cpp/security/certificate/public-key.hpp
@@ -33,13 +33,13 @@
*/
PublicKey(const uint8_t *keyDerBuf, size_t keyDerSize);
- const Buffer&
+ inline const Buffer&
get() const
{
return key_;
}
- void
+ inline void
set(const uint8_t *keyDerBuf, size_t keyDerSize)
{
Buffer buf(keyDerBuf, keyDerSize);
@@ -59,6 +59,18 @@
// Blob
// getDigest(DigestAlgorithm digestAlgorithm = DIGEST_ALGORITHM_SHA256) const;
+ inline bool
+ operator ==(const PublicKey &key) const
+ {
+ return key_ == key.key_;
+ }
+
+ inline bool
+ operator !=(const PublicKey &key) const
+ {
+ return key_ != key.key_;
+ }
+
private:
Buffer key_;
};