Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

64 linhas
2.1 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 <vector>
  23. #include <openssl/span.h>
  24. #include "../internal.h"
  25. // hexdump writes |msg| to |fp| followed by the hex encoding of |len| bytes
  26. // from |in|.
  27. void hexdump(FILE *fp, const char *msg, const void *in, size_t len);
  28. // Bytes is a wrapper over a byte slice which may be compared for equality. This
  29. // allows it to be used in EXPECT_EQ macros.
  30. struct Bytes {
  31. Bytes(const uint8_t *data_arg, size_t len_arg)
  32. : span_(data_arg, len_arg) {}
  33. Bytes(const char *data_arg, size_t len_arg)
  34. : span_(reinterpret_cast<const uint8_t *>(data_arg), len_arg) {}
  35. explicit Bytes(const char *str)
  36. : span_(reinterpret_cast<const uint8_t *>(str), strlen(str)) {}
  37. explicit Bytes(const std::string &str)
  38. : span_(reinterpret_cast<const uint8_t *>(str.data()), str.size()) {}
  39. explicit Bytes(bssl::Span<const uint8_t> span)
  40. : span_(span) {}
  41. bssl::Span<const uint8_t> span_;
  42. };
  43. inline bool operator==(const Bytes &a, const Bytes &b) {
  44. return a.span_ == b.span_;
  45. }
  46. inline bool operator!=(const Bytes &a, const Bytes &b) { return !(a == b); }
  47. std::ostream &operator<<(std::ostream &os, const Bytes &in);
  48. #endif // OPENSSL_HEADER_CRYPTO_TEST_TEST_UTIL_H