BIND 10 #2520: incremental base_n decoding

BIND 10 Development do-not-reply at isc.org
Fri Nov 30 03:57:07 UTC 2012


#2520: incremental base_n decoding
-------------------------------------+-------------------------------------
                   Reporter:         |                 Owner:  UnAssigned
  jinmei                             |                Status:  new
                       Type:  task   |             Milestone:  Next-Sprint-
                   Priority:         |  Proposed
  medium                             |              Keywords:
                  Component:         |             Sensitive:  0
  libdns++                           |           Sub-Project:  DNS
               CVSS Scoring:         |  Estimated Difficulty:  0
            Defect Severity:  N/A    |           Total Hours:  0
Feature Depending on Ticket:         |
  loadzone-ng                        |
        Add Hours to Ticket:  0      |
                  Internal?:  0      |
-------------------------------------+-------------------------------------
 I noticed that base_n decoding with our current API can be less
 efficient, especially for cases like base64 encoded RRSIG signatures.
 named-signzone produces text like this:
 {{{
                         86400   RRSIG   A 5 3 86400 20121225123000 (
                                         20121125123000 57167 jinmei.org.
 pEyYj5y9+NuEZYtyhQlbiEddPGJvPp6Zyorh
 Xv5oSaUMkNDF8cxxMo4Ba15VuuHAj8L+r51Q
 jUxOOVE502UvtO+4cpLYK9MEjC+PKEeGMtQP
 Bed0fp8g6vtjvsNNaIVcwbu2BipKVwR4ZRoa
                                         su4HWjT7bmgDp6xgILbSXusKcPo= )
 }}}

 So our parser will get the signature part as 5 separate strings.
 With our current API we'd have to concatenate these into a single
 string and pass it to decodeBase64().  That's a waste, and
 maybe non negligible because a large signed zone will have many
 RRSIGs.

 So I propose introducing an extension to the current decoder API so
 that we can decode this type of textual input incrementally.
 Specifically, we define and implement the following class:

 {{{#!cpp
 class Base64Decoder {
 public:
     // Constructor with resulting vector.   result will be filled in with
     // the decoded data.
     Base64Decoder(vector<uint8_t>& result);

     // decode the given string into binary and append the data to the
 result
     // vector.  Note that 'len' may not be a multiple of 4, so this class
     // needs to have internal buffer to avoid intermediate decode error.
     // Example: if the initial length is 9, decode the first 8 bytes, and
     // keep the last byte in the internal buffer.  In the next call to
 add,
     // it conceptually prepend the internal buffer to the given string,
     // and repeat the same thing.  Also note that if the given string
 contains
     // a padding character, some special consideration is necessary.
     void add(const char* str, size_t len);

     // tell the class all encoded data have been passed.  This method
 checks
     // error cases.
     void finish();
 };
 }}}

 I believe we can use the existing internal implementation for most of
 the difficult part of the class, so it shouldn't be that difficult as
 it might look.

 Depending on difficulty of this task, also consider providing the same
 feature for hex decoder.  We can use it for the generic form of RDATA.
 This should be a rare case so less critical.

 As far as I can see we don't need it for base32 in practice.

-- 
Ticket URL: <http://bind10.isc.org/ticket/2520>
BIND 10 Development <http://bind10.isc.org>
BIND 10 Development


More information about the bind10-tickets mailing list