/*
 * Copyright (c) 2018-2020 Not for Radio, LLC
 *
 * See the file LICENSE in this distribution.
 *
 */
/* vim: set ts=4 sw=4 et: */
#ifndef HEADER_ETS_CRYPTO_H
# define HEADER_ETS_CRYPTO_H

# include <openssl/evp.h>
# include <openssl/safestack.h>

/*
 * Interfaces and parameters for OpenSSL ETS crypto/key APIs.
 */

#define ETS_FINGERPRINT_BITS    (80)

/*
 * These data structures define the ETS Visibility Information structures for
 * OpenSSL's ASN.1 interfaces.
 */
typedef struct ETSvisibilityInformation_st {
    ASN1_OCTET_STRING *fingerprint;
    ASN1_UTF8STRING *accessDescription;
} ETS_VISIBILITY_INFORMATION;

DECLARE_ASN1_FUNCTIONS(ETS_VISIBILITY_INFORMATION)

int i2a_ETS_VISIBILITY_INFORMATION(BIO *, const ETS_VISIBILITY_INFORMATION *);
int i2t_ETS_VISIBILITY_INFORMATION(char *, int, const ETS_VISIBILITY_INFORMATION *);

/*
 * This is the internal data structure used to organize and track sets of
 * static keys and to cache ETS-related metadata (currently only the
 * fingerprint) associated with them.
 */
struct ETS_PKEY_st {
    EVP_PKEY *pkey;
    unsigned char fingerprint[ETS_FINGERPRINT_BITS / 8];
};
typedef struct ETS_PKEY_st ETS_PKEY;

DEFINE_STACK_OF(ETS_PKEY)

typedef STACK_OF(ETS_PKEY) ETS_PKEYS;

ETS_PKEYS *ETS_PKEYS_new_null(void);
void ETS_PKEYS_free(ETS_PKEYS *);

EVP_PKEY *ETS_find_key(ETS_PKEYS *, const unsigned char *, size_t);

int ETS_fingerprint_pkey(EVP_PKEY *, unsigned char *, size_t);

int ETS_load_keys(const char *, ETS_PKEYS **);

#endif /* !HEADER_ETS_CRYPTO_H */

/* Local Variables:       */
/* c-basic-offset: 4      */
/* tab-width: 4           */
/* indent-tabs-mode: nil  */
/* End:                   */
