Browse Source

[2164] Add RRset::getSIGRdataCount()

Mukund Sivaraman 12 years ago
parent
commit
ceec0dc9bb
3 changed files with 37 additions and 0 deletions
  1. 9 0
      src/lib/dns/rrset.cc
  2. 9 0
      src/lib/dns/rrset.h
  3. 19 0
      src/lib/dns/tests/rrset_unittest.cc

+ 9 - 0
src/lib/dns/rrset.cc

@@ -249,6 +249,15 @@ RRset::RRset(const Name& name, const RRClass& rrclass,
 
 RRset::~RRset() {}
 
+unsigned int
+RRset::getSIGRdataCount() const {
+    if (rrsig_ != NULL) {
+        return (rrsig_->getRdataCount());
+    } else {
+        return (0);
+    }
+}
+
 namespace {
 class BasicRdataIterator : public RdataIterator {
 private:

+ 9 - 0
src/lib/dns/rrset.h

@@ -810,6 +810,15 @@ public:
 
     virtual ~RRset();
 
+    /// \brief Returns the number of \c RRSIG records associated with
+    /// the \c RRset.
+    ///
+    /// Note that an \c RRset with no RRSIG records may exist, so this
+    /// method may return 0.
+    ///
+    /// \return The number of \c RRSIG records associated.
+    unsigned int getSIGRdataCount() const;
+
     /// \brief Updates the owner name of the \c RRset, including RRSIGs if any
     virtual void setName(const Name& n) {
         BasicRRset::setName(n);

+ 19 - 0
src/lib/dns/tests/rrset_unittest.cc

@@ -338,4 +338,23 @@ TEST_F(RRsetRRSIGTest, addRRsig) {
     rrset_a->addRRsig(rrset_rrsig);
     EXPECT_EQ(3, sp->getRdataCount());
 }
+
+TEST_F(RRsetRRSIGTest, getSIGRdataCount) {
+    EXPECT_EQ(1, rrset_aaaa->getSIGRdataCount());
+    EXPECT_EQ(0, rrset_a->getSIGRdataCount());
+
+    rrset_rrsig = RRsetPtr(new RRset(test_name, RRClass::IN(),
+                                     RRType::RRSIG(), RRTTL(3600)));
+    // one signature algorithm (5 = RSA/SHA-1)
+    rrset_rrsig->addRdata(generic::RRSIG("A 5 3 3600 "
+                                         "20000101000000 20000201000000 "
+                                         "12345 example.com. FAKEFAKEFAKE"));
+    // another signature algorithm (3 = DSA/SHA-1)
+    rrset_rrsig->addRdata(generic::RRSIG("A 3 3 3600 "
+                                         "20000101000000 20000201000000 "
+                                         "12345 example.com. FAKEFAKEFAKE"));
+    rrset_a->addRRsig(rrset_rrsig);
+
+    EXPECT_EQ(2, rrset_a->getSIGRdataCount());
+}
 }