#ifndef OPENSSL_HEADER_CRYPTO_TEST_TEST_UTIL_H
#define OPENSSL_HEADER_CRYPTO_TEST_TEST_UTIL_H
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <iosfwd>
#include <string>
#include <vector>
#include <openssl/span.h>
#include "../internal.h"
void hexdump(FILE *fp, const char *msg, const void *in, size_t len);
struct Bytes {
Bytes(const uint8_t *data_arg, size_t len_arg) : span_(data_arg, len_arg) {}
Bytes(const char *data_arg, size_t len_arg)
: span_(reinterpret_cast<const uint8_t *>(data_arg), len_arg) {}
explicit Bytes(const char *str)
: span_(reinterpret_cast<const uint8_t *>(str), strlen(str)) {}
explicit Bytes(const std::string &str)
: span_(reinterpret_cast<const uint8_t *>(str.data()), str.size()) {}
explicit Bytes(bssl::Span<const uint8_t> span) : span_(span) {}
bssl::Span<const uint8_t> span_;
};
inline bool operator==(const Bytes &a, const Bytes &b) {
return a.span_ == b.span_;
}
inline bool operator!=(const Bytes &a, const Bytes &b) { return !(a == b); }
std::ostream &operator<<(std::ostream &os, const Bytes &in);
bool DecodeHex(std::vector<uint8_t> *out, const std::string &in);
std::vector<uint8_t> HexToBytes(const char *str);
std::string EncodeHex(bssl::Span<const uint8_t> in);
bssl::UniquePtr<X509> CertFromPEM(const char *pem);
bssl::UniquePtr<STACK_OF(X509)> CertsToStack(const std::vector<X509 *> &certs);
bssl::UniquePtr<RSA> RSAFromPEM(const char *pem);
struct TempFileCloser {
void operator()(FILE *f) const { fclose(f); }
};
using TempFILE = std::unique_ptr<FILE, TempFileCloser>;
#if defined(OPENSSL_WINDOWS)
#include <windows.h>
#ifndef PATH_MAX
#define PATH_MAX MAX_PATH
#endif
#else
#include <limits.h>
#endif
size_t createTempFILEpath(char buffer[PATH_MAX]);
FILE* createRawTempFILE();
TempFILE createTempFILE();
typedef struct {
int custom_data;
} CustomData;
void CustomDataFree(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
int index, long argl, void *argp);
#endif