-
Notifications
You must be signed in to change notification settings - Fork 662
Expand file tree
/
Copy pathconfig.rs
More file actions
532 lines (486 loc) · 19.7 KB
/
config.rs
File metadata and controls
532 lines (486 loc) · 19.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
use crate::ffi::{QUIC_CREDENTIAL_CONFIG, QUIC_REGISTRATION_CONFIG};
use std::ffi::CString;
/// Specifies the configuration for a new registration.
#[derive(Debug, Default)]
pub struct RegistrationConfig {
app_name: Option<CString>,
execution_profile: ExecutionProfile,
}
impl RegistrationConfig {
/// # Safety
/// ffi type returned needs to have the lifetime of self.
pub(crate) unsafe fn as_ffi(&self) -> QUIC_REGISTRATION_CONFIG {
QUIC_REGISTRATION_CONFIG {
AppName: self
.app_name
.as_ref()
.map(|s| s.as_ptr())
.unwrap_or(std::ptr::null()),
ExecutionProfile: self.execution_profile.clone().into(),
}
}
pub fn new() -> Self {
Self::default()
}
pub fn set_app_name(mut self, value: String) -> Self {
self.app_name = Some(CString::new(value).unwrap());
self
}
pub fn set_execution_profile(mut self, value: ExecutionProfile) -> Self {
self.execution_profile = value;
self
}
}
/// Configures how to process a registration's workload.
#[derive(Debug, PartialEq, Clone, Default)]
pub enum ExecutionProfile {
#[default]
LowLatency,
MaxThroughput,
Scavenger,
RealTime,
}
impl From<ExecutionProfile> for crate::ffi::QUIC_EXECUTION_PROFILE {
fn from(value: ExecutionProfile) -> Self {
match value {
ExecutionProfile::LowLatency => {
crate::ffi::QUIC_EXECUTION_PROFILE_QUIC_EXECUTION_PROFILE_LOW_LATENCY
}
ExecutionProfile::MaxThroughput => {
crate::ffi::QUIC_EXECUTION_PROFILE_QUIC_EXECUTION_PROFILE_TYPE_MAX_THROUGHPUT
}
ExecutionProfile::Scavenger => {
crate::ffi::QUIC_EXECUTION_PROFILE_QUIC_EXECUTION_PROFILE_TYPE_SCAVENGER
}
ExecutionProfile::RealTime => {
crate::ffi::QUIC_EXECUTION_PROFILE_QUIC_EXECUTION_PROFILE_TYPE_REAL_TIME
}
}
}
}
#[derive(Debug, Default)]
pub struct CredentialConfig {
credential_flags: CredentialFlags,
credential: Credential,
principal: Option<CString>, // TODO: support async handler.
allowed_cipher_suites: AllowedCipherSuiteFlags,
ca_certificate_file: Option<CString>,
}
impl CredentialConfig {
pub fn new() -> Self {
Self::default()
}
/// flags are additive when called multiple times.
pub fn set_credential_flags(mut self, value: CredentialFlags) -> Self {
self.credential_flags |= value;
self
}
pub fn set_credential(mut self, value: Credential) -> Self {
self.credential = value;
self
}
pub fn set_principal(mut self, value: String) -> Self {
self.principal = Some(CString::new(value).unwrap());
self
}
pub fn set_allowed_cipher_suites(mut self, value: AllowedCipherSuiteFlags) -> Self {
self.credential_flags |= CredentialFlags::SET_ALLOWED_CIPHER_SUITES;
self.allowed_cipher_suites = value;
self
}
pub fn set_ca_certificate_file(mut self, value: String) -> Self {
self.credential_flags |= CredentialFlags::SET_CA_CERTIFICATE_FILE;
self.ca_certificate_file = Some(CString::new(value).unwrap());
self
}
/// # Safety
/// ffi type returned needs to have the lifetime of self.
pub(crate) unsafe fn as_ffi(&self) -> QUIC_CREDENTIAL_CONFIG {
let mut ffi_cfg = unsafe { std::mem::zeroed::<QUIC_CREDENTIAL_CONFIG>() };
ffi_cfg.Flags = self.credential_flags.bits();
match &self.credential {
Credential::None => {}
Credential::CertificateHash(hash) => {
ffi_cfg.Type =
crate::ffi::QUIC_CREDENTIAL_TYPE_QUIC_CREDENTIAL_TYPE_CERTIFICATE_HASH;
ffi_cfg.__bindgen_anon_1.CertificateHash = (&hash.0) as *const _ as *mut _;
}
Credential::CertificateHashStore(hash) => {
ffi_cfg.Type =
crate::ffi::QUIC_CREDENTIAL_TYPE_QUIC_CREDENTIAL_TYPE_CERTIFICATE_HASH_STORE;
ffi_cfg.__bindgen_anon_1.CertificateHashStore = (&hash.0) as *const _ as *mut _;
}
Credential::CertificateContext(ctx) => {
ffi_cfg.Type =
crate::ffi::QUIC_CREDENTIAL_TYPE_QUIC_CREDENTIAL_TYPE_CERTIFICATE_CONTEXT;
ffi_cfg.__bindgen_anon_1.CertificateContext = *ctx as *mut _;
}
Credential::CertificateFile(file) => {
ffi_cfg.Type =
crate::ffi::QUIC_CREDENTIAL_TYPE_QUIC_CREDENTIAL_TYPE_CERTIFICATE_FILE;
ffi_cfg.__bindgen_anon_1.CertificateFile = file.as_ffi_ref() as *const _ as *mut _;
}
Credential::CertificateFileProtected(file) => {
ffi_cfg.Type = crate::ffi::QUIC_CREDENTIAL_TYPE_QUIC_CREDENTIAL_TYPE_CERTIFICATE_FILE_PROTECTED;
ffi_cfg.__bindgen_anon_1.CertificateFile = file.as_ffi_ref() as *const _ as *mut _;
}
Credential::CertificatePkcs12(cert) => {
ffi_cfg.Type =
crate::ffi::QUIC_CREDENTIAL_TYPE_QUIC_CREDENTIAL_TYPE_CERTIFICATE_PKCS12;
ffi_cfg.__bindgen_anon_1.CertificatePkcs12 =
cert.as_ffi_ref() as *const _ as *mut _;
}
}
ffi_cfg.Principal = self
.principal
.as_ref()
.map(|s| s.as_ptr())
.unwrap_or(std::ptr::null());
ffi_cfg.AllowedCipherSuites = self.allowed_cipher_suites.bits();
ffi_cfg.CaCertificateFile = self
.ca_certificate_file
.as_ref()
.map(|s| s.as_ptr())
.unwrap_or(std::ptr::null());
ffi_cfg
}
pub fn new_client() -> Self {
Self::default()
.set_credential_flags(CredentialFlags::CLIENT)
.set_credential(Credential::None)
}
}
#[derive(Debug)]
pub struct CertificateHash(crate::ffi::QUIC_CERTIFICATE_HASH);
impl CertificateHash {
pub fn new(hash: [u8; 20usize]) -> Self {
Self(crate::ffi::QUIC_CERTIFICATE_HASH { ShaHash: hash })
}
/// Construct from string hash.
#[allow(clippy::should_implement_trait)]
pub fn from_str(s: &str) -> Result<Self, crate::Status> {
Ok(Self::new(Self::decode_hex(s)?))
}
/// To hex string
pub fn to_hex_string(&self) -> String {
use std::fmt::Write;
// write every byte in hex.
self.0.ShaHash.iter().fold(String::new(), |mut out, x| {
write!(out, "{x:02X}").unwrap();
out
})
}
/// Helper function to convert hex string of hash into the hash bytes.
fn decode_hex(s: &str) -> Result<[u8; 20usize], crate::Status> {
let mut buff = [0_u8; 20usize];
if s.len() != buff.len() * 2 {
return Err(crate::StatusCode::QUIC_STATUS_INVALID_PARAMETER.into());
}
// Parse every 2 bytes and fill the buffer.
(0..s.len())
.step_by(2)
.map(|i| u8::from_str_radix(&s[i..i + 2], 16))
.zip(buff.iter_mut())
.try_for_each(|(b, df)| match b {
Ok(data) => {
*df = data;
Ok(())
}
Err(_) => Err(crate::StatusCode::QUIC_STATUS_INVALID_PARAMETER),
})?;
Ok(buff)
}
}
// QUIC_CERTIFICATE_HASH_STORE
#[derive(Debug)]
pub struct CertificateHashStore(crate::ffi::QUIC_CERTIFICATE_HASH_STORE);
impl CertificateHashStore {
pub fn new(flags: CertificateHashStoreFlags, hash: [u8; 20], store_name: String) -> Self {
// prepare slice with nul terminator
let c_str = CString::new(store_name).unwrap();
let c_slice = c_str.as_bytes_with_nul();
let c_slice2 =
unsafe { std::slice::from_raw_parts(c_slice.as_ptr() as *const i8, c_slice.len()) };
// copy with nul terminator
let mut name_buff = [0_i8; 128];
let chunk = &mut name_buff[..c_slice2.len()];
chunk.copy_from_slice(c_slice2);
Self(crate::ffi::QUIC_CERTIFICATE_HASH_STORE {
Flags: flags.bits(),
ShaHash: hash,
StoreName: name_buff,
})
}
}
bitflags::bitflags! {
/// Modifies the default credential configuration.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct CertificateHashStoreFlags: crate::ffi::QUIC_CERTIFICATE_HASH_STORE_FLAGS {
const NONE = crate::ffi::QUIC_CERTIFICATE_HASH_STORE_FLAGS_QUIC_CERTIFICATE_HASH_STORE_FLAG_NONE;
const MACHINE_STORE = crate::ffi::QUIC_CERTIFICATE_HASH_STORE_FLAGS_QUIC_CERTIFICATE_HASH_STORE_FLAG_MACHINE_STORE;
}
}
#[derive(Debug)]
pub struct CertificateFile {
raw: crate::ffi::QUIC_CERTIFICATE_FILE,
_private_key_file: CString,
_certificate_file: CString,
}
impl CertificateFile {
pub fn new(private_key_file: String, certificate_file: String) -> Self {
let key = CString::new(private_key_file).unwrap();
let cert = CString::new(certificate_file).unwrap();
Self {
raw: crate::ffi::QUIC_CERTIFICATE_FILE {
PrivateKeyFile: key.as_ptr(),
CertificateFile: cert.as_ptr(),
},
_private_key_file: key,
_certificate_file: cert,
}
}
pub fn as_ffi_ref(&self) -> &crate::ffi::QUIC_CERTIFICATE_FILE {
&self.raw
}
}
#[derive(Debug)]
pub struct CertificateFileProtected {
raw: crate::ffi::QUIC_CERTIFICATE_FILE_PROTECTED,
_private_key_file: CString,
_certificate_file: CString,
_private_key_password: CString,
}
impl CertificateFileProtected {
pub fn new(
private_key_file: String,
certificate_file: String,
private_key_password: String,
) -> Self {
let key = CString::new(private_key_file).unwrap();
let cert = CString::new(certificate_file).unwrap();
let pwd = CString::new(private_key_password).unwrap();
Self {
raw: crate::ffi::QUIC_CERTIFICATE_FILE_PROTECTED {
PrivateKeyFile: key.as_ptr(),
CertificateFile: cert.as_ptr(),
PrivateKeyPassword: pwd.as_ptr(),
},
_private_key_file: key,
_certificate_file: cert,
_private_key_password: pwd,
}
}
pub fn as_ffi_ref(&self) -> &crate::ffi::QUIC_CERTIFICATE_FILE_PROTECTED {
&self.raw
}
}
#[derive(Debug)]
pub struct CertificatePkcs12 {
raw: crate::ffi::QUIC_CERTIFICATE_PKCS12,
_asn1_blob: Vec<u8>,
_private_key_password: Option<CString>,
}
impl CertificatePkcs12 {
pub fn new(asn1_blob: Vec<u8>, private_key_password: Option<CString>) -> Self {
Self {
raw: crate::ffi::QUIC_CERTIFICATE_PKCS12 {
Asn1Blob: asn1_blob.as_ptr(),
Asn1BlobLength: asn1_blob.len() as u32,
PrivateKeyPassword: private_key_password
.as_ref()
.map(|p| p.as_ptr())
.unwrap_or(std::ptr::null()),
},
_asn1_blob: asn1_blob,
_private_key_password: private_key_password,
}
}
pub fn as_ffi_ref(&self) -> &crate::ffi::QUIC_CERTIFICATE_PKCS12 {
&self.raw
}
}
/// Type of credentials used for a connection.
#[derive(Debug, Default)]
pub enum Credential {
#[default]
None,
/// windows schannel only
CertificateHash(CertificateHash),
/// windows schannel only
CertificateHashStore(CertificateHashStore),
/// windows user mode only
CertificateContext(*const crate::ffi::QUIC_CERTIFICATE),
/// quictls only
CertificateFile(CertificateFile),
/// quictls only
CertificateFileProtected(CertificateFileProtected),
/// quictls only
CertificatePkcs12(CertificatePkcs12),
}
bitflags::bitflags! {
/// Modifies the default credential configuration.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct CredentialFlags: crate::ffi::QUIC_CREDENTIAL_FLAGS {
const NONE = crate::ffi::QUIC_CREDENTIAL_FLAGS_QUIC_CREDENTIAL_FLAG_NONE;
const CLIENT = crate::ffi::QUIC_CREDENTIAL_FLAGS_QUIC_CREDENTIAL_FLAG_CLIENT;
const LOAD_ASYNCHRONOUS = crate::ffi::QUIC_CREDENTIAL_FLAGS_QUIC_CREDENTIAL_FLAG_LOAD_ASYNCHRONOUS;
const NO_CERTIFICATE_VALIDATION = crate::ffi::QUIC_CREDENTIAL_FLAGS_QUIC_CREDENTIAL_FLAG_NO_CERTIFICATE_VALIDATION;
const ENABLE_OCSP = crate::ffi::QUIC_CREDENTIAL_FLAGS_QUIC_CREDENTIAL_FLAG_ENABLE_OCSP;
const INDICATE_CERTIFICATE_RECEIVED = crate::ffi::QUIC_CREDENTIAL_FLAGS_QUIC_CREDENTIAL_FLAG_INDICATE_CERTIFICATE_RECEIVED;
const DEFER_CERTIFICATE_VALIDATION = crate::ffi::QUIC_CREDENTIAL_FLAGS_QUIC_CREDENTIAL_FLAG_DEFER_CERTIFICATE_VALIDATION;
const REQUIRE_CLIENT_AUTHENTICATION = crate::ffi::QUIC_CREDENTIAL_FLAGS_QUIC_CREDENTIAL_FLAG_REQUIRE_CLIENT_AUTHENTICATION;
const USE_TLS_BUILTIN_CERTIFICATE_VALIDATION = crate::ffi::QUIC_CREDENTIAL_FLAGS_QUIC_CREDENTIAL_FLAG_USE_TLS_BUILTIN_CERTIFICATE_VALIDATION;
const REVOCATION_CHECK_END_CERT = crate::ffi::QUIC_CREDENTIAL_FLAGS_QUIC_CREDENTIAL_FLAG_REVOCATION_CHECK_END_CERT;
const REVOCATION_CHECK_CHAIN = crate::ffi::QUIC_CREDENTIAL_FLAGS_QUIC_CREDENTIAL_FLAG_REVOCATION_CHECK_CHAIN;
const REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT = crate::ffi::QUIC_CREDENTIAL_FLAGS_QUIC_CREDENTIAL_FLAG_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT;
const IGNORE_NO_REVOCATION_CHECK = crate::ffi::QUIC_CREDENTIAL_FLAGS_QUIC_CREDENTIAL_FLAG_IGNORE_NO_REVOCATION_CHECK;
const IGNORE_REVOCATION_OFFLINE = crate::ffi::QUIC_CREDENTIAL_FLAGS_QUIC_CREDENTIAL_FLAG_IGNORE_REVOCATION_OFFLINE;
const SET_ALLOWED_CIPHER_SUITES = crate::ffi::QUIC_CREDENTIAL_FLAGS_QUIC_CREDENTIAL_FLAG_SET_ALLOWED_CIPHER_SUITES;
const USE_PORTABLE_CERTIFICATES = crate::ffi::QUIC_CREDENTIAL_FLAGS_QUIC_CREDENTIAL_FLAG_USE_PORTABLE_CERTIFICATES;
const USE_SUPPLIED_CREDENTIALS = crate::ffi::QUIC_CREDENTIAL_FLAGS_QUIC_CREDENTIAL_FLAG_USE_SUPPLIED_CREDENTIALS;
const USE_SYSTEM_MAPPER = crate::ffi::QUIC_CREDENTIAL_FLAGS_QUIC_CREDENTIAL_FLAG_USE_SYSTEM_MAPPER;
const CACHE_ONLY_URL_RETRIEVAL = crate::ffi::QUIC_CREDENTIAL_FLAGS_QUIC_CREDENTIAL_FLAG_CACHE_ONLY_URL_RETRIEVAL;
const REVOCATION_CHECK_CACHE_ONLY = crate::ffi::QUIC_CREDENTIAL_FLAGS_QUIC_CREDENTIAL_FLAG_REVOCATION_CHECK_CACHE_ONLY;
const INPROC_PEER_CERTIFICATE = crate::ffi::QUIC_CREDENTIAL_FLAGS_QUIC_CREDENTIAL_FLAG_INPROC_PEER_CERTIFICATE;
const SET_CA_CERTIFICATE_FILE = crate::ffi::QUIC_CREDENTIAL_FLAGS_QUIC_CREDENTIAL_FLAG_SET_CA_CERTIFICATE_FILE;
const DISABLE_AIA = crate::ffi::QUIC_CREDENTIAL_FLAGS_QUIC_CREDENTIAL_FLAG_DISABLE_AIA;
// reject undefined flags.
const _ = !0;
}
}
impl Default for CredentialFlags {
fn default() -> Self {
Self::NONE
}
}
bitflags::bitflags! {
/// Set of allowed TLS cipher suites.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct AllowedCipherSuiteFlags: crate::ffi::QUIC_ALLOWED_CIPHER_SUITE_FLAGS {
const NONE = crate::ffi::QUIC_ALLOWED_CIPHER_SUITE_FLAGS_QUIC_ALLOWED_CIPHER_SUITE_NONE;
const AES_128_GCM_SHA256 = crate::ffi::QUIC_ALLOWED_CIPHER_SUITE_FLAGS_QUIC_ALLOWED_CIPHER_SUITE_AES_128_GCM_SHA256;
const AES_256_GCM_SHA384 = crate::ffi::QUIC_ALLOWED_CIPHER_SUITE_FLAGS_QUIC_ALLOWED_CIPHER_SUITE_AES_256_GCM_SHA384;
const CHACHA20_POLY1305_SHA256 = crate::ffi::QUIC_ALLOWED_CIPHER_SUITE_FLAGS_QUIC_ALLOWED_CIPHER_SUITE_CHACHA20_POLY1305_SHA256;
// reject undefined flags.
const _ = !0;
}
}
impl Default for AllowedCipherSuiteFlags {
fn default() -> Self {
Self::NONE
}
}
// Disable macos because the ffi bindings is using linux
// for macos and it has error code mismatch.
#[cfg(not(target_os = "macos"))]
#[cfg(test)]
mod tests {
use crate::{
config::{
CertificateFile, CertificateHash, CertificateHashStore, CertificateHashStoreFlags,
Credential,
},
BufferRef, Configuration, Registration, RegistrationConfig, Settings, StatusCode,
};
use super::CredentialConfig;
#[test]
fn config_load() {
let registration = Registration::new(&RegistrationConfig::default()).unwrap();
let alpn = [BufferRef::from("h3")];
let configuration = Configuration::open(
®istration,
&alpn,
Some(
&Settings::new()
.set_PeerBidiStreamCount(100)
.set_PeerUnidiStreamCount(3),
),
)
.unwrap();
{
let cred_config =
CredentialConfig::new().set_credential_flags(super::CredentialFlags::NONE);
// server cred missing
assert_eq!(
configuration
.load_credential(&cred_config)
.unwrap_err()
.try_as_status_code()
.unwrap(),
StatusCode::QUIC_STATUS_INVALID_PARAMETER
);
// zero hash
let cred_config = cred_config
.set_credential(Credential::CertificateHash(CertificateHash::new([0; 20])));
let load_err = configuration
.load_credential(&cred_config)
.unwrap_err()
.try_as_status_code()
.unwrap();
if cfg!(windows) {
assert_eq!(load_err, StatusCode::QUIC_STATUS_NOT_FOUND);
} else {
assert_eq!(load_err, StatusCode::QUIC_STATUS_NOT_SUPPORTED);
}
// key and cert file not found
let cred_config = cred_config.set_credential(Credential::CertificateFile(
CertificateFile::new(String::from("./no_key"), String::from("./no_cert")),
));
let load_err = configuration
.load_credential(&cred_config)
.unwrap_err()
.try_as_status_code()
.unwrap();
if cfg!(windows)
&& !cfg!(feature = "openssl")
&& !cfg!(feature = "openssl_external")
&& !cfg!(feature = "quictls")
{
// schannel does not support load from file.
assert_eq!(load_err, StatusCode::QUIC_STATUS_NOT_SUPPORTED);
} else {
assert_eq!(load_err, StatusCode::QUIC_STATUS_TLS_ERROR);
}
// cert with empty hash store.
let cred_config = cred_config.set_credential(Credential::CertificateHashStore(
CertificateHashStore::new(
CertificateHashStoreFlags::MACHINE_STORE,
[0; 20],
String::from("MY"),
),
));
let load_err = configuration
.load_credential(&cred_config)
.unwrap_err()
.try_as_status_code()
.unwrap();
if cfg!(windows) {
assert_eq!(load_err, StatusCode::QUIC_STATUS_NOT_FOUND);
} else {
assert_eq!(load_err, StatusCode::QUIC_STATUS_NOT_SUPPORTED);
}
// empty context
let cred_config =
cred_config.set_credential(Credential::CertificateContext(std::ptr::null()));
let load_err = configuration
.load_credential(&cred_config)
.unwrap_err()
.try_as_status_code()
.unwrap();
if cfg!(windows) {
assert_eq!(load_err, StatusCode::QUIC_STATUS_INVALID_PARAMETER);
} else {
assert_eq!(load_err, StatusCode::QUIC_STATUS_NOT_SUPPORTED);
}
}
}
#[test]
fn hash_test() {
let hex_str = "0E31650DFB5283AB820E3735FD2B254A286F46B3";
let hash = CertificateHash::from_str(hex_str).expect("fail to convert hash");
let hex = hash.to_hex_string();
assert_eq!(hex_str, hex);
}
}