nsec3param_common.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // Copyright (C) 2012 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 NSEC3PARAM_COMMON_H
  15. #define NSEC3PARAM_COMMON_H 1
  16. #include <dns/master_lexer.h>
  17. #include <util/buffer.h>
  18. #include <stdint.h>
  19. #include <vector>
  20. namespace isc {
  21. namespace dns {
  22. namespace rdata {
  23. namespace generic {
  24. namespace detail {
  25. namespace nsec3 {
  26. /// \file
  27. ///
  28. /// This helper module provides some utilities that handle NSEC3 and
  29. /// NSEC3PARAM RDATA. They share the first few fields, and some operations
  30. /// on these fields are sufficiently complicated, so it would make sense to
  31. /// consolidate the processing logic into a single implementation module.
  32. ///
  33. /// The functions defined here are essentially private and are only expected
  34. /// to be called from the \c NSEC3 and \c NSEC3PARAM class implementations.
  35. /// \brief Result values of the utilities.
  36. ///
  37. /// This structure encapsulates a tuple of NSEC3/NSEC3PARAM algorithm,
  38. /// flags and iterations field values. This is used as the return value
  39. /// of the utility functions defined in this module so the caller can
  40. /// use it for constructing the corresponding RDATA.
  41. struct ParseNSEC3ParamResult {
  42. ParseNSEC3ParamResult(uint8_t param_algorithm, uint8_t param_flags,
  43. uint16_t param_iterations) :
  44. algorithm(param_algorithm), flags(param_flags),
  45. iterations(param_iterations)
  46. {}
  47. const uint8_t algorithm;
  48. const uint8_t flags;
  49. const uint16_t iterations;
  50. };
  51. /// \brief Convert textual representation of NSEC3 parameters.
  52. ///
  53. /// This function takes an input MasterLexer that points at a complete
  54. /// textual representation of an NSEC3 or NSEC3PARAM RDATA and parses it
  55. /// extracting the hash algorithm, flags, iterations, and salt fields.
  56. ///
  57. /// The first three fields are returned as the return value of this function.
  58. /// The salt will be stored in the given vector. The vector is expected
  59. /// to be empty, but if not, the existing content will be overridden.
  60. ///
  61. /// On successful return the given MasterLexer will reach the end of the
  62. /// salt field.
  63. ///
  64. /// \exception isc::BadValue The salt is not a valid hex string.
  65. /// \exception InvalidRdataText The given RDATA is otherwise invalid for
  66. /// NSEC3 or NSEC3PARAM fields.
  67. /// \exception MasterLexer::LexerError There was a syntax error reading
  68. /// a field from the MasterLexer.
  69. ///
  70. /// \param rrtype_name Either "NSEC3" or "NSEC3PARAM"; used as part of
  71. /// exception messages.
  72. /// \param lexer The MasterLexer to read NSEC3 parameter fields from.
  73. /// \param salt A placeholder for the salt field value of the RDATA.
  74. /// Expected to be empty, but it's not checked (and will be overridden).
  75. ///
  76. /// \return The hash algorithm, flags, iterations in the form of
  77. /// ParseNSEC3ParamResult.
  78. ParseNSEC3ParamResult parseNSEC3ParamFromLexer(const char* const rrtype_name,
  79. isc::dns::MasterLexer& lexer,
  80. std::vector<uint8_t>& salt);
  81. /// \brief Extract NSEC3 parameters from wire-format data.
  82. ///
  83. /// This function takes an input buffer that stores wire-format NSEC3 or
  84. /// NSEC3PARAM RDATA and parses it extracting the hash algorithm, flags,
  85. /// iterations, and salt fields.
  86. ///
  87. /// The first three fields are returned as the return value of this function.
  88. /// The salt will be stored in the given vector. The vector is expected
  89. /// to be empty, but if not, the existing content will be overridden.
  90. ///
  91. /// On successful return the input buffer will point to the end of the
  92. /// salt field; rdata_len will be the length of the rest of RDATA
  93. /// (in the case of a valid NSEC3PARAM, it should be 0).
  94. ///
  95. /// \exception DNSMessageFORMERR The wire data is invalid.
  96. ///
  97. /// \param rrtype_name Either "NSEC3" or "NSEC3PARAM"; used as part of
  98. /// exception messages.
  99. /// \param buffer An input buffer that stores wire-format RDATA. It must
  100. /// point to the beginning of the data.
  101. /// \param rdata_len The total length of the RDATA.
  102. /// \param salt A placeholder for the salt field value of the RDATA.
  103. /// Expected to be empty, but it's not checked (and will be overridden).
  104. ///
  105. /// \return The hash algorithm, flags, iterations in the form of
  106. /// ParseNSEC3ParamResult.
  107. ParseNSEC3ParamResult parseNSEC3ParamWire(const char* const rrtype_name,
  108. isc::util::InputBuffer& buffer,
  109. size_t& rdata_len,
  110. std::vector<uint8_t>& salt);
  111. }
  112. }
  113. }
  114. }
  115. }
  116. }
  117. #endif // NSEC3PARAM_COMMON_H
  118. // Local Variables:
  119. // mode: c++
  120. // End: