use serde::Deserialize;
use serde::Serialize;
use thiserror::Error;
use zerocopy::network_endian::*;
use zerocopy::AsBytes;
use zerocopy::FromBytes;
use zerocopy::FromZeroes;
use zerocopy::Unaligned;
#[derive(Debug, FromBytes, FromZeroes, AsBytes, Unaligned, Copy, Clone)]
#[repr(packed)]
pub struct Header {
pub initiator_cookie: U64,
pub responder_cookie: U64,
pub next_payload: u8,
pub version: u8,
pub exchange_type: u8,
pub flags: u8,
pub message_id: U32,
pub length: U32,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
#[repr(u8)]
#[allow(missing_docs)]
pub enum PayloadType {
None = 0,
SecurityAssociation = 1,
Proposal = 2,
Transform = 3,
KeyExchange = 4,
Identification = 5,
Certificate = 6,
CertificateRequest = 7,
Hash = 8,
Signature = 9,
Nonce = 10,
Notification = 11,
Delete = 12,
VendorID = 13,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
#[repr(u8)]
pub enum PayloadTypeOther {
Reserved,
PrivateUse,
}
impl TryFrom<u8> for PayloadType {
type Error = PayloadTypeOther;
fn try_from(value: u8) -> Result<Self, Self::Error> {
Ok(match value {
0 => PayloadType::None,
1 => PayloadType::SecurityAssociation,
2 => PayloadType::Proposal,
3 => PayloadType::Transform,
4 => PayloadType::KeyExchange,
5 => PayloadType::Identification,
6 => PayloadType::Certificate,
7 => PayloadType::CertificateRequest,
8 => PayloadType::Hash,
9 => PayloadType::Signature,
10 => PayloadType::Nonce,
11 => PayloadType::Notification,
12 => PayloadType::Delete,
13 => PayloadType::VendorID,
14..128 => return Err(PayloadTypeOther::Reserved),
_ => return Err(PayloadTypeOther::PrivateUse),
})
}
}
#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Copy, Clone)]
#[repr(u8)]
#[allow(missing_docs)]
pub enum ExchangeType {
None = 0,
Base = 1,
IdentityProtection = 2,
AuthenticationOnly = 3,
Aggressive = 4,
Informational = 5,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
#[repr(u8)]
pub enum ExchangeTypeOther {
IsakmpFutureUse,
DOISpecificUse,
PrivateUse,
}
impl TryFrom<u8> for ExchangeType {
type Error = ExchangeTypeOther;
fn try_from(value: u8) -> Result<Self, Self::Error> {
Ok(match value {
0 => ExchangeType::None,
1 => ExchangeType::Base,
2 => ExchangeType::IdentityProtection,
3 => ExchangeType::AuthenticationOnly,
4 => ExchangeType::Aggressive,
5 => ExchangeType::Informational,
6..32 => return Err(ExchangeTypeOther::IsakmpFutureUse),
32..240 => return Err(ExchangeTypeOther::DOISpecificUse),
_ => return Err(ExchangeTypeOther::PrivateUse),
})
}
}
#[derive(Debug, FromBytes, FromZeroes, AsBytes, Unaligned, Copy, Clone)]
#[repr(packed)]
pub struct GenericPayloadHeader {
pub next_payload: u8,
pub reserved: u8,
pub payload_length: U16,
}
#[derive(Debug, FromBytes, FromZeroes, AsBytes, Unaligned, Copy, Clone)]
#[repr(packed)]
pub struct DataAttributeShort {
pub attribute_type: U16,
pub attribute_value: U16,
}
#[derive(Debug, FromBytes, FromZeroes, AsBytes, Unaligned, Copy, Clone)]
#[repr(packed)]
pub struct StaticDataAttributeLong {
pub attribute_type: U16,
pub attribute_length: U16,
}
#[derive(Debug, Clone)]
pub struct VariableDataAttributeLong {
pub attribute_value: Vec<u8>,
}
#[derive(Debug, FromBytes, FromZeroes, AsBytes, Unaligned, Copy, Clone)]
#[repr(packed)]
pub struct StaticSecurityAssociationPayload {
pub generic_payload_header: GenericPayloadHeader,
pub doi: U32,
}
#[derive(Debug, Clone)]
pub struct VariableSecurityAssociationPayload {
pub situation: Vec<u8>,
}
#[derive(Debug, FromBytes, FromZeroes, AsBytes, Unaligned, Copy, Clone)]
#[repr(packed)]
pub struct StaticProposalPayload {
pub generic_payload_header: GenericPayloadHeader,
pub proposal_no: u8,
pub protocol_id: u8,
pub spi_size: u8,
pub no_of_transforms: u8,
}
#[derive(Debug, Clone)]
pub struct VariableProposalPayload {
pub spi: Vec<u8>,
}
#[derive(Debug, FromBytes, FromZeroes, AsBytes, Unaligned, Copy, Clone)]
#[repr(packed)]
pub struct StaticTransformPayload {
pub generic_payload_header: GenericPayloadHeader,
pub transform_no: u8,
pub transform_id: u8,
pub reserved: U16,
}
#[derive(Debug, Clone)]
pub struct VariableTransformPayload {
pub sa_attributes: Vec<u8>,
}
#[derive(Debug, FromBytes, FromZeroes, AsBytes, Unaligned, Copy, Clone)]
#[repr(packed)]
pub struct StaticKeyExchangePayload {
pub generic_payload_header: GenericPayloadHeader,
}
#[derive(Debug, Clone)]
pub struct VariableKeyExchangePayload {
pub key_exchange_data: Vec<u8>,
}
#[derive(Debug, FromBytes, FromZeroes, AsBytes, Unaligned, Copy, Clone)]
#[repr(packed)]
pub struct StaticIdentificationPayload {
pub generic_payload_header: GenericPayloadHeader,
pub id_type: u8,
}
#[derive(Debug, Clone)]
pub struct VariableIdentificationPayload {
pub identification_data: Vec<u8>,
}
#[derive(Debug, FromBytes, FromZeroes, AsBytes, Unaligned, Copy, Clone)]
#[repr(packed)]
pub struct StaticCertificatePayload {
pub generic_payload_header: GenericPayloadHeader,
pub certificate_encoding: u8,
}
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Copy)]
#[repr(u8)]
#[allow(missing_docs)]
pub enum CertificateEncoding {
None = 0,
PKCS7WrappedX509Certificate = 1,
PGPCertificate = 2,
DNSSignedKey = 3,
X509CertificateSignature = 4,
X509CertificateKeyExchange = 5,
KerberosTokens = 6,
CertificateRevocationList = 7,
AuthorityRevocationList = 8,
SPKICertificate = 9,
X509CertificateAttribute = 10,
}
#[derive(Debug, Clone)]
pub enum CertificateEncodingOther {
Reserved,
}
impl TryFrom<u8> for CertificateEncoding {
type Error = CertificateEncodingOther;
fn try_from(value: u8) -> Result<Self, Self::Error> {
Ok(match value {
0 => CertificateEncoding::None,
1 => CertificateEncoding::PKCS7WrappedX509Certificate,
2 => CertificateEncoding::PGPCertificate,
3 => CertificateEncoding::DNSSignedKey,
4 => CertificateEncoding::X509CertificateSignature,
5 => CertificateEncoding::X509CertificateKeyExchange,
6 => CertificateEncoding::KerberosTokens,
7 => CertificateEncoding::CertificateRevocationList,
8 => CertificateEncoding::AuthorityRevocationList,
9 => CertificateEncoding::SPKICertificate,
10 => CertificateEncoding::X509CertificateAttribute,
_ => return Err(CertificateEncodingOther::Reserved),
})
}
}
#[derive(Debug, Clone)]
pub struct VariableCertificatePayload {
pub certificate_data: Vec<u8>,
}
#[derive(Debug, FromBytes, FromZeroes, AsBytes, Unaligned, Copy, Clone)]
#[repr(packed)]
pub struct StaticCertificateRequestPayload {
pub generic_payload_header: GenericPayloadHeader,
pub certificate_encoding: u8,
}
#[derive(Debug, Clone)]
pub struct VariableCertificateRequestPayload {
pub certificate_authority: Vec<u8>,
}
#[derive(Debug, FromBytes, FromZeroes, AsBytes, Unaligned, Copy, Clone)]
#[repr(packed)]
pub struct StaticHashPayload {
pub generic_payload_header: GenericPayloadHeader,
}
#[derive(Debug, Clone)]
pub struct VariableHashPayload {
pub hash_data: Vec<u8>,
}
#[derive(Debug, FromBytes, FromZeroes, AsBytes, Unaligned, Copy, Clone)]
#[repr(packed)]
pub struct StaticSignaturePayload {
pub generic_payload_header: GenericPayloadHeader,
}
#[derive(Debug, Clone)]
pub struct VariableSignaturePayload {
pub signature_data: Vec<u8>,
}
#[derive(Debug, FromBytes, FromZeroes, AsBytes, Unaligned, Copy, Clone)]
#[repr(packed)]
pub struct StaticNoncePayload {
pub generic_payload_header: GenericPayloadHeader,
}
#[derive(Debug, Clone)]
pub struct VariableNoncePayload {
pub nonce_data: Vec<u8>,
}
#[derive(Debug, FromBytes, FromZeroes, AsBytes, Unaligned, Copy, Clone)]
#[repr(packed)]
pub struct StaticNotificationPayload {
pub generic_payload_header: GenericPayloadHeader,
pub doi: U32,
pub protocol_id: u8,
pub spi_size: u8,
pub notify_message_type: U16,
}
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Copy)]
#[repr(u16)]
#[allow(missing_docs)]
pub enum NotifyMessageType {
Invalid = 0,
InvalidPayloadType = 1,
DOINotSupported = 2,
SituationNotSupported = 3,
InvalidCookie = 4,
InvalidMajorVersion = 5,
InvalidMinorVersion = 6,
InvalidExchangeType = 7,
InvalidFlags = 8,
InvalidMessageId = 9,
InvalidProtocolId = 10,
InvalidSPI = 11,
InvalidTransformId = 12,
AttributesNotSupported = 13,
NoProposalChosen = 14,
BadProposalChosen = 15,
PayloadMalformed = 16,
InvalidKeyInformation = 17,
InvalidIdInformation = 18,
InvalidCertEncoding = 19,
InvalidCertificate = 20,
CertTypeUnsupported = 21,
InvalidCertAuthority = 22,
InvalidHashInformation = 23,
AuthenticationFailed = 24,
InvalidSignature = 25,
AddressNotification = 26,
NotifySALifetime = 27,
CertificateUnavailable = 28,
UnsupportedExchangeType = 29,
UnequalPayloadLengths = 30,
Connected = 16384,
}
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Copy)]
pub enum NotifyMessageTypeOther {
Reserved,
PrivateUse,
Reserved2,
DOISpecific,
PrivateUse2,
Reserved3,
}
impl TryFrom<u16> for NotifyMessageType {
type Error = NotifyMessageTypeOther;
fn try_from(value: u16) -> Result<Self, Self::Error> {
Ok(match value {
0 => NotifyMessageType::Invalid,
1 => NotifyMessageType::InvalidPayloadType,
2 => NotifyMessageType::DOINotSupported,
3 => NotifyMessageType::SituationNotSupported,
4 => NotifyMessageType::InvalidCookie,
5 => NotifyMessageType::InvalidMajorVersion,
6 => NotifyMessageType::InvalidMinorVersion,
7 => NotifyMessageType::InvalidExchangeType,
8 => NotifyMessageType::InvalidFlags,
9 => NotifyMessageType::InvalidMessageId,
10 => NotifyMessageType::InvalidProtocolId,
11 => NotifyMessageType::InvalidSPI,
12 => NotifyMessageType::InvalidTransformId,
13 => NotifyMessageType::AttributesNotSupported,
14 => NotifyMessageType::NoProposalChosen,
15 => NotifyMessageType::BadProposalChosen,
16 => NotifyMessageType::PayloadMalformed,
17 => NotifyMessageType::InvalidKeyInformation,
18 => NotifyMessageType::InvalidIdInformation,
19 => NotifyMessageType::InvalidCertEncoding,
20 => NotifyMessageType::InvalidCertificate,
21 => NotifyMessageType::CertTypeUnsupported,
22 => NotifyMessageType::InvalidCertAuthority,
23 => NotifyMessageType::InvalidHashInformation,
24 => NotifyMessageType::AuthenticationFailed,
25 => NotifyMessageType::InvalidSignature,
26 => NotifyMessageType::AddressNotification,
27 => NotifyMessageType::NotifySALifetime,
28 => NotifyMessageType::CertificateUnavailable,
29 => NotifyMessageType::UnsupportedExchangeType,
30 => NotifyMessageType::UnequalPayloadLengths,
31..8192 => return Err(NotifyMessageTypeOther::Reserved),
8192..16384 => return Err(NotifyMessageTypeOther::PrivateUse),
16384 => NotifyMessageType::Connected,
16385..24576 => return Err(NotifyMessageTypeOther::Reserved2),
24576..32768 => return Err(NotifyMessageTypeOther::PrivateUse2),
_ => return Err(NotifyMessageTypeOther::Reserved3),
})
}
}
#[derive(Debug, Clone)]
pub struct VariableNotificationPayload {
pub spi: Vec<u8>,
pub notification_data: Vec<u8>,
}
#[derive(Debug, FromBytes, FromZeroes, AsBytes, Unaligned, Copy, Clone)]
#[repr(packed)]
pub struct StaticDeletePayload {
pub generic_payload_header: GenericPayloadHeader,
pub doi: U32,
pub protocol_id: u8,
pub spi_size: u8,
pub no_of_spis: U16,
}
#[derive(Debug, Clone)]
pub struct VariableDeletePayload {
pub security_parameter_indexes: Vec<u8>,
}
#[derive(Debug, FromBytes, FromZeroes, AsBytes, Unaligned, Copy, Clone)]
#[repr(packed)]
pub struct StaticVendorIDPayload {
pub generic_payload_header: GenericPayloadHeader,
}
#[derive(Debug, Clone)]
pub struct VariableVendorIDPayload {
pub vendor_id: Vec<u8>,
}
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Copy)]
#[repr(u32)]
#[allow(missing_docs)]
pub enum DomainOfInterpretation {
ISAKMP = 0,
IPSEC = 1,
GDOI = 2,
}
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Copy, Error)]
#[error("Invalid domain of interpretation received: {0}")]
pub struct InvalidDomainOfInterpretation(pub u32);
impl TryFrom<u32> for DomainOfInterpretation {
type Error = InvalidDomainOfInterpretation;
fn try_from(value: u32) -> Result<Self, Self::Error> {
match value {
0 => Ok(DomainOfInterpretation::ISAKMP),
1 => Ok(DomainOfInterpretation::IPSEC),
2 => Ok(DomainOfInterpretation::GDOI),
_ => Err(InvalidDomainOfInterpretation(value)),
}
}
}
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Copy)] #[derive(strum::EnumIter, strum::Display)] #[derive(Serialize, Deserialize)] #[repr(u16)]
#[allow(non_camel_case_types, missing_docs)]
pub enum EncryptionAlgorithm {
Reserved = 0,
DES_CBC = 1,
IDEA_CBC = 2,
BlowfishCBC = 3,
RC5_R16_B64_CBC = 4,
TrippleDES_CBC = 5,
CAST_CBC = 6,
AES_CBC = 7,
CAMELLIA_CBC = 8,
}
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Copy, Error)]
pub enum EncryptionAlgorithmOther {
#[error("Unassigned({0})")]
Unassigned(u16),
#[error("PrivateUse({0})")]
PrivateUse(u16),
}
impl TryFrom<u16> for EncryptionAlgorithm {
type Error = EncryptionAlgorithmOther;
fn try_from(value: u16) -> Result<Self, Self::Error> {
match value {
0 => Ok(EncryptionAlgorithm::Reserved),
1 => Ok(EncryptionAlgorithm::DES_CBC),
2 => Ok(EncryptionAlgorithm::IDEA_CBC),
3 => Ok(EncryptionAlgorithm::BlowfishCBC),
4 => Ok(EncryptionAlgorithm::RC5_R16_B64_CBC),
5 => Ok(EncryptionAlgorithm::TrippleDES_CBC),
6 => Ok(EncryptionAlgorithm::CAST_CBC),
7 => Ok(EncryptionAlgorithm::AES_CBC),
8 => Ok(EncryptionAlgorithm::CAMELLIA_CBC),
9..65001 => Err(EncryptionAlgorithmOther::Unassigned(value)),
_ => Err(EncryptionAlgorithmOther::PrivateUse(value)),
}
}
}
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Copy)] #[derive(strum::EnumIter, strum::Display)] #[derive(Serialize, Deserialize)] #[repr(u16)]
#[allow(missing_docs)]
pub enum HashAlgorithm {
Reserved = 0,
MD5 = 1,
SHA = 2,
Tiger = 3,
SHA2_256 = 4,
SHA2_384 = 5,
SHA2_512 = 6,
}
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Copy, Error)]
pub enum HashAlgorithmOther {
#[error("Unassigned({0})")]
Unassigned(u16),
#[error("Unassigned({0})")]
PrivateUse(u16),
}
impl TryFrom<u16> for HashAlgorithm {
type Error = HashAlgorithmOther;
fn try_from(value: u16) -> Result<Self, Self::Error> {
match value {
0 => Ok(HashAlgorithm::Reserved),
1 => Ok(HashAlgorithm::MD5),
2 => Ok(HashAlgorithm::SHA),
3 => Ok(HashAlgorithm::Tiger),
4 => Ok(HashAlgorithm::SHA2_256),
5 => Ok(HashAlgorithm::SHA2_384),
6 => Ok(HashAlgorithm::SHA2_512),
7..65001 => Err(HashAlgorithmOther::Unassigned(value)),
_ => Err(HashAlgorithmOther::PrivateUse(value)),
}
}
}
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Copy)] #[derive(strum::EnumIter, strum::Display)] #[derive(Serialize, Deserialize)] #[repr(u16)]
#[allow(missing_docs)]
pub enum AuthenticationMethod {
Reserved = 0,
PreSharedKey = 1,
DSSSignatures = 2,
RSASignatures = 3,
EncryptionWithRSA = 4,
RevisedEncryptionWithRSA = 5,
EncryptionWithElGamal = 6,
RevisedEncryptionWithElGamal = 7,
ECDSASignatures = 8,
ECDSAWithSHA256OnP256Curve = 9,
ECDSAWithSHA384OnP384Curve = 10,
ECDSAWithSHA512OnP512Curve = 11,
HybridMode = 64221,
XAUTH = 65001,
}
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Copy, Error)]
pub enum AuthenticationMethodOther {
#[error("Unassigned({0})")]
Unassigned(u16),
#[error("PrivateUse({0})")]
PrivateUse(u16),
}
impl TryFrom<u16> for AuthenticationMethod {
type Error = AuthenticationMethodOther;
fn try_from(value: u16) -> Result<Self, Self::Error> {
match value {
0 => Ok(AuthenticationMethod::Reserved),
1 => Ok(AuthenticationMethod::PreSharedKey),
2 => Ok(AuthenticationMethod::DSSSignatures),
3 => Ok(AuthenticationMethod::RSASignatures),
4 => Ok(AuthenticationMethod::EncryptionWithRSA),
5 => Ok(AuthenticationMethod::RevisedEncryptionWithRSA),
6 => Ok(AuthenticationMethod::EncryptionWithElGamal),
7 => Ok(AuthenticationMethod::RevisedEncryptionWithElGamal),
8 => Ok(AuthenticationMethod::ECDSASignatures),
9 => Ok(AuthenticationMethod::ECDSAWithSHA256OnP256Curve),
10 => Ok(AuthenticationMethod::ECDSAWithSHA384OnP384Curve),
11 => Ok(AuthenticationMethod::ECDSAWithSHA512OnP512Curve),
12..64221 => Err(AuthenticationMethodOther::Unassigned(value)),
64221 => Ok(AuthenticationMethod::HybridMode),
64222..65001 => Err(AuthenticationMethodOther::Unassigned(value)),
65001 => Ok(AuthenticationMethod::XAUTH),
_ => Err(AuthenticationMethodOther::PrivateUse(value)),
}
}
}
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Copy)] #[derive(strum::EnumIter, strum::Display)] #[derive(Serialize, Deserialize)] #[repr(u16)]
#[allow(missing_docs, non_camel_case_types)]
pub enum GroupDescription {
Reserved = 0,
MODP_768 = 1,
MODP_1024 = 2,
EC2N_GF2_155 = 3,
EC2N_GF2_185 = 4,
MODP_1536 = 5,
MODP_2048 = 14,
MODP_3072 = 15,
MODP_4096 = 16,
MODP_6144 = 17,
MODP_8192 = 18,
ECP_Random_256 = 19,
ECP_Random_384 = 20,
ECP_Random_521 = 21,
MODP_1024_160_PrimeOrderSubgroup = 22,
MODP_2048_224_PrimeOrderSubgroup = 23,
MODP_2048_256_PrimeOrderSubgroup = 24,
ECP_Random_192 = 25,
ECP_Random_224 = 26,
ECP_Brainpool_224 = 27,
ECP_Brainpool_256 = 28,
ECP_Brainpool_384 = 29,
ECP_Brainpool_512 = 30,
}
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Copy, Error)]
pub enum GroupDescriptionOther {
#[error("Unassigned({0})")]
Unassigned(u16),
#[error("PrivateUse({0})")]
PrivateUse(u16),
}
impl TryFrom<u16> for GroupDescription {
type Error = GroupDescriptionOther;
fn try_from(value: u16) -> Result<Self, Self::Error> {
match value {
0 => Ok(GroupDescription::Reserved),
1 => Ok(GroupDescription::MODP_768),
2 => Ok(GroupDescription::MODP_1024),
3 => Ok(GroupDescription::EC2N_GF2_155),
4 => Ok(GroupDescription::EC2N_GF2_185),
5 => Ok(GroupDescription::MODP_1536),
6..14 => Err(GroupDescriptionOther::Unassigned(value)),
14 => Ok(GroupDescription::MODP_2048),
15 => Ok(GroupDescription::MODP_3072),
16 => Ok(GroupDescription::MODP_4096),
17 => Ok(GroupDescription::MODP_6144),
18 => Ok(GroupDescription::MODP_8192),
19 => Ok(GroupDescription::ECP_Random_256),
20 => Ok(GroupDescription::ECP_Random_384),
21 => Ok(GroupDescription::ECP_Random_521),
22 => Ok(GroupDescription::MODP_1024_160_PrimeOrderSubgroup),
23 => Ok(GroupDescription::MODP_2048_224_PrimeOrderSubgroup),
24 => Ok(GroupDescription::MODP_2048_256_PrimeOrderSubgroup),
25 => Ok(GroupDescription::ECP_Random_192),
26 => Ok(GroupDescription::ECP_Random_224),
27 => Ok(GroupDescription::ECP_Brainpool_224),
28 => Ok(GroupDescription::ECP_Brainpool_256),
29 => Ok(GroupDescription::ECP_Brainpool_384),
30 => Ok(GroupDescription::ECP_Brainpool_512),
31..32768 => Err(GroupDescriptionOther::Unassigned(value)),
_ => Err(GroupDescriptionOther::PrivateUse(value)),
}
}
}
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Copy)] #[derive(strum::EnumIter, strum::Display)] #[derive(Serialize, Deserialize)] #[repr(u16)]
#[allow(missing_docs)]
pub enum AttributeType {
Reserved = 0,
EncryptionAlgorithm = 1,
HashAlgorithm = 2,
AuthenticationMethod = 3,
GroupDescription = 4,
GroupType = 5,
GroupPrime = 6,
GroupGeneratorOne = 7,
GroupGeneratorTwo = 8,
GroupCurveA = 9,
GroupCurveB = 10,
LifeType = 11,
LifeDuration = 12,
PRF = 13,
KeyLength = 14,
FieldSize = 15,
GroupOrder = 16,
}
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Copy, Error)]
pub enum AttributeTypeOther {
#[error("Unassigned({0})")]
Unassigned(u16),
#[error("PrivateUse({0})")]
PrivateUse(u16),
}
impl TryFrom<u16> for AttributeType {
type Error = AttributeTypeOther;
fn try_from(value: u16) -> Result<Self, Self::Error> {
match value {
0 => Ok(AttributeType::Reserved),
1 => Ok(AttributeType::EncryptionAlgorithm),
2 => Ok(AttributeType::HashAlgorithm),
3 => Ok(AttributeType::AuthenticationMethod),
4 => Ok(AttributeType::GroupDescription),
5 => Ok(AttributeType::GroupType),
6 => Ok(AttributeType::GroupPrime),
7 => Ok(AttributeType::GroupGeneratorOne),
8 => Ok(AttributeType::GroupGeneratorTwo),
9 => Ok(AttributeType::GroupCurveA),
10 => Ok(AttributeType::GroupCurveB),
11 => Ok(AttributeType::LifeType),
12 => Ok(AttributeType::LifeDuration),
13 => Ok(AttributeType::PRF),
14 => Ok(AttributeType::KeyLength),
15 => Ok(AttributeType::FieldSize),
16 => Ok(AttributeType::GroupOrder),
17..16384 => Err(AttributeTypeOther::Unassigned(value)),
_ => Err(AttributeTypeOther::PrivateUse(value)),
}
}
}
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Copy)]
#[allow(missing_docs)]
#[repr(u16)]
pub enum GroupType {
Reserved = 0,
MODP = 1,
ECP = 2,
ECP2N = 3,
}
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Copy, Error)]
pub enum GroupTypeOther {
#[error("Unassigned({0})")]
Unassigned(u16),
#[error("PrivateUse({0})")]
PrivateUse(u16),
}
impl TryFrom<u16> for GroupType {
type Error = GroupTypeOther;
fn try_from(value: u16) -> Result<Self, Self::Error> {
match value {
0 => Ok(GroupType::Reserved),
1 => Ok(GroupType::MODP),
2 => Ok(GroupType::ECP),
3 => Ok(GroupType::ECP2N),
4..65001 => Err(GroupTypeOther::Unassigned(value)),
_ => Err(GroupTypeOther::PrivateUse(value)),
}
}
}
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Copy)]
#[allow(missing_docs)]
#[repr(u16)]
pub enum LifeType {
Reserved = 0,
Seconds = 1,
Kilobytes = 2,
}
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Copy, Error)]
pub enum LifeTypeOther {
#[error("Unassigned({0})")]
Unassigned(u16),
#[error("PrivateUse({0})")]
PrivateUse(u16),
}
impl TryFrom<u16> for LifeType {
type Error = LifeTypeOther;
fn try_from(value: u16) -> Result<Self, Self::Error> {
match value {
0 => Ok(LifeType::Reserved),
1 => Ok(LifeType::Seconds),
2 => Ok(LifeType::Kilobytes),
3..65001 => Err(LifeTypeOther::Unassigned(value)),
_ => Err(LifeTypeOther::PrivateUse(value)),
}
}
}