signature: reorganize code
In SignatureInfo, Signature, and its subclasses:
* Improve Doxygen.
* Improve error messages.
* Make comparison operators non-member functions.
refs #4171
Change-Id: I9395a72594702255b41e3700ee145f35fc1a41f2
diff --git a/src/security/digest-sha256.cpp b/src/security/digest-sha256.cpp
index bbe2e10..3c8867c 100644
--- a/src/security/digest-sha256.cpp
+++ b/src/security/digest-sha256.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2015 Regents of the University of California.
+/*
+ * Copyright (c) 2013-2017 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -32,7 +32,7 @@
: Signature(signature)
{
if (getType() != tlv::DigestSha256)
- BOOST_THROW_EXCEPTION(Error("Incorrect signature type"));
+ BOOST_THROW_EXCEPTION(Error("Cannot construct DigestSha256 from SignatureType " + to_string(getType())));
}
} // namespace ndn
diff --git a/src/security/digest-sha256.hpp b/src/security/digest-sha256.hpp
index d3a15de..fe226d8 100644
--- a/src/security/digest-sha256.hpp
+++ b/src/security/digest-sha256.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2014 Regents of the University of California.
+/*
+ * Copyright (c) 2013-2017 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -22,34 +22,29 @@
#ifndef NDN_SECURITY_DIGEST_SHA256_HPP
#define NDN_SECURITY_DIGEST_SHA256_HPP
-#include "../data.hpp"
-#include "../encoding/tlv.hpp"
+#include "../signature.hpp"
namespace ndn {
-/**
- * Represent a SHA256 digest.
+/** @brief Represents a signature of DigestSha256 type
+ *
+ * This signature type provides integrity protection using SHA-256 digest, but no provenance of a
+ * Data packet or any kind of guarantee that packet is from the original source.
*/
class DigestSha256 : public Signature
{
public:
- class Error : public Signature::Error
- {
- public:
- explicit
- Error(const std::string& what)
- : Signature::Error(what)
- {
- }
- };
-
+ /** @brief Create empty DigestSha256 signature
+ */
DigestSha256();
+ /** @brief Convert base Signature to DigestSha256 signature
+ * @throw Signature::Error SignatureType is not DigestSha256
+ */
explicit
DigestSha256(const Signature& signature);
-
};
} // namespace ndn
-#endif //NDN_SECURITY_DIGEST_SHA256_HPP
+#endif // NDN_SECURITY_DIGEST_SHA256_HPP
diff --git a/src/security/signature-sha256-with-ecdsa.cpp b/src/security/signature-sha256-with-ecdsa.cpp
index 72a5acd..bb86839 100644
--- a/src/security/signature-sha256-with-ecdsa.cpp
+++ b/src/security/signature-sha256-with-ecdsa.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2015 Regents of the University of California.
+/*
+ * Copyright (c) 2013-2017 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -32,17 +32,17 @@
: Signature(signature)
{
if (getType() != tlv::SignatureSha256WithEcdsa)
- BOOST_THROW_EXCEPTION(Error("Incorrect signature type"));
+ BOOST_THROW_EXCEPTION(Error("Cannot construct Sha256WithEcdsa from SignatureType " + to_string(getType())));
if (!hasKeyLocator()) {
- BOOST_THROW_EXCEPTION(Error("KeyLocator is missing"));
+ BOOST_THROW_EXCEPTION(Error("KeyLocator is missing in Sha256WithEcdsa signature"));
}
}
void
SignatureSha256WithEcdsa::unsetKeyLocator()
{
- BOOST_THROW_EXCEPTION(Error("KeyLocator cannot be reset for SignatureSha256WithEcdsa"));
+ BOOST_THROW_EXCEPTION(Error("KeyLocator cannot be unset in Sha256WithEcdsa signature"));
}
} // namespace ndn
diff --git a/src/security/signature-sha256-with-ecdsa.hpp b/src/security/signature-sha256-with-ecdsa.hpp
index 4b0eb7f..c75ffc9 100644
--- a/src/security/signature-sha256-with-ecdsa.hpp
+++ b/src/security/signature-sha256-with-ecdsa.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2014 Regents of the University of California.
+/*
+ * Copyright (c) 2013-2017 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -26,33 +26,32 @@
namespace ndn {
-/**
- * represents a Sha256WithEcdsa signature.
+/** @brief Represents a signature of Sha256WithEcdsa type
+ *
+ * This signature type provides integrity and provenance protection using an ECDSA signature over a
+ * SHA-256 digest.
*/
class SignatureSha256WithEcdsa : public Signature
{
public:
- class Error : public Signature::Error
- {
- public:
- explicit
- Error(const std::string& what)
- : Signature::Error(what)
- {
- }
- };
-
+ /** @brief Create Sha256WithEcdsa signature with specified KeyLocator
+ */
explicit
SignatureSha256WithEcdsa(const KeyLocator& keyLocator = KeyLocator());
+ /** @brief Convert base Signature to Sha256WithEcdsa signature
+ * @throw Signature::Error SignatureType is not Sha256WithEcdsa
+ */
explicit
SignatureSha256WithEcdsa(const Signature& signature);
private:
+ /** @brief Prevent unsetting KeyLocator
+ */
void
unsetKeyLocator();
};
} // namespace ndn
-#endif //NDN_SECURITY_SIGNATURE_SHA256_WITH_ECDSA_HPP
+#endif // NDN_SECURITY_SIGNATURE_SHA256_WITH_ECDSA_HPP
diff --git a/src/security/signature-sha256-with-rsa.cpp b/src/security/signature-sha256-with-rsa.cpp
index 72f5c8b..97946f8 100644
--- a/src/security/signature-sha256-with-rsa.cpp
+++ b/src/security/signature-sha256-with-rsa.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2015 Regents of the University of California.
+/*
+ * Copyright (c) 2013-2017 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -32,17 +32,17 @@
: Signature(signature)
{
if (getType() != tlv::SignatureSha256WithRsa)
- BOOST_THROW_EXCEPTION(Error("Incorrect signature type"));
+ BOOST_THROW_EXCEPTION(Error("Cannot construct Sha256WithRsa from SignatureType " + to_string(getType())));
if (!hasKeyLocator()) {
- BOOST_THROW_EXCEPTION(Error("KeyLocator is missing"));
+ BOOST_THROW_EXCEPTION(Error("KeyLocator is missing in Sha256WithRsa signature"));
}
}
void
SignatureSha256WithRsa::unsetKeyLocator()
{
- BOOST_THROW_EXCEPTION(Error("KeyLocator cannot be reset for SignatureSha256WithRsa"));
+ BOOST_THROW_EXCEPTION(Error("KeyLocator cannot be unset in Sha256WithRsa signature"));
}
} // namespace ndn
diff --git a/src/security/signature-sha256-with-rsa.hpp b/src/security/signature-sha256-with-rsa.hpp
index 937794b..2466018 100644
--- a/src/security/signature-sha256-with-rsa.hpp
+++ b/src/security/signature-sha256-with-rsa.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2014 Regents of the University of California.
+/*
+ * Copyright (c) 2013-2017 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -26,33 +26,32 @@
namespace ndn {
-/**
- * Represent a SHA256-with-RSA signature.
+/** @brief Represents a signature of Sha256WithRsa type
+ *
+ * This signature type provides integrity and provenance protection using a RSA signature over a
+ * SHA-256 digest.
*/
class SignatureSha256WithRsa : public Signature
{
public:
- class Error : public Signature::Error
- {
- public:
- explicit
- Error(const std::string& what)
- : Signature::Error(what)
- {
- }
- };
-
+ /** @brief Create Sha256WithRsa signature with specified KeyLocator
+ */
explicit
SignatureSha256WithRsa(const KeyLocator& keyLocator = KeyLocator());
+ /** @brief Convert base Signature to Sha256WithRsa signature
+ * @throw Signature::Error SignatureType is not Sha256WithRsa
+ */
explicit
SignatureSha256WithRsa(const Signature& signature);
private:
+ /** @brief Prevent unsetting KeyLocator
+ */
void
unsetKeyLocator();
};
} // namespace ndn
-#endif //NDN_SECURITY_SIGNATURE_SHA256_WITH_RSA_HPP
+#endif // NDN_SECURITY_SIGNATURE_SHA256_WITH_RSA_HPP