1
1
use std:: { borrow:: Cow , convert:: TryFrom , str} ;
2
2
3
- const PP2_TYPE_ALPN : u8 = 0x01 ;
4
- const PP2_TYPE_AUTHORITY : u8 = 0x02 ;
3
+ const PP2_TYPE_ALPN : u8 = 0x01 ; // done
4
+ const PP2_TYPE_AUTHORITY : u8 = 0x02 ; // done
5
5
const PP2_TYPE_CRC32C : u8 = 0x03 ; // done
6
6
const PP2_TYPE_NOOP : u8 = 0x04 ; // done
7
7
const PP2_TYPE_UNIQUE_ID : u8 = 0x05 ; // done
@@ -100,7 +100,7 @@ impl Tlv for Authority {
100
100
}
101
101
102
102
fn value_bytes ( & self ) -> Cow < ' _ , [ u8 ] > {
103
- Cow :: Borrowed ( & self . authority . as_bytes ( ) )
103
+ Cow :: Borrowed ( self . authority . as_bytes ( ) )
104
104
}
105
105
}
106
106
@@ -178,11 +178,15 @@ impl UniqueId {
178
178
///
179
179
///
180
180
/// # Panics
181
- /// Panics if `value` is empty (i.e., has length of 0) .
181
+ /// Panics if `value` is 0 bytes or larger than 128 bytes .
182
182
pub fn new ( id : impl Into < Vec < u8 > > ) -> Self {
183
183
let value = id. into ( ) ;
184
184
185
185
assert ! ( !value. is_empty( ) , "UniqueId TLV `value` cannot be empty" ) ;
186
+ assert ! (
187
+ value. len( ) < 128 ,
188
+ "UniqueId TLV `value` cannot be larger than 128 bytes"
189
+ ) ;
186
190
187
191
Self { value }
188
192
}
@@ -202,6 +206,67 @@ impl Tlv for UniqueId {
202
206
}
203
207
}
204
208
209
+ bitflags:: bitflags! {
210
+ #[ derive( Debug , Clone , PartialEq , Eq ) ]
211
+ struct SslClientFlags : u8 {
212
+ const PP2_CLIENT_SSL = 0x01 ;
213
+ const PP2_CLIENT_CERT_CONN = 0x02 ;
214
+ const PP2_CLIENT_CERT_SESS = 0x04 ;
215
+ }
216
+ }
217
+
218
+ /// TLS (SSL).
219
+ ///
220
+ /// Heckin broken atm.
221
+ #[ derive( Debug , Clone , PartialEq , Eq ) ]
222
+ pub struct Ssl {
223
+ /// The <client> field is made of a bit field indicating which element is present.
224
+ ///
225
+ /// Note, that each of these elements may lead to extra data being appended to
226
+ /// this TLV using a second level of TLV encapsulation. It is thus possible to
227
+ /// find multiple TLV values after this field. The total length of the pp2_tlv_ssl
228
+ /// TLV will reflect this.
229
+ client : SslClientFlags ,
230
+
231
+ /// The <verify> field will be zero if the client presented a certificate
232
+ /// and it was successfully verified, and non-zero otherwise.
233
+ verify : bool ,
234
+
235
+ /// Sub-TLVs.
236
+ tlvs : Vec < SslTlv > ,
237
+ }
238
+
239
+ impl Tlv for Ssl {
240
+ const TYPE : u8 = PP2_TYPE_SSL ;
241
+
242
+ fn try_from_value ( value : & [ u8 ] ) -> Option < Self > {
243
+ /// The PP2_CLIENT_SSL flag indicates that the client connected over SSL/TLS. When
244
+ /// this field is present, the US-ASCII string representation of the TLS version is
245
+ /// appended at the end of the field in the TLV format using the type
246
+ /// PP2_SUBTYPE_SSL_VERSION.
247
+ const PP2_CLIENT_SSL : u8 = 0x01 ;
248
+
249
+ /// PP2_CLIENT_CERT_CONN indicates that the client provided a certificate over the
250
+ /// current connection.
251
+ const PP2_CLIENT_CERT_CONN : u8 = 0x02 ;
252
+
253
+ /// PP2_CLIENT_CERT_SESS indicates that the client provided a
254
+ /// certificate at least once over the TLS session this connection belongs to.
255
+ const PP2_CLIENT_CERT_SESS : u8 = 0x04 ;
256
+
257
+ // TODO: finish parsing
258
+
259
+ None
260
+ }
261
+
262
+ fn value_bytes ( & self ) -> Cow < ' _ , [ u8 ] > {
263
+ Cow :: Borrowed ( & [ ] )
264
+ }
265
+ }
266
+
267
+ #[ derive( Debug , Clone , PartialEq , Eq ) ]
268
+ struct SslTlv { }
269
+
205
270
#[ cfg( test) ]
206
271
mod tests {
207
272
use super :: * ;
0 commit comments