#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum TlsVersion {
Tls10,
Tls11,
Tls12,
Tls13,
Dtls12,
Dtls13,
}
impl TlsVersion {
#[must_use]
pub fn uses_tls13_handshake_semantics(self) -> bool {
matches!(self, Self::Tls13 | Self::Dtls13)
}
#[must_use]
pub fn is_dtls(self) -> bool {
matches!(self, Self::Dtls12 | Self::Dtls13)
}
}
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum TlsRole {
Client,
Server,
}
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum HandshakeState {
Idle,
ClientHelloReceived,
ServerHelloSent,
ClientHelloSent,
ServerHelloReceived,
ServerEncryptedExtensionsReceived,
ServerCertificateRequestReceived,
ServerCertificateReceived,
ServerCertificateVerified,
KeysDerived,
Finished,
}
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum CipherSuite {
TlsAes128GcmSha256,
TlsAes256GcmSha384,
TlsChacha20Poly1305Sha256,
TlsEcdheRsaWithAes128GcmSha256,
TlsEcdheRsaWithAes256GcmSha384,
TlsEcdheRsaWithAes128CbcSha,
TlsEcdheRsaWithChacha20Poly1305Sha256,
TlsRsaWithAes128CbcSha,
TlsEcdheEcdsaWithAes128GcmSha256,
TlsEcdheEcdsaWithAes256GcmSha384,
TlsEcdheEcdsaWithChacha20Poly1305Sha256,
TlsDheRsaWithChacha20Poly1305Sha256,
TlsDheRsaWithAes128GcmSha256,
TlsDheRsaWithAes256GcmSha384,
TlsRsaWithAes128GcmSha256,
TlsRsaWithAes256GcmSha384,
TlsEcdheEcdsaWithAes128CcmSha256,
TlsEcdheEcdsaWithAes256CcmSha256,
TlsEcdheEcdsaWithAes128Ccm8Sha256,
TlsEcdheEcdsaWithAes256Ccm8Sha256,
TlsRsaWithAes128CcmSha256,
TlsRsaWithAes256CcmSha256,
TlsRsaWithAes128Ccm8Sha256,
TlsRsaWithAes256Ccm8Sha256,
TlsDheRsaWithAes128CcmSha256,
TlsDheRsaWithAes256CcmSha256,
TlsDheRsaWithAes128Ccm8Sha256,
TlsDheRsaWithAes256Ccm8Sha256,
TlsPskWithAes128Ccm8Sha256,
TlsEcjpakeWithAes128Ccm8Sha256,
}
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum RecordContentType {
Invalid,
ChangeCipherSpec,
Alert,
Handshake,
ApplicationData,
}
impl RecordContentType {
#[must_use]
pub fn to_u8(self) -> u8 {
match self {
Self::Invalid => 0x00,
Self::ChangeCipherSpec => 0x14,
Self::Alert => 0x15,
Self::Handshake => 0x16,
Self::ApplicationData => 0x17,
}
}
#[must_use]
pub fn from_u8(value: u8) -> Option<Self> {
match value {
0x00 => Some(Self::Invalid),
0x14 => Some(Self::ChangeCipherSpec),
0x15 => Some(Self::Alert),
0x16 => Some(Self::Handshake),
0x17 => Some(Self::ApplicationData),
_ => None,
}
}
}
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum AlertLevel {
Warning,
Fatal,
}
impl AlertLevel {
#[must_use]
pub fn to_u8(self) -> u8 {
match self {
Self::Warning => 1,
Self::Fatal => 2,
}
}
#[must_use]
pub fn from_u8(value: u8) -> Option<Self> {
match value {
1 => Some(Self::Warning),
2 => Some(Self::Fatal),
_ => None,
}
}
}
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum AlertDescription {
CloseNotify,
UnexpectedMessage,
BadRecordMac,
RecordOverflow,
HandshakeFailure,
CertificateUnknown,
IllegalParameter,
DecodeError,
DecryptError,
ProtocolVersion,
InternalError,
UserCanceled,
MissingExtension,
NoApplicationProtocol,
}
impl AlertDescription {
#[must_use]
pub fn to_u8(self) -> u8 {
match self {
Self::CloseNotify => 0,
Self::UnexpectedMessage => 10,
Self::BadRecordMac => 20,
Self::RecordOverflow => 22,
Self::HandshakeFailure => 40,
Self::CertificateUnknown => 46,
Self::IllegalParameter => 47,
Self::DecodeError => 50,
Self::DecryptError => 51,
Self::ProtocolVersion => 70,
Self::InternalError => 80,
Self::UserCanceled => 90,
Self::MissingExtension => 109,
Self::NoApplicationProtocol => 120,
}
}
#[must_use]
pub fn from_u8(value: u8) -> Option<Self> {
match value {
0 => Some(Self::CloseNotify),
10 => Some(Self::UnexpectedMessage),
20 => Some(Self::BadRecordMac),
22 => Some(Self::RecordOverflow),
40 => Some(Self::HandshakeFailure),
46 => Some(Self::CertificateUnknown),
47 => Some(Self::IllegalParameter),
50 => Some(Self::DecodeError),
51 => Some(Self::DecryptError),
70 => Some(Self::ProtocolVersion),
80 => Some(Self::InternalError),
90 => Some(Self::UserCanceled),
109 => Some(Self::MissingExtension),
120 => Some(Self::NoApplicationProtocol),
_ => None,
}
}
}