Skip to content

Commit

Permalink
Merge f0dd6d1 into a923234
Browse files Browse the repository at this point in the history
  • Loading branch information
thomwiggers committed May 8, 2019
2 parents a923234 + f0dd6d1 commit 7809317
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 90 deletions.
198 changes: 110 additions & 88 deletions src/msgs/enums.rs
Expand Up @@ -2,10 +2,11 @@

use crate::msgs::codec::{Reader, Codec};

/// The `ProtocolVersion` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
enum_builder! {@U16
enum_builder! {
/// The `ProtocolVersion` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
@U16
EnumName: ProtocolVersion;
EnumVal{
SSLv2 => 0x0200,
Expand All @@ -17,10 +18,11 @@ enum_builder! {@U16
}
}

/// The `HashAlgorithm` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
enum_builder! {@U8
enum_builder! {
/// The `HashAlgorithm` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
@U8
EnumName: HashAlgorithm;
EnumVal{
NONE => 0x00,
Expand All @@ -33,10 +35,11 @@ enum_builder! {@U8
}
}

/// The `SignatureAlgorithm` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
enum_builder! {@U8
enum_builder! {
/// The `SignatureAlgorithm` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
@U8
EnumName: SignatureAlgorithm;
EnumVal{
Anonymous => 0x00,
Expand All @@ -46,10 +49,11 @@ enum_builder! {@U8
}
}

/// The `ClientCertificateType` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
enum_builder! {@U8
enum_builder! {
/// The `ClientCertificateType` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
@U8
EnumName: ClientCertificateType;
EnumVal{
RSASign => 0x01,
Expand All @@ -65,10 +69,11 @@ enum_builder! {@U8
}
}

/// The `Compression` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
enum_builder! {@U8
enum_builder! {
/// The `Compression` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
@U8
EnumName: Compression;
EnumVal{
Null => 0x00,
Expand All @@ -77,10 +82,11 @@ enum_builder! {@U8
}
}

/// The `ContentType` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
enum_builder! {@U8
enum_builder! {
/// The `ContentType` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
@U8
EnumName: ContentType;
EnumVal{
ChangeCipherSpec => 0x14,
Expand All @@ -91,10 +97,11 @@ enum_builder! {@U8
}
}

/// The `HandshakeType` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
enum_builder! {@U8
enum_builder! {
/// The `HandshakeType` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
@U8
EnumName: HandshakeType;
EnumVal{
HelloRequest => 0x00,
Expand All @@ -118,21 +125,23 @@ enum_builder! {@U8
}
}

/// The `AlertLevel` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
enum_builder! {@U8
enum_builder! {
/// The `AlertLevel` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
@U8
EnumName: AlertLevel;
EnumVal{
Warning => 0x01,
Fatal => 0x02
}
}

/// The `AlertDescription` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
enum_builder! {@U8
enum_builder! {
/// The `AlertDescription` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
@U8
EnumName: AlertDescription;
EnumVal{
CloseNotify => 0x00,
Expand Down Expand Up @@ -172,21 +181,23 @@ enum_builder! {@U8
}
}

/// The `HeartbeatMessageType` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
enum_builder! {@U8
enum_builder! {
/// The `HeartbeatMessageType` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
@U8
EnumName: HeartbeatMessageType;
EnumVal{
Request => 0x01,
Response => 0x02
}
}

/// The `ExtensionType` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
enum_builder! {@U16
enum_builder! {
/// The `ExtensionType` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
@U16
EnumName: ExtensionType;
EnumVal{
ServerName => 0x0000,
Expand Down Expand Up @@ -228,20 +239,22 @@ enum_builder! {@U16
}
}

/// The `ServerNameType` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
enum_builder! {@U8
enum_builder! {
/// The `ServerNameType` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
@U8
EnumName: ServerNameType;
EnumVal{
HostName => 0x00
}
}

/// The `NamedCurve` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
enum_builder! {@U16
enum_builder! {
/// The `NamedCurve` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
@U16
EnumName: NamedCurve;
EnumVal{
sect163k1 => 0x0001,
Expand Down Expand Up @@ -279,10 +292,11 @@ enum_builder! {@U16
}
}

/// The `NamedGroup` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
enum_builder! {@U16
enum_builder! {
/// The `NamedGroup` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
@U16
EnumName: NamedGroup;
EnumVal{
secp256r1 => 0x0017,
Expand All @@ -298,10 +312,11 @@ enum_builder! {@U16
}
}

/// The `CipherSuite` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
enum_builder! {@U16
enum_builder! {
/// The `CipherSuite` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
@U16
EnumName: CipherSuite;
EnumVal{
TLS_NULL_WITH_NULL_NULL => 0x0000,
Expand Down Expand Up @@ -679,10 +694,11 @@ enum_builder! {@U16
}
}

/// The `ECPointFormat` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
enum_builder! {@U8
enum_builder! {
/// The `ECPointFormat` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
@U8
EnumName: ECPointFormat;
EnumVal{
Uncompressed => 0x00,
Expand All @@ -691,21 +707,23 @@ enum_builder! {@U8
}
}

/// The `HeartbeatMode` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
enum_builder! {@U8
enum_builder! {
/// The `HeartbeatMode` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
@U8
EnumName: HeartbeatMode;
EnumVal{
PeerAllowedToSend => 0x01,
PeerNotAllowedToSend => 0x02
}
}

/// The `ECCurveType` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
enum_builder! {@U8
enum_builder! {
/// The `ECCurveType` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
@U8
EnumName: ECCurveType;
EnumVal{
ExplicitPrime => 0x01,
Expand All @@ -714,10 +732,11 @@ enum_builder! {@U8
}
}

/// The `SignatureScheme` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
enum_builder! {@U16
enum_builder! {
/// The `SignatureScheme` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
@U16
EnumName: SignatureScheme;
EnumVal{
RSA_PKCS1_SHA1 => 0x0201,
Expand All @@ -736,32 +755,35 @@ enum_builder! {@U16
}
}

/// The `PSKKeyExchangeMode` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
enum_builder! {@U8
enum_builder! {
/// The `PSKKeyExchangeMode` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
@U8
EnumName: PSKKeyExchangeMode;
EnumVal{
PSK_KE => 0x00,
PSK_DHE_KE => 0x01
}
}

/// The `KeyUpdateRequest` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
enum_builder! {@U8
enum_builder! {
/// The `KeyUpdateRequest` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
@U8
EnumName: KeyUpdateRequest;
EnumVal{
UpdateNotRequested => 0x00,
UpdateRequested => 0x01
}
}

/// The `CertificateStatusType` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
enum_builder! {@U8
enum_builder! {
/// The `CertificateStatusType` TLS protocol enum. Values in this enum are taken
/// from the various RFCs covering TLS, and are listed by IANA.
/// The `Unknown` item is used when processing unrecognised ordinals.
@U8
EnumName: CertificateStatusType;
EnumVal{
OCSP => 0x01
Expand Down
10 changes: 8 additions & 2 deletions src/msgs/macros.rs
@@ -1,9 +1,12 @@
/// A macro which defines an enum type.
macro_rules! enum_builder {
(@U8
(
$(#[$comment:meta])*
@U8
EnumName: $enum_name: ident;
EnumVal { $( $enum_var: ident => $enum_val: expr ),* }
) => {
$(#[$comment])*
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum $enum_name {
$( $enum_var),*
Expand Down Expand Up @@ -32,10 +35,13 @@ macro_rules! enum_builder {
}
}
};
(@U16
(
$(#[$comment:meta])*
@U16
EnumName: $enum_name: ident;
EnumVal { $( $enum_var: ident => $enum_val: expr ),* }
) => {
$(#[$comment])*
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum $enum_name {
$( $enum_var),*
Expand Down

0 comments on commit 7809317

Please sign in to comment.