@@ -5,7 +5,6 @@ use std::sync::Arc;
5
5
6
6
use crate :: ffi_panic_boundary;
7
7
use libc:: { c_char, c_uint, size_t} ;
8
- use num_enum:: TryFromPrimitive ;
9
8
use rustls:: { CertificateError , Error , InvalidMessage } ;
10
9
11
10
/// A return value for a function that may return either success (0) or a
@@ -16,6 +15,162 @@ use rustls::{CertificateError, Error, InvalidMessage};
16
15
#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
17
16
pub struct rustls_io_result ( pub libc:: c_int ) ;
18
17
18
+ macro_rules! u32_enum_builder {
19
+ (
20
+ $( #[ $comment: meta] ) *
21
+ EnumName : $enum_name: ident;
22
+ EnumDefault : $enum_default: ident;
23
+ EnumVal { $( $enum_var: ident => $enum_val: expr ) ,* }
24
+ ) => {
25
+ $( #[ $comment] ) *
26
+ #[ allow( dead_code) ]
27
+ #[ repr( u32 ) ]
28
+ #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
29
+ pub enum $enum_name {
30
+ $( $enum_var = $enum_val) ,*
31
+ }
32
+ impl From <u32 > for $enum_name {
33
+ fn from( x: u32 ) -> Self {
34
+ match x {
35
+ $( $enum_val => $enum_name:: $enum_var) ,*
36
+ , _ => $enum_name:: $enum_default,
37
+ }
38
+ }
39
+ }
40
+ } ;
41
+ }
42
+
43
+ u32_enum_builder ! {
44
+ EnumName : rustls_result;
45
+ EnumDefault : InvalidParameter ;
46
+ EnumVal {
47
+ Ok => 7000 ,
48
+ Io => 7001 ,
49
+ NullParameter => 7002 ,
50
+ InvalidDnsNameError => 7003 ,
51
+ Panic => 7004 ,
52
+ CertificateParseError => 7005 ,
53
+ PrivateKeyParseError => 7006 ,
54
+ InsufficientSize => 7007 ,
55
+ NotFound => 7008 ,
56
+ InvalidParameter => 7009 ,
57
+ UnexpectedEof => 7010 ,
58
+ PlaintextEmpty => 7011 ,
59
+ AcceptorNotReady => 7012 ,
60
+ AlreadyUsed => 7013 ,
61
+
62
+ // From https://docs.rs/rustls/latest/rustls/enum.Error.html
63
+ NoCertificatesPresented => 7101 ,
64
+ DecryptError => 7102 ,
65
+ FailedToGetCurrentTime => 7103 ,
66
+ FailedToGetRandomBytes => 7113 ,
67
+ HandshakeNotComplete => 7104 ,
68
+ PeerSentOversizedRecord => 7105 ,
69
+ NoApplicationProtocol => 7106 ,
70
+ BadMaxFragmentSize => 7114 ,
71
+ UnsupportedNameType => 7115 ,
72
+ EncryptError => 7116 ,
73
+
74
+ // Reserved from previous use pre rustls-ffi <0.21.0
75
+ // CorruptMessage => 7100,
76
+ // CorruptMessagePayload => 7111,
77
+ // CertInvalidEncoding => 7117,
78
+ // CertInvalidSignatureType => 7118,
79
+ // CertInvalidSignature => 7119,
80
+ // CertInvalidData => 7120,
81
+
82
+ // From InvalidCertificate, with fields that get flattened.
83
+ // https://docs.rs/rustls/0.21.0/rustls/enum.Error.html#variant.InvalidCertificate
84
+ CertEncodingBad => 7121 ,
85
+ CertExpired => 7122 ,
86
+ CertNotYetValid => 7123 ,
87
+ CertRevoked => 7124 ,
88
+ CertUnhandledCriticalExtension => 7125 ,
89
+ CertUnknownIssuer => 7126 ,
90
+ CertBadSignature => 7127 ,
91
+ CertNotValidForName => 7128 ,
92
+ CertInvalidPurpose => 7129 ,
93
+ CertApplicationVerificationFailure => 7130 ,
94
+ CertOtherError => 7131 ,
95
+
96
+ // From InvalidMessage, with fields that get flattened.
97
+ // https://docs.rs/rustls/0.21.0/rustls/enum.Error.html#variant.InvalidMessage
98
+ MessageHandshakePayloadTooLarge => 7133 ,
99
+ MessageInvalidCcs => 7134 ,
100
+ MessageInvalidContentType => 7135 ,
101
+ MessageInvalidCertStatusType => 7136 ,
102
+ MessageInvalidCertRequest => 7137 ,
103
+ MessageInvalidDhParams => 7138 ,
104
+ MessageInvalidEmptyPayload => 7139 ,
105
+ MessageInvalidKeyUpdate => 7140 ,
106
+ MessageInvalidServerName => 7141 ,
107
+ MessageTooLarge => 7142 ,
108
+ MessageTooShort => 7143 ,
109
+ MessageMissingData => 7144 ,
110
+ MessageMissingKeyExchange => 7145 ,
111
+ MessageNoSignatureSchemes => 7146 ,
112
+ MessageTrailingData => 7147 ,
113
+ MessageUnexpectedMessage => 7148 ,
114
+ MessageUnknownProtocolVersion => 7149 ,
115
+ MessageUnsupportedCompression => 7150 ,
116
+ MessageUnsupportedCurveType => 7151 ,
117
+ MessageUnsupportedKeyExchangeAlgorithm => 7152 ,
118
+ MessageInvalidOther => 7153 , // Last added.
119
+
120
+ // From Error, with fields that get dropped.
121
+ PeerIncompatibleError => 7107 ,
122
+ PeerMisbehavedError => 7108 ,
123
+ InappropriateMessage => 7109 ,
124
+ InappropriateHandshakeMessage => 7110 ,
125
+ General => 7112 ,
126
+
127
+ // From Error, with fields that get flattened.
128
+ // https://docs.rs/rustls/latest/rustls/internal/msgs/enums/enum.AlertDescription.html
129
+ AlertCloseNotify => 7200 ,
130
+ AlertUnexpectedMessage => 7201 ,
131
+ AlertBadRecordMac => 7202 ,
132
+ AlertDecryptionFailed => 7203 ,
133
+ AlertRecordOverflow => 7204 ,
134
+ AlertDecompressionFailure => 7205 ,
135
+ AlertHandshakeFailure => 7206 ,
136
+ AlertNoCertificate => 7207 ,
137
+ AlertBadCertificate => 7208 ,
138
+ AlertUnsupportedCertificate => 7209 ,
139
+ AlertCertificateRevoked => 7210 ,
140
+ AlertCertificateExpired => 7211 ,
141
+ AlertCertificateUnknown => 7212 ,
142
+ AlertIllegalParameter => 7213 ,
143
+ AlertUnknownCA => 7214 ,
144
+ AlertAccessDenied => 7215 ,
145
+ AlertDecodeError => 7216 ,
146
+ AlertDecryptError => 7217 ,
147
+ AlertExportRestriction => 7218 ,
148
+ AlertProtocolVersion => 7219 ,
149
+ AlertInsufficientSecurity => 7220 ,
150
+ AlertInternalError => 7221 ,
151
+ AlertInappropriateFallback => 7222 ,
152
+ AlertUserCanceled => 7223 ,
153
+ AlertNoRenegotiation => 7224 ,
154
+ AlertMissingExtension => 7225 ,
155
+ AlertUnsupportedExtension => 7226 ,
156
+ AlertCertificateUnobtainable => 7227 ,
157
+ AlertUnrecognisedName => 7228 ,
158
+ AlertBadCertificateStatusResponse => 7229 ,
159
+ AlertBadCertificateHashValue => 7230 ,
160
+ AlertUnknownPSKIdentity => 7231 ,
161
+ AlertCertificateRequired => 7232 ,
162
+ AlertNoApplicationProtocol => 7233 ,
163
+ AlertUnknown => 7234 ,
164
+
165
+ // https://docs.rs/sct/latest/sct/enum.Error.html
166
+ CertSCTMalformed => 7319 ,
167
+ CertSCTInvalidSignature => 7320 ,
168
+ CertSCTTimestampInFuture => 7321 ,
169
+ CertSCTUnsupportedVersion => 7322 ,
170
+ CertSCTUnknownLog => 7323
171
+ }
172
+ }
173
+
19
174
impl rustls_result {
20
175
/// After a rustls function returns an error, you may call
21
176
/// this to get a pointer to a buffer containing a detailed error
@@ -135,136 +290,6 @@ fn test_rustls_result_is_cert_error() {
135
290
}
136
291
}
137
292
138
- #[ allow( dead_code) ]
139
- #[ repr( u32 ) ]
140
- #[ derive( Debug , TryFromPrimitive , Clone , Copy , PartialEq , Eq ) ]
141
- pub enum rustls_result {
142
- Ok = 7000 ,
143
- Io = 7001 ,
144
- NullParameter = 7002 ,
145
- InvalidDnsNameError = 7003 ,
146
- Panic = 7004 ,
147
- CertificateParseError = 7005 ,
148
- PrivateKeyParseError = 7006 ,
149
- InsufficientSize = 7007 ,
150
- NotFound = 7008 ,
151
- InvalidParameter = 7009 ,
152
- UnexpectedEof = 7010 ,
153
- PlaintextEmpty = 7011 ,
154
- AcceptorNotReady = 7012 ,
155
- AlreadyUsed = 7013 ,
156
-
157
- // From https://docs.rs/rustls/latest/rustls/enum.Error.html
158
- NoCertificatesPresented = 7101 ,
159
- DecryptError = 7102 ,
160
- FailedToGetCurrentTime = 7103 ,
161
- FailedToGetRandomBytes = 7113 ,
162
- HandshakeNotComplete = 7104 ,
163
- PeerSentOversizedRecord = 7105 ,
164
- NoApplicationProtocol = 7106 ,
165
- BadMaxFragmentSize = 7114 ,
166
- UnsupportedNameType = 7115 ,
167
- EncryptError = 7116 ,
168
-
169
- // Reserved from previous use pre rustls-ffi <0.21.0
170
- // CorruptMessage = 7100,
171
- // CorruptMessagePayload = 7111,
172
- // CertInvalidEncoding = 7117,
173
- // CertInvalidSignatureType = 7118,
174
- // CertInvalidSignature = 7119,
175
- // CertInvalidData = 7120,
176
-
177
- // From InvalidCertificate, with fields that get flattened.
178
- // https://docs.rs/rustls/0.21.0/rustls/enum.Error.html#variant.InvalidCertificate
179
- CertEncodingBad = 7121 ,
180
- CertExpired = 7122 ,
181
- CertNotYetValid = 7123 ,
182
- CertRevoked = 7124 ,
183
- CertUnhandledCriticalExtension = 7125 ,
184
- CertUnknownIssuer = 7126 ,
185
- CertBadSignature = 7127 ,
186
- CertNotValidForName = 7128 ,
187
- CertInvalidPurpose = 7129 ,
188
- CertApplicationVerificationFailure = 7130 ,
189
- CertOtherError = 7131 ,
190
-
191
- // From InvalidMessage, with fields that get flattened.
192
- // https://docs.rs/rustls/0.21.0/rustls/enum.Error.html#variant.InvalidMessage
193
- MessageHandshakePayloadTooLarge = 7133 ,
194
- MessageInvalidCcs = 7134 ,
195
- MessageInvalidContentType = 7135 ,
196
- MessageInvalidCertStatusType = 7136 ,
197
- MessageInvalidCertRequest = 7137 ,
198
- MessageInvalidDhParams = 7138 ,
199
- MessageInvalidEmptyPayload = 7139 ,
200
- MessageInvalidKeyUpdate = 7140 ,
201
- MessageInvalidServerName = 7141 ,
202
- MessageTooLarge = 7142 ,
203
- MessageTooShort = 7143 ,
204
- MessageMissingData = 7144 ,
205
- MessageMissingKeyExchange = 7145 ,
206
- MessageNoSignatureSchemes = 7146 ,
207
- MessageTrailingData = 7147 ,
208
- MessageUnexpectedMessage = 7148 ,
209
- MessageUnknownProtocolVersion = 7149 ,
210
- MessageUnsupportedCompression = 7150 ,
211
- MessageUnsupportedCurveType = 7151 ,
212
- MessageUnsupportedKeyExchangeAlgorithm = 7152 ,
213
- MessageInvalidOther = 7153 , // Last added.
214
-
215
- // From Error, with fields that get dropped.
216
- PeerIncompatibleError = 7107 ,
217
- PeerMisbehavedError = 7108 ,
218
- InappropriateMessage = 7109 ,
219
- InappropriateHandshakeMessage = 7110 ,
220
- General = 7112 ,
221
-
222
- // From Error, with fields that get flattened.
223
- // https://docs.rs/rustls/latest/rustls/internal/msgs/enums/enum.AlertDescription.html
224
- AlertCloseNotify = 7200 ,
225
- AlertUnexpectedMessage = 7201 ,
226
- AlertBadRecordMac = 7202 ,
227
- AlertDecryptionFailed = 7203 ,
228
- AlertRecordOverflow = 7204 ,
229
- AlertDecompressionFailure = 7205 ,
230
- AlertHandshakeFailure = 7206 ,
231
- AlertNoCertificate = 7207 ,
232
- AlertBadCertificate = 7208 ,
233
- AlertUnsupportedCertificate = 7209 ,
234
- AlertCertificateRevoked = 7210 ,
235
- AlertCertificateExpired = 7211 ,
236
- AlertCertificateUnknown = 7212 ,
237
- AlertIllegalParameter = 7213 ,
238
- AlertUnknownCA = 7214 ,
239
- AlertAccessDenied = 7215 ,
240
- AlertDecodeError = 7216 ,
241
- AlertDecryptError = 7217 ,
242
- AlertExportRestriction = 7218 ,
243
- AlertProtocolVersion = 7219 ,
244
- AlertInsufficientSecurity = 7220 ,
245
- AlertInternalError = 7221 ,
246
- AlertInappropriateFallback = 7222 ,
247
- AlertUserCanceled = 7223 ,
248
- AlertNoRenegotiation = 7224 ,
249
- AlertMissingExtension = 7225 ,
250
- AlertUnsupportedExtension = 7226 ,
251
- AlertCertificateUnobtainable = 7227 ,
252
- AlertUnrecognisedName = 7228 ,
253
- AlertBadCertificateStatusResponse = 7229 ,
254
- AlertBadCertificateHashValue = 7230 ,
255
- AlertUnknownPSKIdentity = 7231 ,
256
- AlertCertificateRequired = 7232 ,
257
- AlertNoApplicationProtocol = 7233 ,
258
- AlertUnknown = 7234 ,
259
-
260
- // https://docs.rs/sct/latest/sct/enum.Error.html
261
- CertSCTMalformed = 7319 ,
262
- CertSCTInvalidSignature = 7320 ,
263
- CertSCTTimestampInFuture = 7321 ,
264
- CertSCTUnsupportedVersion = 7322 ,
265
- CertSCTUnknownLog = 7323 ,
266
- }
267
-
268
293
pub ( crate ) fn map_error ( input : rustls:: Error ) -> rustls_result {
269
294
use rustls:: AlertDescription as alert;
270
295
use rustls_result:: * ;
0 commit comments