ferritls-rustls 0.9.1

rustls CryptoProvider adapter backed by ferritls-core (pure Rust)
Documentation
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
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
//! 证书/握手签名验证算法(rustls-webpki 经由
//! `rustls::crypto::WebPkiSupportedAlgorithms` 消费)。
//!
//! 注意:TLS 1.3 对每个 scheme 只取 `mapping` 的**第一个**算法,
//! TLS 1.2 会尝试全部——当前映射 1:1;若 M8 需要跨曲线容错
//! (同 scheme 兼容 P-256/P-384 验证器,rustls-rustcrypto 的做法),
//! 在此扩展即可。
//!
//! `public_key_alg_id()` / `signature_alg_id()` 的字节语义(pki-types
//! 1.15 实测,以 `src/data/alg-*.der` 与 rustls-webpki 的比对逻辑为准):
//! 返回 **AlgorithmIdentifier 的 SEQUENCE 内容**(即内层 TLV 序列,不带
//! 外层 `30 xx` 头)——webpki 用 `der::expect_tag` 剥掉外层后逐字节比对。
//! 注意与 RSA 相关的 NULL 参数是内容的一部分,必须保留:
//! - EC:公钥 = ecPublicKey OID + 命名曲线 OID;签名 = ecdsa-with-SHA*
//!   (RFC 5758:不带 NULL 参数);
//! - Ed25519:公钥/签名同 OID(1.3.101.112,无参数);
//! - RSA PKCS#1:公钥 = rsaEncryption + NULL;签名 = sha*WithRSA + NULL;
//! - RSA-PSS:公钥同 RSA;签名 = RSASSA-PSS OID + PSS 参数
//!   (RFC 4055:hash/MGF1-SHA*/salt=哈希长)。
//!
//! `verify_signature` 的 `public_key` 参数语义(rustls-webpki 0.103.x
//! `signed_data.rs` 实测):webpki 传入的是 **subjectPublicKey 的
//! BIT STRING 内容(key_value)**——即裸密钥本体(RSA = 裸
//! `RSAPublicKey` DER;EC = 未压缩 SEC1 点;Ed25519 = 32 字节裸
//! 公钥),**不含** SPKI/AlgorithmIdentifier 包装。ferritls-core
//! 的 `VerifyKey` 构造器即按该裸格式定义,此处直接透传。

use rustls::SignatureScheme;
use rustls::crypto::WebPkiSupportedAlgorithms;
use rustls::pki_types::{AlgorithmIdentifier, InvalidSignature, SignatureVerificationAlgorithm};

use ferritls_core::sign::{ecdsa, ed25519, rsa};

macro_rules! verifier {
    ($name:ident, $pk_alg_id:expr, $sig_alg_id:expr, $verify:expr, $doc:expr) => {
        #[doc = $doc]
        #[derive(Debug)]
        pub struct $name;

        impl SignatureVerificationAlgorithm for $name {
            fn verify_signature(
                &self,
                public_key: &[u8],
                message: &[u8],
                signature: &[u8],
            ) -> Result<(), InvalidSignature> {
                $verify(public_key, message, signature).map_err(|_| InvalidSignature)
            }

            fn public_key_alg_id(&self) -> AlgorithmIdentifier {
                AlgorithmIdentifier::from_slice($pk_alg_id)
            }

            fn signature_alg_id(&self) -> AlgorithmIdentifier {
                AlgorithmIdentifier::from_slice($sig_alg_id)
            }

            fn fips(&self) -> bool {
                // 认证前恒 false(lib.rs“fips() 语义”)。
                false
            }
        }
    };
}

// ---------------------------------------------------------------------------
// AlgorithmIdentifier 静态表(均为 SEQUENCE 内容,无外层 30 xx 头;
// 与 pki-types src/data/alg-*.der 逐字节一致)
// ---------------------------------------------------------------------------

/// ecPublicKey + prime256v1
const PK_EC_P256: &[u8] = &[
    0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d,
    0x03, 0x01, 0x07,
];
/// ecPublicKey + secp384r1
const PK_EC_P384: &[u8] = &[
    0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x22,
];
/// ecdsa-with-SHA256(无参数)
const SIG_ECDSA_SHA256: &[u8] = &[0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02];
/// ecdsa-with-SHA384(无参数)
const SIG_ECDSA_SHA384: &[u8] = &[0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x03];
/// Ed25519(公钥/签名同形)
const ID_ED25519: &[u8] = &[0x06, 0x03, 0x2b, 0x65, 0x70];
/// rsaEncryption + NULL
const PK_RSA: &[u8] = &[
    0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00,
];
/// sha256WithRSAEncryption + NULL
const SIG_RSA_PKCS1_SHA256: &[u8] = &[
    0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00,
];
/// sha384WithRSAEncryption + NULL
const SIG_RSA_PKCS1_SHA384: &[u8] = &[
    0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0c, 0x05, 0x00,
];
/// sha512WithRSAEncryption + NULL
const SIG_RSA_PKCS1_SHA512: &[u8] = &[
    0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0d, 0x05, 0x00,
];
/// RSASSA-PSS(SHA-256 / MGF1-SHA256 / salt 32):OID + 参数
const SIG_RSA_PSS_SHA256: &[u8] = &[
    0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0a, 0x30, 0x34, 0xa0, 0x0f, 0x30,
    0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0xa1, 0x1c,
    0x30, 0x1a, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x08, 0x30, 0x0d, 0x06,
    0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0xa2, 0x03, 0x02, 0x01,
    0x20,
];
/// RSASSA-PSS(SHA-384 / MGF1-SHA384 / salt 48)
const SIG_RSA_PSS_SHA384: &[u8] = &[
    0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0a, 0x30, 0x34, 0xa0, 0x0f, 0x30,
    0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02, 0x05, 0x00, 0xa1, 0x1c,
    0x30, 0x1a, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x08, 0x30, 0x0d, 0x06,
    0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02, 0x05, 0x00, 0xa2, 0x03, 0x02, 0x01,
    0x30,
];
/// RSASSA-PSS(SHA-512 / MGF1-SHA512 / salt 64)
const SIG_RSA_PSS_SHA512: &[u8] = &[
    0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0a, 0x30, 0x34, 0xa0, 0x0f, 0x30,
    0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x05, 0x00, 0xa1, 0x1c,
    0x30, 0x1a, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x08, 0x30, 0x0d, 0x06,
    0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x05, 0x00, 0xa2, 0x03, 0x02, 0x01,
    0x40,
];

fn v_ecdsa_p256(
    public_key: &[u8],
    message: &[u8],
    signature: &[u8],
) -> Result<(), ferritls_core::Error> {
    ecdsa::p256::VerifyKey::from_sec1_point(public_key)?.verify(message, signature)
}

fn v_ecdsa_p384(
    public_key: &[u8],
    message: &[u8],
    signature: &[u8],
) -> Result<(), ferritls_core::Error> {
    ecdsa::p384::VerifyKey::from_sec1_point(public_key)?.verify(message, signature)
}

fn v_ed25519(
    public_key: &[u8],
    message: &[u8],
    signature: &[u8],
) -> Result<(), ferritls_core::Error> {
    ed25519::VerifyKey::from_raw_bytes(public_key)?.verify(message, signature)
}

/// 解析裸 `RSAPublicKey` DER(webpki 传入的 key_value 格式)。
/// 解析失败统一归一化为 `InvalidSignature`,不区分密钥格式错误
/// 与签名验证失败。
fn v_rsa_pkcs1_256(
    public_key: &[u8],
    message: &[u8],
    signature: &[u8],
) -> Result<(), ferritls_core::Error> {
    rsa::VerifyKey::from_rsapublickey_der(public_key)?.verify_pkcs1v15(256, message, signature)
}

fn v_rsa_pkcs1_384(
    public_key: &[u8],
    message: &[u8],
    signature: &[u8],
) -> Result<(), ferritls_core::Error> {
    rsa::VerifyKey::from_rsapublickey_der(public_key)?.verify_pkcs1v15(384, message, signature)
}

fn v_rsa_pkcs1_512(
    public_key: &[u8],
    message: &[u8],
    signature: &[u8],
) -> Result<(), ferritls_core::Error> {
    rsa::VerifyKey::from_rsapublickey_der(public_key)?.verify_pkcs1v15(512, message, signature)
}

fn v_rsa_pss_256(
    public_key: &[u8],
    message: &[u8],
    signature: &[u8],
) -> Result<(), ferritls_core::Error> {
    rsa::VerifyKey::from_rsapublickey_der(public_key)?.verify_pss(256, message, signature)
}

fn v_rsa_pss_384(
    public_key: &[u8],
    message: &[u8],
    signature: &[u8],
) -> Result<(), ferritls_core::Error> {
    rsa::VerifyKey::from_rsapublickey_der(public_key)?.verify_pss(384, message, signature)
}

fn v_rsa_pss_512(
    public_key: &[u8],
    message: &[u8],
    signature: &[u8],
) -> Result<(), ferritls_core::Error> {
    rsa::VerifyKey::from_rsapublickey_der(public_key)?.verify_pss(512, message, signature)
}

verifier!(
    EcdsaP256Sha256,
    PK_EC_P256,
    SIG_ECDSA_SHA256,
    v_ecdsa_p256,
    "ECDSA P-256/SHA-256(批准)。"
);
verifier!(
    EcdsaP384Sha384,
    PK_EC_P384,
    SIG_ECDSA_SHA384,
    v_ecdsa_p384,
    "ECDSA P-384/SHA-384(批准)。"
);
verifier!(
    Ed25519,
    ID_ED25519,
    ID_ED25519,
    v_ed25519,
    "Ed25519(非批准)。"
);
verifier!(
    RsaPkcs1Sha256,
    PK_RSA,
    SIG_RSA_PKCS1_SHA256,
    v_rsa_pkcs1_256,
    "RSA PKCS#1 v1.5/SHA-256(批准;仅证书链验证遗留用途)。"
);
verifier!(
    RsaPkcs1Sha384,
    PK_RSA,
    SIG_RSA_PKCS1_SHA384,
    v_rsa_pkcs1_384,
    "RSA PKCS#1 v1.5/SHA-384(批准;遗留用途)。"
);
verifier!(
    RsaPkcs1Sha512,
    PK_RSA,
    SIG_RSA_PKCS1_SHA512,
    v_rsa_pkcs1_512,
    "RSA PKCS#1 v1.5/SHA-512(批准;遗留用途)。"
);
verifier!(
    RsaPssSha256,
    PK_RSA,
    SIG_RSA_PSS_SHA256,
    v_rsa_pss_256,
    "RSA-PSS/SHA-256(批准)。"
);
verifier!(
    RsaPssSha384,
    PK_RSA,
    SIG_RSA_PSS_SHA384,
    v_rsa_pss_384,
    "RSA-PSS/SHA-384(批准)。"
);
verifier!(
    RsaPssSha512,
    PK_RSA,
    SIG_RSA_PSS_SHA512,
    v_rsa_pss_512,
    "RSA-PSS/SHA-512(批准)。"
);

/// 供 `WebPkiSupportedAlgorithms::all` 使用的完整清单。
pub static ALL_VERIFIERS: &[&dyn SignatureVerificationAlgorithm] = &[
    &EcdsaP256Sha256,
    &EcdsaP384Sha384,
    &Ed25519,
    &RsaPkcs1Sha256,
    &RsaPkcs1Sha384,
    &RsaPkcs1Sha512,
    &RsaPssSha256,
    &RsaPssSha384,
    &RsaPssSha512,
];

/// scheme → 验证算法映射(TLS 1.3 只取各组首项)。
pub static SCHEME_MAP: &[(SignatureScheme, &[&dyn SignatureVerificationAlgorithm])] = &[
    (SignatureScheme::ECDSA_NISTP256_SHA256, &[&EcdsaP256Sha256]),
    (SignatureScheme::ECDSA_NISTP384_SHA384, &[&EcdsaP384Sha384]),
    (SignatureScheme::ED25519, &[&Ed25519]),
    (SignatureScheme::RSA_PKCS1_SHA256, &[&RsaPkcs1Sha256]),
    (SignatureScheme::RSA_PKCS1_SHA384, &[&RsaPkcs1Sha384]),
    (SignatureScheme::RSA_PKCS1_SHA512, &[&RsaPkcs1Sha512]),
    (SignatureScheme::RSA_PSS_SHA256, &[&RsaPssSha256]),
    (SignatureScheme::RSA_PSS_SHA384, &[&RsaPssSha384]),
    (SignatureScheme::RSA_PSS_SHA512, &[&RsaPssSha512]),
];

/// 默认(非批准模式)的 webpki 验证算法集。
pub static SUPPORTED_ALGORITHMS: WebPkiSupportedAlgorithms = WebPkiSupportedAlgorithms {
    all: ALL_VERIFIERS,
    mapping: SCHEME_MAP,
};

/// 批准模式的 webpki 验证算法集(无 Ed25519)。
pub static FIPS_SUPPORTED_ALGORITHMS: WebPkiSupportedAlgorithms = WebPkiSupportedAlgorithms {
    all: FIPS_ALL_VERIFIERS,
    mapping: FIPS_SCHEME_MAP,
};

static FIPS_ALL_VERIFIERS: &[&dyn SignatureVerificationAlgorithm] = &[
    &EcdsaP256Sha256,
    &EcdsaP384Sha384,
    &RsaPkcs1Sha256,
    &RsaPkcs1Sha384,
    &RsaPkcs1Sha512,
    &RsaPssSha256,
    &RsaPssSha384,
    &RsaPssSha512,
];

static FIPS_SCHEME_MAP: &[(SignatureScheme, &[&dyn SignatureVerificationAlgorithm])] = &[
    (SignatureScheme::ECDSA_NISTP256_SHA256, &[&EcdsaP256Sha256]),
    (SignatureScheme::ECDSA_NISTP384_SHA384, &[&EcdsaP384Sha384]),
    (SignatureScheme::RSA_PKCS1_SHA256, &[&RsaPkcs1Sha256]),
    (SignatureScheme::RSA_PKCS1_SHA384, &[&RsaPkcs1Sha384]),
    (SignatureScheme::RSA_PKCS1_SHA512, &[&RsaPkcs1Sha512]),
    (SignatureScheme::RSA_PSS_SHA256, &[&RsaPssSha256]),
    (SignatureScheme::RSA_PSS_SHA384, &[&RsaPssSha384]),
    (SignatureScheme::RSA_PSS_SHA512, &[&RsaPssSha512]),
];

// ---------------------------------------------------------------------------
// AlgorithmIdentifier 静态表锚定:webpki 用 `der::expect_tag` 剥外层
// SEQUENCE 后与 `public_key_alg_id()` / `signature_alg_id()` 的返回
// 逐字节比对(pki-types 1.15 本地实测语义),因此表内容必须与
// rustls-pki-types 的权威算法标识数据逐字节一致。
//
// 权威来源:rustls-pki-types 1.15.1 `src/data/alg-*.der`(该 crate 经
// `AlgorithmIdentifier::from_slice(include_bytes!(...))` 直接装载这些
// 文件为 `alg_id::*` 常量)。下方 hex 为开发期从上述文件 `xxd -p`
// 读出后录入(文件:版本见 Cargo.lock 锚定的 rustls-pki-types
// 1.15.1),并与 `rustls::pki_types::alg_id::*` 常量双重比对——两个
// 断言任一漂移都会被拦截。
// ---------------------------------------------------------------------------
#[cfg(test)]
mod alg_id_tests {
    use super::*;
    use rustls::pki_types::alg_id;

    /// 表常量 = 权威文件的逐字节 SEQUENCE 内容(无外层 30 xx 头)。
    #[test]
    fn alg_id_tables_match_pki_types_authority_files() {
        // 来源:rustls-pki-types 1.15.1 src/data/alg-ecdsa-p256.der
        assert_eq!(
            PK_EC_P256,
            &[
                0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48,
                0xce, 0x3d, 0x03, 0x01, 0x07,
            ][..],
        );
        // 来源:alg-ecdsa-p384.der
        assert_eq!(
            PK_EC_P384,
            &[
                0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x05, 0x2b, 0x81, 0x04,
                0x00, 0x22,
            ][..],
        );
        // 来源:alg-ecdsa-sha256.der
        assert_eq!(
            SIG_ECDSA_SHA256,
            &[0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02][..],
        );
        // 来源:alg-ecdsa-sha384.der
        assert_eq!(
            SIG_ECDSA_SHA384,
            &[0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x03][..],
        );
        // 来源:alg-ed25519.der
        assert_eq!(ID_ED25519, &[0x06, 0x03, 0x2b, 0x65, 0x70][..]);
        // 来源:alg-rsa-encryption.der(rsaEncryption + NULL 参数)
        assert_eq!(
            PK_RSA,
            &[
                0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00
            ][..],
        );
        // 来源:alg-rsa-pkcs1-sha256.der
        assert_eq!(
            SIG_RSA_PKCS1_SHA256,
            &[
                0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00
            ][..],
        );
        // 来源:alg-rsa-pkcs1-sha384.der
        assert_eq!(
            SIG_RSA_PKCS1_SHA384,
            &[
                0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0c, 0x05, 0x00
            ][..],
        );
        // 来源:alg-rsa-pkcs1-sha512.der
        assert_eq!(
            SIG_RSA_PKCS1_SHA512,
            &[
                0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0d, 0x05, 0x00
            ][..],
        );
        // 来源:alg-rsa-pss-sha256.der(RSASSA-PSS OID + RFC 4055 §3.1
        // 参数:SHA-256 / MGF1-SHA256 / salt 32)
        assert_eq!(
            SIG_RSA_PSS_SHA256,
            &[
                0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0a, 0x30, 0x34, 0xa0,
                0x0f, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01,
                0x05, 0x00, 0xa1, 0x1c, 0x30, 0x1a, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d,
                0x01, 0x01, 0x08, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04,
                0x02, 0x01, 0x05, 0x00, 0xa2, 0x03, 0x02, 0x01, 0x20,
            ][..],
        );
        // 来源:alg-rsa-pss-sha384.der(SHA-384 / MGF1-SHA384 / salt 48)
        assert_eq!(
            SIG_RSA_PSS_SHA384,
            &[
                0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0a, 0x30, 0x34, 0xa0,
                0x0f, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02,
                0x05, 0x00, 0xa1, 0x1c, 0x30, 0x1a, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d,
                0x01, 0x01, 0x08, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04,
                0x02, 0x02, 0x05, 0x00, 0xa2, 0x03, 0x02, 0x01, 0x30,
            ][..],
        );
        // 来源:alg-rsa-pss-sha512.der(SHA-512 / MGF1-SHA512 / salt 64)
        assert_eq!(
            SIG_RSA_PSS_SHA512,
            &[
                0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0a, 0x30, 0x34, 0xa0,
                0x0f, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03,
                0x05, 0x00, 0xa1, 0x1c, 0x30, 0x1a, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d,
                0x01, 0x01, 0x08, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04,
                0x02, 0x03, 0x05, 0x00, 0xa2, 0x03, 0x02, 0x01, 0x40,
            ][..],
        );
    }

    /// 每个 verifier 实例的 `public_key_alg_id()` / `signature_alg_id()`
    /// 必须逐字节等于对应静态表条目,且等于 pki-types 装载权威 .der
    /// 文件得到的 `alg_id::*` 常量(双重锚定,pki-types 升级若改动
    /// 权威数据即刻暴露)。
    #[test]
    fn verifier_alg_ids_match_tables_and_pki_types_constants() {
        use rustls::pki_types::SignatureVerificationAlgorithm as SVA;

        type VerifierCase = (
            &'static dyn SVA,
            &'static [u8],
            &'static [u8],
            AlgorithmIdentifier,
            AlgorithmIdentifier,
        );
        let cases: &[VerifierCase] = &[
            (
                &EcdsaP256Sha256,
                PK_EC_P256,
                SIG_ECDSA_SHA256,
                alg_id::ECDSA_P256,
                alg_id::ECDSA_SHA256,
            ),
            (
                &EcdsaP384Sha384,
                PK_EC_P384,
                SIG_ECDSA_SHA384,
                alg_id::ECDSA_P384,
                alg_id::ECDSA_SHA384,
            ),
            (
                &Ed25519,
                ID_ED25519,
                ID_ED25519,
                alg_id::ED25519,
                alg_id::ED25519,
            ),
            (
                &RsaPkcs1Sha256,
                PK_RSA,
                SIG_RSA_PKCS1_SHA256,
                alg_id::RSA_ENCRYPTION,
                alg_id::RSA_PKCS1_SHA256,
            ),
            (
                &RsaPkcs1Sha384,
                PK_RSA,
                SIG_RSA_PKCS1_SHA384,
                alg_id::RSA_ENCRYPTION,
                alg_id::RSA_PKCS1_SHA384,
            ),
            (
                &RsaPkcs1Sha512,
                PK_RSA,
                SIG_RSA_PKCS1_SHA512,
                alg_id::RSA_ENCRYPTION,
                alg_id::RSA_PKCS1_SHA512,
            ),
            (
                &RsaPssSha256,
                PK_RSA,
                SIG_RSA_PSS_SHA256,
                alg_id::RSA_ENCRYPTION,
                alg_id::RSA_PSS_SHA256,
            ),
            (
                &RsaPssSha384,
                PK_RSA,
                SIG_RSA_PSS_SHA384,
                alg_id::RSA_ENCRYPTION,
                alg_id::RSA_PSS_SHA384,
            ),
            (
                &RsaPssSha512,
                PK_RSA,
                SIG_RSA_PSS_SHA512,
                alg_id::RSA_ENCRYPTION,
                alg_id::RSA_PSS_SHA512,
            ),
        ];
        for (v, pk, sig, pk_const, sig_const) in cases {
            assert_eq!(
                v.public_key_alg_id().as_ref(),
                *pk,
                "{v:?} public_key_alg_id"
            );
            assert_eq!(
                v.signature_alg_id().as_ref(),
                *sig,
                "{v:?} signature_alg_id"
            );
            assert_eq!(
                v.public_key_alg_id(),
                *pk_const,
                "{v:?} public_key_alg_id vs pki-types 常量"
            );
            assert_eq!(
                v.signature_alg_id(),
                *sig_const,
                "{v:?} signature_alg_id vs pki-types 常量"
            );
        }
    }

    /// verifier 的 `fips()` 恒 false(规则 3:认证前;默认实现在
    /// pki-types 1.15 返回 false,此处显式锚定我们覆写后的语义)。
    #[test]
    fn verifier_fips_is_false_before_validation() {
        for v in ALL_VERIFIERS {
            assert!(!v.fips(), "认证前 fips() 恒 false");
        }
    }
}