Parcourir la source

cleanup:
avoided using a hardocded magic number
simplified RRType construction


git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@1076 e5f2f494-b856-4b98-b285-d166d9295462

JINMEI Tatuya il y a 15 ans
Parent
commit
25e8db65ba
1 fichiers modifiés avec 11 ajouts et 3 suppressions
  1. 11 3
      src/lib/dns/cpp/rdata/generic/rrsig_46.cc

+ 11 - 3
src/lib/dns/cpp/rdata/generic/rrsig_46.cc

@@ -39,6 +39,15 @@ using namespace std;
 // BEGIN_ISC_NAMESPACE
 // BEGIN_RDATA_NAMESPACE
 
+namespace {
+// This is the minimum necessary length of all wire-format RRSIG RDATA:
+// - two 8-bit fields (algorithm and labels)
+// - two 16-bit fields (covered and tag)
+// - three 32-bit fields (original TTL, expire and inception)
+const size_t RRSIG_MINIMUM_LEN = 2 * sizeof(uint8_t) + 2 * sizeof(uint16_t) +
+    3 * sizeof(uint32_t);
+}
+
 struct RRSIGImpl {
     // straightforward representation of RRSIG RDATA fields
     RRSIGImpl(const RRType& covered, uint8_t algorithm, uint8_t labels,
@@ -100,12 +109,11 @@ RRSIG::RRSIG(InputBuffer& buffer, size_t rdata_len)
 {
     size_t pos = buffer.getPosition();
 
-    if (rdata_len < 18) {
+    if (rdata_len < RRSIG_MINIMUM_LEN) {
         dns_throw(InvalidRdataLength, "RRSIG too short");
     }
 
-    uint16_t typecode = buffer.readUint16();
-    RRType covered(typecode);
+    RRType covered(buffer);
     uint8_t algorithm = buffer.readUint8();
     uint8_t labels = buffer.readUint8();
     uint32_t originalttl = buffer.readUint32();