You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

63 lines
2.2 KiB

  1. /* Copyright (c) 2015, Google Inc.
  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 THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  10. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  12. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  13. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
  14. #ifndef OPENSSL_HEADER_CRYPTO_TEST_TEST_UTIL_H
  15. #define OPENSSL_HEADER_CRYPTO_TEST_TEST_UTIL_H
  16. #include <stddef.h>
  17. #include <stdint.h>
  18. #include <stdio.h>
  19. #include <string.h>
  20. #include <iosfwd>
  21. #include <string>
  22. #include "../internal.h"
  23. // hexdump writes |msg| to |fp| followed by the hex encoding of |len| bytes
  24. // from |in|.
  25. void hexdump(FILE *fp, const char *msg, const void *in, size_t len);
  26. // Bytes is a wrapper over a byte slice which may be compared for equality. This
  27. // allows it to be used in EXPECT_EQ macros.
  28. struct Bytes {
  29. Bytes(const uint8_t *data_arg, size_t len_arg)
  30. : data(data_arg), len(len_arg) {}
  31. Bytes(const char *data_arg, size_t len_arg)
  32. : data(reinterpret_cast<const uint8_t *>(data_arg)), len(len_arg) {}
  33. explicit Bytes(const char *str)
  34. : data(reinterpret_cast<const uint8_t *>(str)), len(strlen(str)) {}
  35. explicit Bytes(const std::string &str)
  36. : data(reinterpret_cast<const uint8_t *>(str.data())), len(str.size()) {}
  37. template <size_t N>
  38. explicit Bytes(const uint8_t (&array)[N]) : data(array), len(N) {}
  39. const uint8_t *data;
  40. size_t len;
  41. };
  42. inline bool operator==(const Bytes &a, const Bytes &b) {
  43. return a.len == b.len && OPENSSL_memcmp(a.data, b.data, a.len) == 0;
  44. }
  45. inline bool operator!=(const Bytes &a, const Bytes &b) { return !(a == b); }
  46. std::ostream &operator<<(std::ostream &os, const Bytes &in);
  47. #endif /* OPENSSL_HEADER_CRYPTO_TEST_TEST_UTIL_H */