error.rs (5749B)
1 use alloc::string::String; 2 use core::fmt; 3 use radroots_simplex_smp_crypto::prelude::RadrootsSimplexSmpCryptoError; 4 use radroots_simplex_smp_proto::prelude::RadrootsSimplexSmpProtoError; 5 6 #[derive(Debug, Clone, PartialEq, Eq)] 7 pub enum RadrootsSimplexSmpTransportError { 8 Proto(RadrootsSimplexSmpProtoError), 9 Crypto(RadrootsSimplexSmpCryptoError), 10 InvalidPaddedBlockLength { expected: usize, actual: usize }, 11 TransportPayloadTooLarge(usize), 12 EmptyTransportBlock, 13 TransmissionCountOverflow(usize), 14 TransmissionTooLarge(usize), 15 InvalidPadding { index: usize, value: u8 }, 16 UnexpectedTransmissionCount { declared: u8, actual: usize }, 17 TrailingTransportBytes(usize), 18 MissingHandshakeField(&'static str), 19 InvalidSessionIdentifierLength(usize), 20 MissingServerProof, 21 InvalidCertificateChainLength(usize), 22 UnsupportedAlpn(String), 23 SessionResumptionNotAllowed, 24 ServerIdentityMismatch { expected: String, actual: String }, 25 MissingChannelBinding, 26 SessionBindingMismatch, 27 NoMutualTransportVersion { offered: String, supported: String }, 28 MissingCorrelationId, 29 InvalidServerAddress(String), 30 LiveTransportIo(String), 31 MissingPeerCertificates, 32 UnexpectedBrokerTransmissionCount(usize), 33 CorrelationIdMismatch, 34 } 35 36 impl From<RadrootsSimplexSmpProtoError> for RadrootsSimplexSmpTransportError { 37 fn from(value: RadrootsSimplexSmpProtoError) -> Self { 38 Self::Proto(value) 39 } 40 } 41 42 impl From<RadrootsSimplexSmpCryptoError> for RadrootsSimplexSmpTransportError { 43 fn from(value: RadrootsSimplexSmpCryptoError) -> Self { 44 Self::Crypto(value) 45 } 46 } 47 48 impl fmt::Display for RadrootsSimplexSmpTransportError { 49 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 50 match self { 51 Self::Proto(error) => write!(f, "{error}"), 52 Self::Crypto(error) => write!(f, "{error}"), 53 Self::InvalidPaddedBlockLength { expected, actual } => { 54 write!( 55 f, 56 "invalid SMP padded block length {actual}, expected {expected}" 57 ) 58 } 59 Self::TransportPayloadTooLarge(length) => { 60 write!(f, "SMP transport payload too large: {length} bytes") 61 } 62 Self::EmptyTransportBlock => write!(f, "empty SMP transport block"), 63 Self::TransmissionCountOverflow(count) => { 64 write!(f, "too many SMP transmissions for one block: {count}") 65 } 66 Self::TransmissionTooLarge(length) => { 67 write!(f, "SMP transmission too large for word16 framing: {length}") 68 } 69 Self::InvalidPadding { index, value } => { 70 write!( 71 f, 72 "invalid SMP transport padding byte {value:#04x} at index {index}" 73 ) 74 } 75 Self::UnexpectedTransmissionCount { declared, actual } => { 76 write!( 77 f, 78 "declared {declared} SMP transmissions but decoded {actual}" 79 ) 80 } 81 Self::TrailingTransportBytes(length) => { 82 write!(f, "trailing SMP transport bytes after decode: {length}") 83 } 84 Self::MissingHandshakeField(field) => { 85 write!(f, "missing required SMP handshake field `{field}`") 86 } 87 Self::InvalidSessionIdentifierLength(length) => { 88 write!(f, "invalid SMP session identifier length {length}") 89 } 90 Self::MissingServerProof => write!(f, "missing SMP server proof in handshake"), 91 Self::InvalidCertificateChainLength(length) => { 92 write!(f, "invalid SMP certificate chain length {length}") 93 } 94 Self::UnsupportedAlpn(alpn) => write!(f, "unsupported SMP ALPN `{alpn}`"), 95 Self::SessionResumptionNotAllowed => { 96 write!(f, "SMP TLS session resumption is not allowed") 97 } 98 Self::ServerIdentityMismatch { expected, actual } => { 99 write!( 100 f, 101 "SMP server identity mismatch: expected `{expected}`, got `{actual}`" 102 ) 103 } 104 Self::MissingChannelBinding => write!(f, "missing SMP tls-unique channel binding"), 105 Self::SessionBindingMismatch => { 106 write!( 107 f, 108 "SMP session identifier does not match tls-unique binding" 109 ) 110 } 111 Self::NoMutualTransportVersion { offered, supported } => { 112 write!( 113 f, 114 "no mutual SMP transport version between `{offered}` and `{supported}`" 115 ) 116 } 117 Self::MissingCorrelationId => { 118 write!(f, "SMP transport request is missing a correlation id") 119 } 120 Self::InvalidServerAddress(message) => write!(f, "{message}"), 121 Self::LiveTransportIo(message) => write!(f, "{message}"), 122 Self::MissingPeerCertificates => { 123 write!(f, "SMP TLS peer certificate chain is missing") 124 } 125 Self::UnexpectedBrokerTransmissionCount(count) => { 126 write!( 127 f, 128 "expected exactly one SMP broker transmission, got {count}" 129 ) 130 } 131 Self::CorrelationIdMismatch => { 132 write!( 133 f, 134 "SMP broker response correlation id did not match the request" 135 ) 136 } 137 } 138 } 139 } 140 141 #[cfg(feature = "std")] 142 impl std::error::Error for RadrootsSimplexSmpTransportError {}