2015-07-23 03:36:57 +01:00
|
|
|
/* Copyright (c) 2015, Google Inc.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
|
|
|
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
|
|
|
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
|
|
|
|
|
|
|
#ifndef OPENSSL_HEADER_CRYPTO_TEST_TEST_UTIL_H
|
|
|
|
#define OPENSSL_HEADER_CRYPTO_TEST_TEST_UTIL_H
|
|
|
|
|
|
|
|
#include <stddef.h>
|
2017-02-04 16:48:59 +00:00
|
|
|
#include <stdint.h>
|
2015-07-23 03:36:57 +01:00
|
|
|
#include <stdio.h>
|
2017-02-05 07:52:55 +00:00
|
|
|
#include <string.h>
|
2015-07-23 03:36:57 +01:00
|
|
|
|
2017-02-04 16:48:59 +00:00
|
|
|
#include <iosfwd>
|
2017-04-17 15:04:39 +01:00
|
|
|
#include <string>
|
2017-05-19 20:26:18 +01:00
|
|
|
#include <vector>
|
2015-07-23 03:36:57 +01:00
|
|
|
|
2018-08-15 03:11:18 +01:00
|
|
|
#include <openssl/span.h>
|
|
|
|
|
2017-02-04 16:48:59 +00:00
|
|
|
#include "../internal.h"
|
2015-07-23 03:36:57 +01:00
|
|
|
|
2017-02-04 16:48:59 +00:00
|
|
|
|
|
|
|
// hexdump writes |msg| to |fp| followed by the hex encoding of |len| bytes
|
|
|
|
// from |in|.
|
2015-07-23 03:36:57 +01:00
|
|
|
void hexdump(FILE *fp, const char *msg, const void *in, size_t len);
|
|
|
|
|
2017-02-04 16:48:59 +00:00
|
|
|
// Bytes is a wrapper over a byte slice which may be compared for equality. This
|
|
|
|
// allows it to be used in EXPECT_EQ macros.
|
|
|
|
struct Bytes {
|
|
|
|
Bytes(const uint8_t *data_arg, size_t len_arg)
|
2018-08-15 03:11:18 +01:00
|
|
|
: span_(data_arg, len_arg) {}
|
2017-03-09 06:13:07 +00:00
|
|
|
Bytes(const char *data_arg, size_t len_arg)
|
2018-08-15 03:11:18 +01:00
|
|
|
: span_(reinterpret_cast<const uint8_t *>(data_arg), len_arg) {}
|
2017-02-04 16:48:59 +00:00
|
|
|
|
2017-04-17 15:04:39 +01:00
|
|
|
explicit Bytes(const char *str)
|
2018-08-15 03:11:18 +01:00
|
|
|
: span_(reinterpret_cast<const uint8_t *>(str), strlen(str)) {}
|
2017-04-17 15:04:39 +01:00
|
|
|
explicit Bytes(const std::string &str)
|
2018-08-15 03:11:18 +01:00
|
|
|
: span_(reinterpret_cast<const uint8_t *>(str.data()), str.size()) {}
|
|
|
|
explicit Bytes(bssl::Span<const uint8_t> span)
|
|
|
|
: span_(span) {}
|
2017-02-04 16:48:59 +00:00
|
|
|
|
2018-08-15 03:11:18 +01:00
|
|
|
bssl::Span<const uint8_t> span_;
|
2017-02-04 16:48:59 +00:00
|
|
|
};
|
2015-07-23 03:36:57 +01:00
|
|
|
|
2017-02-04 16:48:59 +00:00
|
|
|
inline bool operator==(const Bytes &a, const Bytes &b) {
|
2018-08-15 03:11:18 +01:00
|
|
|
return a.span_ == b.span_;
|
2015-07-23 03:36:57 +01:00
|
|
|
}
|
2017-02-04 16:48:59 +00:00
|
|
|
|
|
|
|
inline bool operator!=(const Bytes &a, const Bytes &b) { return !(a == b); }
|
|
|
|
|
|
|
|
std::ostream &operator<<(std::ostream &os, const Bytes &in);
|
|
|
|
|
2015-07-23 03:36:57 +01:00
|
|
|
|
2017-08-18 19:06:02 +01:00
|
|
|
#endif // OPENSSL_HEADER_CRYPTO_TEST_TEST_UTIL_H
|