chromium/net/third_party/quiche/src/quiche/quic/core/crypto/certificate_view.h

// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef QUICHE_QUIC_CORE_CRYPTO_CERTIFICATE_VIEW_H_
#define QUICHE_QUIC_CORE_CRYPTO_CERTIFICATE_VIEW_H_

#include <istream>
#include <memory>
#include <optional>
#include <vector>

#include "absl/strings/string_view.h"
#include "openssl/base.h"
#include "openssl/bytestring.h"
#include "openssl/evp.h"
#include "quiche/quic/core/crypto/boring_utils.h"
#include "quiche/quic/core/quic_time.h"
#include "quiche/quic/core/quic_types.h"
#include "quiche/quic/platform/api/quic_export.h"
#include "quiche/quic/platform/api/quic_ip_address.h"

namespace quic {

struct QUICHE_EXPORT PemReadResult {};

// Reads |input| line-by-line and returns the next available PEM message.
QUICHE_EXPORT PemReadResult ReadNextPemMessage(std::istream* input);

// Cryptograhpic algorithms recognized in X.509.
enum class PublicKeyType {};
QUICHE_EXPORT std::string PublicKeyTypeToString(PublicKeyType type);
QUICHE_EXPORT PublicKeyType
PublicKeyTypeFromSignatureAlgorithm(uint16_t signature_algorithm);

// Returns the list of the signature algorithms that can be processed by
// CertificateView::VerifySignature() and CertificatePrivateKey::Sign().
QUICHE_EXPORT QuicSignatureAlgorithmVector
SupportedSignatureAlgorithmsForQuic();

// CertificateView represents a parsed version of a single X.509 certificate. As
// the word "view" implies, it does not take ownership of the underlying strings
// and consists primarily of pointers into the certificate that is passed into
// the parser.
class QUICHE_EXPORT CertificateView {};

// CertificatePrivateKey represents a private key that can be used with an X.509
// certificate.
class QUICHE_EXPORT CertificatePrivateKey {};

// Parses a DER-encoded X.509 NameAttribute.  Exposed primarily for testing.
QUICHE_EXPORT std::optional<std::string> X509NameAttributeToString(CBS input);

// Parses a DER time based on the specified ASN.1 tag.  Exposed primarily for
// testing.
QUICHE_EXPORT std::optional<quic::QuicWallTime> ParseDerTime(
    unsigned tag, absl::string_view payload);

}  // namespace quic

#endif  // QUICHE_QUIC_CORE_CRYPTO_CERTIFICATE_VIEW_H_