security: Return *this from SigningInfo setters
This change is to allow chaining of SigningInfo setters.
Change-Id: I6d37b6028cf4d94f17f574b5a0d5cc65482580f1
diff --git a/src/security/signing-info.cpp b/src/security/signing-info.cpp
index 57cf046..f8a7892 100644
--- a/src/security/signing-info.cpp
+++ b/src/security/signing-info.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016 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).
*
@@ -74,37 +74,43 @@
}
}
-void
+SigningInfo&
SigningInfo::setSigningIdentity(const Name& identity)
{
m_type = SIGNER_TYPE_ID;
m_name = identity;
+ return *this;
}
-void
+
+SigningInfo&
SigningInfo::setSigningKeyName(const Name& keyName)
{
m_type = SIGNER_TYPE_KEY;
m_name = keyName;
+ return *this;
}
-void
+SigningInfo&
SigningInfo::setSigningCertName(const Name& certificateName)
{
m_type = SIGNER_TYPE_CERT;
m_name = certificateName;
+ return *this;
}
-void
+SigningInfo&
SigningInfo::setSha256Signing()
{
m_type = SIGNER_TYPE_SHA256;
m_name.clear();
+ return *this;
}
-void
+SigningInfo&
SigningInfo::setSignatureInfo(const SignatureInfo& signatureInfo)
{
m_info = signatureInfo;
+ return *this;
}
std::ostream&
diff --git a/src/security/signing-info.hpp b/src/security/signing-info.hpp
index aaa2770..375d9e8 100644
--- a/src/security/signing-info.hpp
+++ b/src/security/signing-info.hpp
@@ -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).
*
@@ -93,28 +93,28 @@
* @brief Set signer as an identity with name @p identity
* @post Change the signerType to SIGNER_TYPE_ID
*/
- void
+ SigningInfo&
setSigningIdentity(const Name& identity);
/**
* @brief Set signer as a key with name @p keyName
* @post Change the signerType to SIGNER_TYPE_KEY
*/
- void
+ SigningInfo&
setSigningKeyName(const Name& keyName);
/**
* @brief Set signer as a certificate with name @p certificateName
* @post Change the signerType to SIGNER_TYPE_CERT
*/
- void
+ SigningInfo&
setSigningCertName(const Name& certificateName);
/**
* @brief Set Sha256 as the signing method
* @post Reset signerName, also change the signerType to SIGNER_TYPE_SHA256
*/
- void
+ SigningInfo&
setSha256Signing();
/**
@@ -138,10 +138,11 @@
/**
* @brief Set the digest algorithm for public key operations
*/
- void
+ SigningInfo&
setDigestAlgorithm(const DigestAlgorithm& algorithm)
{
m_digestAlgorithm = algorithm;
+ return *this;
}
/**
@@ -156,7 +157,7 @@
/**
* @brief Set a semi-prepared SignatureInfo;
*/
- void
+ SigningInfo&
setSignatureInfo(const SignatureInfo& signatureInfo);
/**
diff --git a/tests/unit-tests/security/signing-info.t.cpp b/tests/unit-tests/security/signing-info.t.cpp
index e7e1447..6613fea 100644
--- a/tests/unit-tests/security/signing-info.t.cpp
+++ b/tests/unit-tests/security/signing-info.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016 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).
*
@@ -152,6 +152,19 @@
"id:/localhost/identity/digest-sha256");
}
+BOOST_AUTO_TEST_CASE(Chaining)
+{
+ SigningInfo info = SigningInfo()
+ .setSigningIdentity("/identity")
+ .setSigningKeyName("/key/name")
+ .setSigningCertName("/cert/name")
+ .setSha256Signing()
+ .setDigestAlgorithm(DigestAlgorithm::SHA256)
+ .setSignatureInfo(SignatureInfo());
+
+ BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(info), "id:/localhost/identity/digest-sha256");
+}
+
BOOST_AUTO_TEST_SUITE_END() // TestSigningInfo
BOOST_AUTO_TEST_SUITE_END() // Security