#include <limits.h>
#include <stdio.h>
#include <map>
#include <string>
#include <vector>
#include <gtest/gtest.h>
#include <openssl/asn1.h>
#include <openssl/asn1t.h>
#include <openssl/bio.h>
#include <openssl/bytestring.h>
#include <openssl/err.h>
#include <openssl/mem.h>
#include <openssl/obj.h>
#include <openssl/pem.h>
#include <openssl/posix_time.h>
#include <openssl/span.h>
#include <openssl/x509.h>
#include "../test/test_util.h"
#include "internal.h"
#if defined(OPENSSL_THREADS)
#include <thread>
#endif
template <typename T, typename U>
void TestSerialize(T obj, int (*i2d_func)(U a, uint8_t **pp),
bssl::Span<const uint8_t> expected) { … }
TEST(ASN1Test, UnknownTags) { … }
static bssl::UniquePtr<BIGNUM> BIGNUMPow2(unsigned bit) { … }
TEST(ASN1Test, Integer) { … }
TEST(ASN1Test, NegativeZero) { … }
TEST(ASN1Test, SerializeObject) { … }
TEST(ASN1Test, Boolean) { … }
TEST(ASN1Test, SerializeEmbeddedBoolean) { … }
TEST(ASN1Test, ASN1Type) { … }
TEST(ASN1Test, UnusedBooleanBits) { … }
TEST(ASN1Test, ParseASN1Object) { … }
TEST(ASN1Test, BitString) { … }
TEST(ASN1Test, SetBit) { … }
TEST(ASN1Test, StringToUTF8) { … }
static std::string ASN1StringToStdString(const ASN1_STRING *str) { … }
static bool ASN1Time_check_posix(const ASN1_TIME *s, int64_t t) { … }
static std::string PrintStringToBIO(const ASN1_STRING *str,
int (*print_func)(BIO *,
const ASN1_STRING *)) { … }
TEST(ASN1Test, SetTime) { … }
TEST(ASN1Test, TimeSetString) { … }
TEST(ASN1Test, AdjTime) { … }
static std::vector<uint8_t> StringToVector(const std::string &str) { … }
TEST(ASN1Test, StringPrintEx) { … }
TEST(ASN1Test, MBString) { … }
TEST(ASN1Test, StringByNID) { … }
TEST(ASN1Test, StringByCustomNID) { … }
#if defined(OPENSSL_THREADS)
TEST(ASN1Test, StringByCustomNIDThreads) { … }
#endif
TEST(ASN1Test, NegativeEnumeratedMultistring) { … }
TEST(ASN1Test, InvalidChoice) { … }
TEST(ASN1Test, InvalidObject) { … }
TEST(ASN1Test, InvalidASN1Type) { … }
TEST(ASN1Test, InvalidMSTRING) { … }
TEST(ASN1Test, StringTableSorted) { … }
TEST(ASN1Test, Null) { … }
TEST(ASN1Test, Pack) { … }
TEST(ASN1Test, Unpack) { … }
TEST(ASN1Test, StringCmp) { … }
TEST(ASN1Test, PrintASN1Object) { … }
TEST(ASN1Test, GetObject) { … }
template <typename T>
void ExpectNoParse(T *(*d2i)(T **, const uint8_t **, long),
const std::vector<uint8_t> &in) { … }
TEST(ASN1Test, ZeroTag) { … }
TEST(ASN1Test, StringEncoding) { … }
TEST(ASN1Test, POSIXTime) { … }
TEST(ASN1Test, LargeString) { … }
static auto TimeToTuple(const tm &t) { … }
TEST(ASN1Test, TimeOverflow) { … }
#if !defined(OPENSSL_WINDOWS) || !defined(BORINGSSL_SHARED_LIBRARY)
ASN1_LINKED_LIST;
DECLARE_ASN1_ITEM(ASN1_LINKED_LIST)
DECLARE_ASN1_FUNCTIONS(ASN1_LINKED_LIST)
ASN1_SEQUENCE(ASN1_LINKED_LIST) = … ASN1_SEQUENCE_END(ASN1_LINKED_LIST)
IMPLEMENT_ASN1_FUNCTIONS(…)
static bool MakeLinkedList(bssl::UniquePtr<uint8_t> *out, size_t *out_len,
size_t count) { … }
TEST(ASN1Test, Recursive) { … }
struct IMPLICIT_CHOICE { … };
DECLARE_ASN1_FUNCTIONS(IMPLICIT_CHOICE)
ASN1_SEQUENCE(IMPLICIT_CHOICE) = … ASN1_SEQUENCE_END(IMPLICIT_CHOICE)
IMPLEMENT_ASN1_FUNCTIONS(…)
TEST(ASN1Test, ImplicitChoice) { … }
struct REQUIRED_FIELD { … };
DECLARE_ASN1_FUNCTIONS(REQUIRED_FIELD)
ASN1_SEQUENCE(REQUIRED_FIELD) = … ASN1_SEQUENCE_END(REQUIRED_FIELD)
IMPLEMENT_ASN1_FUNCTIONS(…)
TEST(ASN1Test, MissingRequiredField) { … }
struct BOOLEANS { … };
DECLARE_ASN1_FUNCTIONS(BOOLEANS)
ASN1_SEQUENCE(BOOLEANS) = … ASN1_SEQUENCE_END(BOOLEANS)
IMPLEMENT_ASN1_FUNCTIONS(…)
TEST(ASN1Test, OptionalAndDefaultBooleans) { … }
ASN1_ITEM_TEMPLATE(EXPLICIT_BOOLEAN) = …
ASN1_ITEM_TEMPLATE_END(EXPLICIT_BOOLEAN)
ASN1_ITEM_TEMPLATE(EXPLICIT_OCTET_STRING) = …
ASN1_ITEM_TEMPLATE_END(EXPLICIT_OCTET_STRING)
struct DOUBLY_TAGGED { … };
DECLARE_ASN1_FUNCTIONS(DOUBLY_TAGGED)
ASN1_SEQUENCE(DOUBLY_TAGGED) = … ASN1_SEQUENCE_END(DOUBLY_TAGGED)
IMPLEMENT_ASN1_FUNCTIONS(…)
TEST(ASN1Test, DoublyTagged) { … }
#define CHOICE_TYPE_OCT …
#define CHOICE_TYPE_BOOL …
struct CHOICE_TYPE { … };
DECLARE_ASN1_FUNCTIONS(CHOICE_TYPE)
ASN1_CHOICE(CHOICE_TYPE) = … ASN1_CHOICE_END(…)
IMPLEMENT_ASN1_FUNCTIONS(…)
struct OPTIONAL_CHOICE { … };
DECLARE_ASN1_FUNCTIONS(OPTIONAL_CHOICE)
ASN1_SEQUENCE(OPTIONAL_CHOICE) = … ASN1_SEQUENCE_END(OPTIONAL_CHOICE)
IMPLEMENT_ASN1_FUNCTIONS(…)
TEST(ASN1Test, OptionalChoice) { … }
struct EMBED_X509_ALGOR { … };
struct EMBED_X509_EXTENSION { … };
struct EMBED_X509_NAME { … };
struct EMBED_X509 { … };
DECLARE_ASN1_FUNCTIONS(EMBED_X509_ALGOR)
ASN1_SEQUENCE(EMBED_X509_ALGOR) = … ASN1_SEQUENCE_END(EMBED_X509_ALGOR)
IMPLEMENT_ASN1_FUNCTIONS(…)
DECLARE_ASN1_FUNCTIONS(EMBED_X509_NAME)
ASN1_SEQUENCE(EMBED_X509_NAME) = … ASN1_SEQUENCE_END(EMBED_X509_NAME)
IMPLEMENT_ASN1_FUNCTIONS(…)
DECLARE_ASN1_FUNCTIONS(EMBED_X509_EXTENSION)
ASN1_SEQUENCE(EMBED_X509_EXTENSION) = … ASN1_SEQUENCE_END(EMBED_X509_EXTENSION)
IMPLEMENT_ASN1_FUNCTIONS(…)
DECLARE_ASN1_FUNCTIONS(EMBED_X509)
ASN1_SEQUENCE(EMBED_X509) = … ASN1_SEQUENCE_END(EMBED_X509)
IMPLEMENT_ASN1_FUNCTIONS(…)
template <typename EmbedT, typename T, typename MaybeConstT, typename StackT>
void TestEmbedType(bssl::Span<const uint8_t> inp,
int (*i2d)(MaybeConstT *, uint8_t **),
EmbedT *(*embed_new)(), void (*embed_free)(EmbedT *),
EmbedT *(*d2i_embed)(EmbedT **, const uint8_t **, long),
int (*i2d_embed)(EmbedT *, uint8_t **),
size_t (*sk_num)(const StackT *),
T *(*sk_value)(const StackT *, size_t)) { … }
TEST(ASN1Test, EmbedTypes) { … }
#endif