LCOV - code coverage report
Current view: top level - dns - tsigerror.h (source / functions) Hit Total Coverage
Test: report.info Lines: 61 61 100.0 %
Date: 2012-05-15 Functions: 19 19 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 64 118 54.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                 :            : #ifndef __TSIGERROR_H
      16                 :            : #define __TSIGERROR_H 1
      17                 :            : 
      18                 :            : #include <ostream>
      19                 :            : #include <string>
      20                 :            : 
      21                 :            : #include <dns/rcode.h>
      22                 :            : 
      23                 :            : namespace isc {
      24                 :            : namespace dns {
      25                 :            : /// TSIG errors
      26                 :            : ///
      27                 :            : /// The \c TSIGError class objects represent standard errors related to
      28                 :            : /// TSIG protocol operations as defined in related specifications, mainly
      29                 :            : /// in RFC2845.
      30                 :            : class TSIGError {
      31                 :            : public:
      32                 :            :     /// Constants for pre-defined TSIG error values.
      33                 :            :     ///
      34                 :            :     /// Code values from 0 through 15 (inclusive) are derived from those of
      35                 :            :     /// RCODE and are not defined here.  See the \c Rcode class.
      36                 :            :     ///
      37                 :            :     /// \note Unfortunately some systems define "BADSIG" as a macro in a public
      38                 :            :     /// header file.  To avoid conflict with it we add an underscore to our
      39                 :            :     /// definitions.
      40                 :            :     enum CodeValue {
      41                 :            :         BAD_SIG_CODE = 16, ///< 16: TSIG verification failure
      42                 :            :         BAD_KEY_CODE = 17, ///< 17: TSIG key is not recognized
      43                 :            :         BAD_TIME_CODE = 18 ///< 18: Current time and time signed are too different
      44                 :            :     };
      45                 :            : 
      46                 :            :     /// \name Constructors
      47                 :            :     ///
      48                 :            :     /// We use the default versions of destructor, copy constructor,
      49                 :            :     /// and assignment operator.
      50                 :            :     //@{
      51                 :            :     /// Constructor from the code value.
      52                 :            :     ///
      53                 :            :     /// \exception None
      54                 :            :     ///
      55                 :            :     /// \param error_code The underlying 16-bit error code value of the \c TSIGError.
      56                 :        138 :     explicit TSIGError(uint16_t error_code) : code_(error_code) {}
      57                 :            : 
      58                 :            :     /// Constructor from \c Rcode.
      59                 :            :     ///
      60                 :            :     /// As defined in RFC2845, error code values from 0 to 15 (inclusive) are
      61                 :            :     /// derived from the DNS RCODEs, which are represented via the \c Rcode
      62                 :            :     /// class in this library.  This constructor works as a converter from
      63                 :            :     /// these RCODEs to corresponding TSIGError objects.
      64                 :            :     ///
      65                 :            :     /// \exception isc::OutOfRange Given rcode is not convertible to
      66                 :            :     /// TSIGErrors.
      67                 :            :     ///
      68                 :            :     /// \param rcode the \c Rcode from which the TSIGError should be derived.
      69                 :            :     explicit TSIGError(Rcode rcode);
      70                 :            :     //@}
      71                 :            : 
      72                 :            :     /// \brief Returns the \c TSIGCode error code value.
      73                 :            :     ///
      74                 :            :     /// \exception None
      75                 :            :     ///
      76                 :            :     /// \return The underlying code value corresponding to the \c TSIGError.
      77                 :         22 :     uint16_t getCode() const { return (code_); }
      78                 :            : 
      79                 :            :     /// \brief Return true iff two \c TSIGError objects are equal.
      80                 :            :     ///
      81                 :            :     /// Two TSIGError objects are equal iff their error codes are equal.
      82                 :            :     ///
      83                 :            :     /// \exception None
      84                 :            :     ///
      85                 :            :     /// \param other the \c TSIGError object to compare against.
      86                 :            :     /// \return true if the two TSIGError are equal; otherwise false.
      87                 :            :     bool equals(const TSIGError& other) const
      88                 :       2016 :     { return (code_ == other.code_); }
      89                 :            : 
      90                 :            :     /// \brief Same as \c equals().
      91                 :            :     bool operator==(const TSIGError& other) const { return (equals(other)); }
      92                 :            : 
      93                 :            :     /// \brief Return true iff two \c TSIGError objects are not equal.
      94                 :            :     ///
      95                 :            :     /// \exception None
      96                 :            :     ///
      97                 :            :     /// \param other the \c TSIGError object to compare against.
      98                 :            :     /// \return true if the two TSIGError objects are not equal;
      99                 :            :     /// otherwise false.
     100                 :            :     bool nequals(const TSIGError& other) const
     101                 :        259 :     { return (code_ != other.code_); }
     102                 :            : 
     103                 :            :     /// \brief Same as \c nequals().
     104                 :            :     bool operator!=(const TSIGError& other) const { return (nequals(other)); }
     105                 :            : 
     106                 :            :     /// \brief Convert the \c TSIGError to a string.
     107                 :            :     ///
     108                 :            :     /// For codes derived from RCODEs up to 15, this method returns the
     109                 :            :     /// same string as \c Rcode::toText() for the corresponding code.
     110                 :            :     /// For other pre-defined code values (see TSIGError::CodeValue),
     111                 :            :     /// this method returns a string representation of the "mnemonic' used
     112                 :            :     /// for the enum and constant objects as defined in RFC2845.
     113                 :            :     /// For example, the string for code value 16 is "BADSIG", etc.
     114                 :            :     /// For other code values it returns a string representation of the decimal
     115                 :            :     /// number of the value, e.g. "32", "100", etc.
     116                 :            :     ///
     117                 :            :     /// \exception std::bad_alloc Resource allocation for the string fails
     118                 :            :     ///
     119                 :            :     /// \return A string representation of the \c TSIGError.
     120                 :            :     std::string toText() const;
     121                 :            : 
     122                 :            :     /// \brief Convert the \c TSIGError to a \c Rcode
     123                 :            :     ///
     124                 :            :     /// This method returns an \c Rcode object that is corresponding to
     125                 :            :     /// the TSIG error.  The returned \c Rcode is expected to be used
     126                 :            :     /// by a verifying server to specify the RCODE of a response when
     127                 :            :     /// TSIG verification fails.
     128                 :            :     ///
     129                 :            :     /// Specifically, this method returns \c Rcode::NOTAUTH() for the
     130                 :            :     /// TSIG specific errors, BADSIG, BADKEY, BADTIME, as described in
     131                 :            :     /// RFC2845.  For errors derived from the standard Rcode (code 0-15),
     132                 :            :     /// it returns the corresponding \c Rcode.  For others, this method
     133                 :            :     /// returns \c Rcode::SERVFAIL() as a last resort.
     134                 :            :     ///
     135                 :            :     /// \exception None
     136                 :            :     Rcode toRcode() const;
     137                 :            : 
     138                 :            :     /// A constant TSIG error object derived from \c Rcode::NOERROR()
     139                 :            :     static const TSIGError& NOERROR();
     140                 :            : 
     141                 :            :     /// A constant TSIG error object derived from \c Rcode::FORMERR()
     142                 :            :     static const TSIGError& FORMERR();
     143                 :            : 
     144                 :            :     /// A constant TSIG error object derived from \c Rcode::SERVFAIL()
     145                 :            :     static const TSIGError& SERVFAIL();
     146                 :            : 
     147                 :            :     /// A constant TSIG error object derived from \c Rcode::NXDOMAIN()
     148                 :            :     static const TSIGError& NXDOMAIN();
     149                 :            : 
     150                 :            :     /// A constant TSIG error object derived from \c Rcode::NOTIMP()
     151                 :            :     static const TSIGError& NOTIMP();
     152                 :            : 
     153                 :            :     /// A constant TSIG error object derived from \c Rcode::REFUSED()
     154                 :            :     static const TSIGError& REFUSED();
     155                 :            : 
     156                 :            :     /// A constant TSIG error object derived from \c Rcode::YXDOMAIN()
     157                 :            :     static const TSIGError& YXDOMAIN();
     158                 :            : 
     159                 :            :     /// A constant TSIG error object derived from \c Rcode::YXRRSET()
     160                 :            :     static const TSIGError& YXRRSET();
     161                 :            : 
     162                 :            :     /// A constant TSIG error object derived from \c Rcode::NXRRSET()
     163                 :            :     static const TSIGError& NXRRSET();
     164                 :            : 
     165                 :            :     /// A constant TSIG error object derived from \c Rcode::NOTAUTH()
     166                 :            :     static const TSIGError& NOTAUTH();
     167                 :            : 
     168                 :            :     /// A constant TSIG error object derived from \c Rcode::NOTZONE()
     169                 :            :     static const TSIGError& NOTZONE();
     170                 :            : 
     171                 :            :     /// A constant TSIG error object derived from \c Rcode::RESERVED11()
     172                 :            :     static const TSIGError& RESERVED11();
     173                 :            : 
     174                 :            :     /// A constant TSIG error object derived from \c Rcode::RESERVED12()
     175                 :            :     static const TSIGError& RESERVED12();
     176                 :            : 
     177                 :            :     /// A constant TSIG error object derived from \c Rcode::RESERVED13()
     178                 :            :     static const TSIGError& RESERVED13();
     179                 :            : 
     180                 :            :     /// A constant TSIG error object derived from \c Rcode::RESERVED14()
     181                 :            :     static const TSIGError& RESERVED14();
     182                 :            : 
     183                 :            :     /// A constant TSIG error object derived from \c Rcode::RESERVED15()
     184                 :            :     static const TSIGError& RESERVED15();
     185                 :            : 
     186                 :            :     /// A constant TSIG error object for the BADSIG code
     187                 :            :     /// (see \c TSIGError::BAD_SIG_CODE).
     188                 :            :     static const TSIGError& BAD_SIG();
     189                 :            : 
     190                 :            :     /// A constant TSIG error object for the BADKEY code
     191                 :            :     /// (see \c TSIGError::BAD_KEY_CODE).
     192                 :            :     static const TSIGError& BAD_KEY();
     193                 :            : 
     194                 :            :     /// A constant TSIG error object for the BADTIME code
     195                 :            :     /// (see \c TSIGError::BAD_TIME_CODE).
     196                 :            :     static const TSIGError& BAD_TIME();
     197                 :            : 
     198                 :            : private:
     199                 :            :     // This is internally used to specify the maximum possible RCODE value
     200                 :            :     // that can be convertible to TSIGErrors.
     201                 :            :     static const int MAX_RCODE_FOR_TSIGERROR = 15;
     202                 :            : 
     203                 :            :     uint16_t code_;
     204                 :            : };
     205                 :            : 
     206                 :            : inline const TSIGError&
     207                 :       1333 : TSIGError::NOERROR() {
     208 [ +  + ][ +  - ]:       1364 :     static TSIGError e(Rcode::NOERROR());
         [ +  - ][ +  - ]
     209                 :       1333 :     return (e);
     210                 :            : }
     211                 :            : 
     212                 :            : inline const TSIGError&
     213                 :         51 : TSIGError::FORMERR() {
     214 [ +  + ][ +  - ]:         81 :     static TSIGError e(Rcode::FORMERR());
                 [ +  - ]
     215                 :         51 :     return (e);
     216                 :            : }
     217                 :            : 
     218                 :            : inline const TSIGError&
     219                 :         29 : TSIGError::SERVFAIL() {
     220 [ +  - ][ +  - ]:         58 :     static TSIGError e(Rcode::SERVFAIL());
                 [ +  - ]
     221                 :         29 :     return (e);
     222                 :            : }
     223                 :            : 
     224                 :            : inline const TSIGError&
     225                 :         29 : TSIGError::NXDOMAIN() {
     226 [ +  - ][ +  - ]:         58 :     static TSIGError e(Rcode::NXDOMAIN());
                 [ +  - ]
     227                 :         29 :     return (e);
     228                 :            : }
     229                 :            : 
     230                 :            : inline const TSIGError&
     231                 :         29 : TSIGError::NOTIMP() {
     232 [ +  - ][ +  - ]:         58 :     static TSIGError e(Rcode::NOTIMP());
                 [ +  - ]
     233                 :         29 :     return (e);
     234                 :            : }
     235                 :            : 
     236                 :            : inline const TSIGError&
     237                 :         29 : TSIGError::REFUSED() {
     238 [ +  - ][ +  - ]:         58 :     static TSIGError e(Rcode::REFUSED());
                 [ +  - ]
     239                 :         29 :     return (e);
     240                 :            : }
     241                 :            : 
     242                 :            : inline const TSIGError&
     243                 :         29 : TSIGError::YXDOMAIN() {
     244 [ +  - ][ +  - ]:         58 :     static TSIGError e(Rcode::YXDOMAIN());
                 [ +  - ]
     245                 :         29 :     return (e);
     246                 :            : }
     247                 :            : 
     248                 :            : inline const TSIGError&
     249                 :         29 : TSIGError::YXRRSET() {
     250 [ +  - ][ +  - ]:         58 :     static TSIGError e(Rcode::YXRRSET());
                 [ +  - ]
     251                 :         29 :     return (e);
     252                 :            : }
     253                 :            : 
     254                 :            : inline const TSIGError&
     255                 :         29 : TSIGError::NXRRSET() {
     256 [ +  - ][ +  - ]:         58 :     static TSIGError e(Rcode::NXRRSET());
                 [ +  - ]
     257                 :         29 :     return (e);
     258                 :            : }
     259                 :            : 
     260                 :            : inline const TSIGError&
     261                 :         29 : TSIGError::NOTAUTH() {
     262 [ +  - ][ +  - ]:         59 :     static TSIGError e(Rcode::NOTAUTH());
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     263                 :         29 :     return (e);
     264                 :            : }
     265                 :            : 
     266                 :            : inline const TSIGError&
     267                 :         29 : TSIGError::NOTZONE() {
     268 [ +  - ][ +  - ]:         58 :     static TSIGError e(Rcode::NOTZONE());
                 [ +  - ]
     269                 :         29 :     return (e);
     270                 :            : }
     271                 :            : 
     272                 :            : inline const TSIGError&
     273                 :         29 : TSIGError::RESERVED11() {
     274 [ +  - ][ +  - ]:         58 :     static TSIGError e(Rcode::RESERVED11());
                 [ +  - ]
     275                 :         29 :     return (e);
     276                 :            : }
     277                 :            : 
     278                 :            : inline const TSIGError&
     279                 :         29 : TSIGError::RESERVED12() {
     280 [ +  - ][ +  - ]:         58 :     static TSIGError e(Rcode::RESERVED12());
                 [ +  - ]
     281                 :         29 :     return (e);
     282                 :            : }
     283                 :            : 
     284                 :            : inline const TSIGError&
     285                 :         29 : TSIGError::RESERVED13() {
     286 [ +  - ][ +  - ]:         58 :     static TSIGError e(Rcode::RESERVED13());
                 [ +  - ]
     287                 :         29 :     return (e);
     288                 :            : }
     289                 :            : 
     290                 :            : inline const TSIGError&
     291                 :         30 : TSIGError::RESERVED14() {
     292 [ +  - ][ +  - ]:         60 :     static TSIGError e(Rcode::RESERVED14());
                 [ +  - ]
     293                 :         30 :     return (e);
     294                 :            : }
     295                 :            : 
     296                 :            : inline const TSIGError&
     297                 :         29 : TSIGError::RESERVED15() {
     298 [ +  - ][ +  - ]:         58 :     static TSIGError e(Rcode::RESERVED15());
                 [ +  - ]
     299                 :         29 :     return (e);
     300                 :            : }
     301                 :            : 
     302                 :            : inline const TSIGError&
     303                 :        403 : TSIGError::BAD_SIG() {
     304 [ +  + ][ +  - ]:        432 :     static TSIGError e(BAD_SIG_CODE);
     305                 :        403 :     return (e);
     306                 :            : }
     307                 :            : 
     308                 :            : inline const TSIGError&
     309                 :        472 : TSIGError::BAD_KEY() {
     310 [ +  + ][ +  - ]:        502 :     static TSIGError e(BAD_KEY_CODE);
     311                 :        472 :     return (e);
     312                 :            : }
     313                 :            : 
     314                 :            : inline const TSIGError&
     315                 :        778 : TSIGError::BAD_TIME() {
     316 [ +  + ][ +  - ]:        807 :     static TSIGError e(BAD_TIME_CODE);
     317                 :        778 :     return (e);
     318                 :            : }
     319                 :            : 
     320                 :            : /// Insert the \c TSIGError as a string into stream.
     321                 :            : ///
     322                 :            : /// This method convert \c tsig_error into a string and inserts it into the
     323                 :            : /// output stream \c os.
     324                 :            : ///
     325                 :            : /// \param os A \c std::ostream object on which the insertion operation is
     326                 :            : /// performed.
     327                 :            : /// \param tsig_error An \c TSIGError object output by the operation.
     328                 :            : /// \return A reference to the same \c std::ostream object referenced by
     329                 :            : /// parameter \c os after the insertion operation.
     330                 :            : std::ostream& operator<<(std::ostream& os, const TSIGError& tsig_error);
     331                 :            : }
     332                 :            : }
     333                 :            : 
     334                 :            : #endif  // __TSIGERROR_H
     335                 :            : 
     336                 :            : // Local Variables:
     337                 :            : // mode: c++
     338                 :            : // End:

Generated by: LCOV version 1.9