nsec_bitmap.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. #ifndef __NSECBITMAP_H
  15. #define __NSECBITMAP_H 1
  16. #include <stdint.h>
  17. #include <sstream>
  18. #include <vector>
  19. namespace isc {
  20. namespace dns {
  21. namespace rdata {
  22. namespace generic {
  23. namespace detail {
  24. namespace nsec {
  25. /// \file
  26. ///
  27. /// This helper module provides some utilities that handle NSEC and NSEC3
  28. /// type bitmaps. The format and processing of the type bitmaps are generally
  29. /// the same for these two RRs, so it would make sense to consolidate
  30. /// the processing logic into a single implementation module.
  31. ///
  32. /// The functions defined here are essentially private and are only expected
  33. /// to be called from the \c NSEC and \c NSEC3 class implementations.
  34. /// \brief Check if a given "type bitmap" for NSEC/NSEC3 is valid.
  35. ///
  36. /// This function checks given wire format data (stored in a
  37. /// \c std::vector) is a valid type bitmaps used for the NSEC and NSEC3 RRs
  38. /// according to RFC4034 and RFC5155.
  39. ///
  40. /// \exception DNSMessageFORMERR The bitmap is not valid.
  41. ///
  42. /// \param rrtype_name Either "NSEC" or "NSEC3"; used as part of exception
  43. /// messages.
  44. /// \param typebits The type bitmaps in wire format. The size of vector
  45. /// is the total length of the bitmaps.
  46. void checkRRTypeBitmaps(const char* const rrtype_name,
  47. const std::vector<uint8_t>& typebits);
  48. /// \brief Convert textual sequence of RR types into type bitmaps.
  49. ///
  50. /// This function extracts a sequence of strings, converts each sequence
  51. /// into an RR type, and builds NSEC/NSEC3 type bitmaps with the corresponding
  52. /// bits for the extracted types being on. The resulting bitmaps (which are
  53. /// in the wire format according to RFC4034 and RFC5155) are stored in the
  54. /// given vector. This function expects the given string stream ends with
  55. /// the sequence.
  56. ///
  57. /// \exception InvalidRdataText The given input stream does not meet the
  58. /// assumption (e.g. including invalid form of RR type, not ending with
  59. /// an RR type string).
  60. ///
  61. /// \param rrtype_name Either "NSEC" or "NSEC3"; used as part of exception
  62. /// messages.
  63. /// \param iss Input stream that consists of a complete sequence of textual
  64. /// RR types for which the corresponding bits are set.
  65. /// \param typebits A placeholder for the resulting bitmaps. Expected to be
  66. /// empty, but it's not checked.
  67. void buildBitmapsFromText(const char* const rrtype_name,
  68. std::istringstream& iss,
  69. std::vector<uint8_t>& typebits);
  70. /// \brief Convert type bitmaps to textual sequence of RR types.
  71. ///
  72. /// This function converts wire-format data of type bitmaps for NSEC/NSEC3
  73. /// into a sequence of corresponding RR type strings, and inserts them
  74. /// into the given output stream with separating them by a single space
  75. /// character.
  76. ///
  77. /// This function assumes the given bitmaps are valid in terms of RFC4034
  78. /// and RFC5155 (in practice, it assumes it's from a validly constructed
  79. /// NSEC or NSEC3 object); if it detects a format error, it aborts the
  80. /// program with assert().
  81. ///
  82. /// \param typebits The type bitmaps in wire format. The size of vector
  83. /// is the total length of the bitmaps.
  84. /// \param oss The output stream to which the converted RR type sequence
  85. /// are to be inserted.
  86. void bitmapsToText(const std::vector<uint8_t>& typebits,
  87. std::ostringstream& oss);
  88. }
  89. }
  90. }
  91. }
  92. }
  93. }
  94. #endif // __NSECBITMAP_H
  95. // Local Variables:
  96. // mode: c++
  97. // End: