nsec_bitmap.h 4.0 KB

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