diff options
author | Paul Selkirk <pselkirk@isc.org> | 2013-04-10 04:48:23 +0200 |
---|---|---|
committer | Paul Selkirk <pselkirk@isc.org> | 2013-04-10 04:48:23 +0200 |
commit | c9095ff3de68440efa427a536985bb01e0125504 (patch) | |
tree | 88bd990d03551f715c2aeddb1c284d2a958d922d /src | |
parent | [2521] enabled previously disabled rrsig test (diff) | |
download | kea-c9095ff3de68440efa427a536985bb01e0125504.tar.xz kea-c9095ff3de68440efa427a536985bb01e0125504.zip |
[2521] add MasterLexer constructor for DHCID
Diffstat (limited to 'src')
-rwxr-xr-x | src/lib/dns/gen-rdatacode.py.in | 1 | ||||
-rw-r--r-- | src/lib/dns/rdata/in_1/dhcid_49.cc | 63 | ||||
-rw-r--r-- | src/lib/dns/rdata/in_1/dhcid_49.h | 5 |
3 files changed, 51 insertions, 18 deletions
diff --git a/src/lib/dns/gen-rdatacode.py.in b/src/lib/dns/gen-rdatacode.py.in index 28644570e4..02ad537524 100755 --- a/src/lib/dns/gen-rdatacode.py.in +++ b/src/lib/dns/gen-rdatacode.py.in @@ -36,6 +36,7 @@ new_rdata_factory_users = [('a', 'in'), ('aaaa', 'in'), ('afsdb', 'generic'), ('cname', 'generic'), + ('dhcid', 'in'), ('dlv', 'generic'), ('dname', 'generic'), ('ds', 'generic'), diff --git a/src/lib/dns/rdata/in_1/dhcid_49.cc b/src/lib/dns/rdata/in_1/dhcid_49.cc index 77451619af..01ba370088 100644 --- a/src/lib/dns/rdata/in_1/dhcid_49.cc +++ b/src/lib/dns/rdata/in_1/dhcid_49.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2011-2013 Internet Systems Consortium, Inc. ("ISC") // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above @@ -15,8 +15,6 @@ #include <stdint.h> #include <string.h> -#include <string> - #include <exceptions/exceptions.h> #include <util/buffer.h> @@ -28,10 +26,26 @@ using namespace std; using namespace isc::util; +using namespace isc::util::encode; // BEGIN_ISC_NAMESPACE // BEGIN_RDATA_NAMESPACE +void +DHCID::createFromLexer(MasterLexer& lexer) { + string digest_txt = lexer.getNextToken(MasterToken::STRING).getString(); + decodeBase64(digest_txt, digest_); + + // RFC4701 states DNS software should consider the RDATA section to + // be opaque, but there must be at least three bytes in the data: + // < 2 octets > Identifier type code + // < 1 octet > Digest type code + if (digest_.size() < 3) { + isc_throw(InvalidRdataLength, "DHCID length " << digest_.size() << + " too short, need at least 3 bytes"); + } +} + /// \brief Constructor from string. /// /// \param dhcid_str A base-64 representation of the DHCID binary data. @@ -48,22 +62,37 @@ using namespace isc::util; /// If the data is less than 3 octets (i.e. it cannot contain id type code and /// digest type code), an exception of class \c InvalidRdataLength is thrown. DHCID::DHCID(const std::string& dhcid_str) { - istringstream iss(dhcid_str); - stringbuf digestbuf; - - iss >> &digestbuf; - isc::util::encode::decodeBase64(digestbuf.str(), digest_); - - // RFC4701 states DNS software should consider the RDATA section to - // be opaque, but there must be at least three bytes in the data: - // < 2 octets > Identifier type code - // < 1 octet > Digest type code - if (digest_.size() < 3) { - isc_throw(InvalidRdataLength, "DHCID length " << digest_.size() << - " too short, need at least 3 bytes"); + try { + std::istringstream iss(dhcid_str); + MasterLexer lexer; + lexer.pushSource(iss); + + createFromLexer(lexer); + + if (lexer.getNextToken().getType() != MasterToken::END_OF_FILE) { + isc_throw(InvalidRdataText, "extra input text for DHCID: " + << dhcid_str); + } + } catch (const MasterLexer::LexerError& ex) { + isc_throw(InvalidRdataText, "Failed to construct DHCID from '" << + dhcid_str << "': " << ex.what()); } } +/// \brief Constructor with a context of MasterLexer. +/// +/// The \c lexer should point to the beginning of valid textual representation +/// of a DHCID RDATA. +/// +/// \throw MasterLexer::LexerError General parsing error such as missing field. +/// +/// \param lexer A \c MasterLexer object parsing a master file for the +/// RDATA to be created +DHCID::DHCID(MasterLexer& lexer, const Name*, + MasterLoader::Options, MasterLoaderCallbacks&) { + createFromLexer(lexer); +} + /// \brief Constructor from wire-format data. /// /// \param buffer A buffer storing the wire format data. @@ -112,7 +141,7 @@ DHCID::toWire(AbstractMessageRenderer& renderer) const { /// \return A string representation of \c DHCID. string DHCID::toText() const { - return (isc::util::encode::encodeBase64(digest_)); + return (encodeBase64(digest_)); } /// \brief Compare two instances of \c DHCID RDATA. diff --git a/src/lib/dns/rdata/in_1/dhcid_49.h b/src/lib/dns/rdata/in_1/dhcid_49.h index 90f5fabf94..17bd7466ca 100644 --- a/src/lib/dns/rdata/in_1/dhcid_49.h +++ b/src/lib/dns/rdata/in_1/dhcid_49.h @@ -1,4 +1,4 @@ -// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2011-2013 Internet Systems Consortium, Inc. ("ISC") // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above @@ -43,6 +43,9 @@ public: const std::vector<uint8_t>& getDigest() const; private: + // helper for string and lexer constructors + void createFromLexer(MasterLexer& lexer); + /// \brief Private data representation /// /// Opaque data at least 3 octets long as per RFC4701. |