moonbitstack/moontls/alert does not have a README file

    Alert

    pub(all) suberror Alert {
    Alert(level~ : Level, kind~ : Kind)
    } derive(Eq,
    Debug
    )

    An alert (RFC 8446 §6).

    It is also the error a handshake raises, so one value carries both the reason a caller branches on and the two octets to put on the wire.

    Alert::equal

    fn Alert::equal(Alert, Alert) -> Bool

    Alert::not_equal

    fn Alert::not_equal(x : Alert, y : Alert) -> Bool

    Alert::to_repr

    Kind

    pub(all) enum Kind {
    CloseNotify
    UnexpectedMessage
    BadRecordMac
    RecordOverflow
    HandshakeFailure
    BadCertificate
    UnsupportedCertificate
    CertificateRevoked
    CertificateExpired
    CertificateUnknown
    IllegalParameter
    UnknownCa
    AccessDenied
    DecodeError
    DecryptError
    ProtocolVersion
    InsufficientSecurity
    InternalError
    InappropriateFallback
    UserCanceled
    MissingExtension
    UnsupportedExtension
    UnrecognizedName
    BadCertificateStatusResponse
    UnknownPskIdentity
    CertificateRequired
    NoApplicationProtocol
    Other(Int)
    } derive(Eq,
    Debug
    )

    What an endpoint says went wrong (RFC 8446 §6.1, §6.2).

    The description is the only diagnostic a peer ever receives, so it is what makes a failed handshake readable from the other end — a connection that simply goes away tells the client nothing.

    Other carries a code the RFC does not assign. An unrecognised description still arrives, and dropping the number would lose the only thing it said.

    Kind::code

    fn Kind::code(self : Kind) -> Int

    The octet this description goes on the wire as.

    Kind::equal

    fn Kind::equal(Kind, Kind) -> Bool

    Kind::is_fatal

    fn Kind::is_fatal(self : Kind) -> Bool

    Whether this description ends the connection (RFC 8446 §6.1).

    Everything but CloseNotify and UserCanceled, whatever level the sender put on it — the level is advisory and the description is not.

    Kind::not_equal

    fn Kind::not_equal(x : Kind, y : Kind) -> Bool

    Kind::of

    fn Kind::of(code : Int) -> Kind

    The description an octet names. Never fails: one the RFC does not assign becomes Other.

    Kind::to_repr

    Level

    pub(all) enum Level {
    Warning
    Fatal
    } derive(Eq,
    Debug
    )

    An alert's level (RFC 8446 §6).

    TLS 1.3 acts on the description rather than the level: only CloseNotify and UserCanceled leave a connection usable, whichever level carries them. The level is still on the wire, so it is still read and written.

    Level::code

    fn Level::code(self : Level) -> Int

    The octet this level goes on the wire as.

    Level::equal

    fn Level::equal(Level, Level) -> Bool

    Level::not_equal

    fn Level::not_equal(x : Level, y : Level) -> Bool

    Level::of

    fn Level::of(code : Int) -> Level?

    The level an octet names, or None for one RFC 8446 does not assign.

    Level::to_repr

    decode

    fn decode(view : BytesView) -> Alert?

    Read an alert back off the wire, or None if fewer than two octets are there.

    A level the RFC does not assign is refused rather than guessed at; an unassigned description is carried through as [Kind::Other], because the description is the diagnostic and losing it loses the message.

    encode

    fn encode(alert : Alert) -> Bytes

    The two octets an alert goes on the wire as (RFC 8446 §6).

    fatal

    fn fatal(kind : Kind) -> Alert

    A fatal alert carrying kind — every way a TLS 1.3 handshake can fail.

    warning

    fn warning(kind : Kind) -> Alert

    A warning alert carrying kind: CloseNotify and UserCanceled, the two a peer may act on without tearing the connection down.

    Source Files