#ifndef UTIL_CRYPTO_CERTIFICATE_UTILS_H_
#define UTIL_CRYPTO_CERTIFICATE_UTILS_H_
#include <openssl/evp.h>
#include <openssl/x509.h>
#include <stdint.h>
#include <chrono>
#include <string>
#include <string_view>
#include <vector>
#include "platform/api/time.h"
#include "platform/base/error.h"
#include "util/crypto/rsa_private_key.h"
namespace openscreen {
bssl::UniquePtr<EVP_PKEY> GenerateRsaKeyPair(int key_bits = 2048);
ErrorOr<bssl::UniquePtr<X509>> CreateSelfSignedX509Certificate(
std::string_view name,
std::chrono::seconds duration,
const EVP_PKEY& key_pair,
std::chrono::seconds time_since_unix_epoch = GetWallTimeSinceUnixEpoch(),
bool make_ca = false,
X509* issuer = nullptr,
EVP_PKEY* issuer_key = nullptr);
ErrorOr<std::vector<uint8_t>> ExportX509CertificateToDer(
const X509& certificate);
ErrorOr<bssl::UniquePtr<X509>> ImportCertificate(const uint8_t* der_x509_cert,
int der_x509_cert_length);
ErrorOr<bssl::UniquePtr<EVP_PKEY>> ImportRSAPrivateKey(
const uint8_t* der_rsa_private_key,
int key_length);
std::string GetSpkiTlv(X509* cert);
ErrorOr<uint64_t> ParseDerUint64(const ASN1_INTEGER* asn1int);
}
#endif