hex.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright (C) 2009 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. // $Id$
  15. #ifndef __HEX_H
  16. #define __HEX_H 1
  17. #include <string>
  18. #include <vector>
  19. #include <exceptions/exceptions.h>
  20. //
  21. // Note: this helper module isn't specific to the DNS protocol per se.
  22. // We should probably move this to somewhere else, possibly in some common
  23. // utility area.
  24. //
  25. namespace isc {
  26. namespace dns {
  27. ///
  28. /// \brief A standard DNS (or ISC) module exception that is thrown if a hex
  29. /// decoder encounters an invalid input.
  30. ///
  31. class BadHexString : public Exception {
  32. public:
  33. BadHexString(const char* file, size_t line, const char* what) :
  34. isc::Exception(file, line, what) {}
  35. };
  36. std::string encodeHex(const std::vector<uint8_t>& binary);
  37. void decodeHex(const std::string& hex, std::vector<uint8_t>& result);
  38. }
  39. }
  40. #endif // __HEX_H
  41. // Local Variables:
  42. // mode: c++
  43. // End: