chromium/net/third_party/quiche/src/quiche/quic/core/quic_error_codes.h

// Copyright (c) 2012 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_QUIC_ERROR_CODES_H_
#define QUICHE_QUIC_CORE_QUIC_ERROR_CODES_H_

#include <cstdint>
#include <limits>
#include <string>

#include "quiche/quic/platform/api/quic_export.h"

namespace quic {

// QuicRstStreamErrorCode is encoded as a single octet on-the-wire in IETF QUIC
// and a 32-bit integer in gQUIC.
enum QuicRstStreamErrorCode : uint32_t {};
// QuicRstStreamErrorCode is encoded as a single octet on-the-wire.
static_assert;

// These values must remain stable as they are uploaded to UMA histograms.
// To add a new error code, use the current value of QUIC_LAST_ERROR and
// increment QUIC_LAST_ERROR.
enum QuicErrorCode : uint32_t {};
// QuicErrorCodes is encoded as four octets on-the-wire when doing Google QUIC,
// or a varint62 when doing IETF QUIC. Ensure that its value does not exceed
// the smaller of the two limits.
static_assert;

// Wire values for HTTP/3 errors.
// https://www.rfc-editor.org/rfc/rfc9114.html#http-error-codes
enum class QuicHttp3ErrorCode {};

// Wire values for QPACK errors.
// https://www.rfc-editor.org/rfc/rfc9204.html#error-code-registration
enum class QuicHttpQpackErrorCode {};

// Represents a reason for resetting a stream in both gQUIC and IETF error code
// space.  Both error codes have to be present.
class QUICHE_EXPORT QuicResetStreamError {};

// Convert TLS alert code to QuicErrorCode.
QUICHE_EXPORT QuicErrorCode TlsAlertToQuicErrorCode(uint8_t desc);

// Returns the name of the QuicRstStreamErrorCode as a char*
QUICHE_EXPORT const char* QuicRstStreamErrorCodeToString(
    QuicRstStreamErrorCode error);

// Returns the name of the QuicErrorCode as a char*
QUICHE_EXPORT const char* QuicErrorCodeToString(QuicErrorCode error);

// Wire values for QUIC transport errors.
// https://quicwg.org/base-drafts/draft-ietf-quic-transport.html#name-transport-error-codes
enum QuicIetfTransportErrorCodes : uint64_t {};

QUICHE_EXPORT std::string QuicIetfTransportErrorCodeString(
    QuicIetfTransportErrorCodes c);

QUICHE_EXPORT std::ostream& operator<<(std::ostream& os,
                                       const QuicIetfTransportErrorCodes& c);

// A transport error code (if is_transport_close is true) or application error
// code (if is_transport_close is false) to be used in CONNECTION_CLOSE frames.
struct QUICHE_EXPORT QuicErrorCodeToIetfMapping {};

// Convert QuicErrorCode to transport or application IETF error code
// to be used in CONNECTION_CLOSE frames.
QUICHE_EXPORT QuicErrorCodeToIetfMapping
QuicErrorCodeToTransportErrorCode(QuicErrorCode error);

// Convert a QuicRstStreamErrorCode to an application error code to be used in
// an IETF QUIC RESET_STREAM frame
QUICHE_EXPORT uint64_t RstStreamErrorCodeToIetfResetStreamErrorCode(
    QuicRstStreamErrorCode rst_stream_error_code);

// Convert the application error code of an IETF QUIC RESET_STREAM frame
// to QuicRstStreamErrorCode.
QUICHE_EXPORT QuicRstStreamErrorCode
IetfResetStreamErrorCodeToRstStreamErrorCode(uint64_t ietf_error_code);

QUICHE_EXPORT inline std::string HistogramEnumString(QuicErrorCode enum_value) {}

QUICHE_EXPORT inline std::string HistogramEnumDescription(
    QuicErrorCode /*dummy*/) {}

}  // namespace quic

#endif  // QUICHE_QUIC_CORE_QUIC_ERROR_CODES_H_