LCOV - code coverage report
Current view: top level - dns - tsigerror.cc (source / functions) Hit Total Coverage
Test: report.info Lines: 18 18 100.0 %
Date: 2012-05-15 Functions: 4 4 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 13 16 81.2 %

           Branch data     Line data    Source code
       1                 :            : // Copyright (C) 2011  Internet Systems Consortium, Inc. ("ISC")
       2                 :            : //
       3                 :            : // Permission to use, copy, modify, and/or distribute this software for any
       4                 :            : // purpose with or without fee is hereby granted, provided that the above
       5                 :            : // copyright notice and this permission notice appear in all copies.
       6                 :            : //
       7                 :            : // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
       8                 :            : // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
       9                 :            : // AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
      10                 :            : // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
      11                 :            : // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
      12                 :            : // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
      13                 :            : // PERFORMANCE OF THIS SOFTWARE.
      14                 :            : 
      15                 :            : #include <ostream>
      16                 :            : #include <string>
      17                 :            : 
      18                 :            : #include <boost/lexical_cast.hpp>
      19                 :            : 
      20                 :            : #include <exceptions/exceptions.h>
      21                 :            : 
      22                 :            : #include <dns/rcode.h>
      23                 :            : #include <dns/tsigerror.h>
      24                 :            : 
      25                 :            : namespace isc {
      26                 :            : namespace dns {
      27                 :            : namespace {
      28                 :            : const char* const tsigerror_text[] = {
      29                 :            :     "BADSIG",
      30                 :            :     "BADKEY",
      31                 :            :     "BADTIME"
      32                 :            : };
      33                 :            : }
      34                 :            : 
      35                 :        988 : TSIGError::TSIGError(Rcode rcode) : code_(rcode.getCode()) {
      36         [ +  + ]:        494 :     if (code_ > MAX_RCODE_FOR_TSIGERROR) {
      37 [ +  - ][ +  - ]:          4 :         isc_throw(OutOfRange, "Invalid RCODE for TSIG Error: " << rcode);
      38                 :            :     }
      39                 :        492 : }
      40                 :            : 
      41                 :            : std::string
      42                 :         42 : TSIGError::toText() const {
      43         [ +  + ]:         42 :     if (code_ <= MAX_RCODE_FOR_TSIGERROR) {
      44                 :         18 :         return (Rcode(code_).toText());
      45         [ +  + ]:         24 :     } else if (code_ <= BAD_TIME_CODE) {
      46                 :         19 :         return (tsigerror_text[code_ - (MAX_RCODE_FOR_TSIGERROR + 1)]);
      47                 :            :     } else {
      48                 :            :         return (boost::lexical_cast<std::string>(code_));
      49                 :            :     }
      50                 :            : }
      51                 :            : 
      52                 :            : Rcode
      53                 :         19 : TSIGError::toRcode() const {
      54         [ +  + ]:         19 :     if (code_ <= MAX_RCODE_FOR_TSIGERROR) {
      55                 :          2 :         return (Rcode(code_));
      56                 :            :     }
      57         [ +  + ]:         17 :     if (code_ > BAD_TIME_CODE) {
      58                 :          4 :         return (Rcode::SERVFAIL());
      59                 :            :     }
      60                 :         13 :     return (Rcode::NOTAUTH());
      61                 :            : }
      62                 :            : 
      63                 :            : std::ostream&
      64                 :          1 : operator<<(std::ostream& os, const TSIGError& error) {
      65         [ +  - ]:          1 :     return (os << error.toText());
      66                 :            : }
      67                 :            : } // namespace dns
      68                 :         20 : } // namespace isc

Generated by: LCOV version 1.9