openbao 1.0.1

Secure, typed, async Rust SDK for OpenBao
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
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
//! TLS certificate authentication support.

use core::fmt;
use std::collections::BTreeMap;

use reqwest::{Method, StatusCode};
use secrecy::SecretString;
use serde::{
    Deserialize, Deserializer, Serialize,
    de::{IgnoredAny, MapAccess, SeqAccess, Visitor},
};

use crate::{
    Authenticated, Client, Error, Result, Unauthenticated,
    path::validate_mount_path,
    response::{
        Empty, ListEntries, ListPageOptions, ResponseEnvelope,
        deserialize_bounded_string_map_or_default,
    },
};

/// Handle for TLS certificate auth login at a configured mount.
#[derive(Debug)]
pub struct CertAuth<'a> {
    client: &'a Client<Unauthenticated>,
    mount: String,
}

/// Handle for TLS certificate auth administration at a configured mount.
#[derive(Debug)]
pub struct CertAuthAdmin<'a> {
    client: &'a Client<Authenticated>,
    mount: String,
}

/// TLS certificate auth method configuration.
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct CertAuthConfig {
    /// Skips matching the renewed token to the certificate identity used at login.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub disable_binding: Option<bool>,
    /// Stores certificate metadata on the identity alias.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub enable_identity_alias_metadata: Option<bool>,
    /// OCSP response cache size for all configured certificates.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub ocsp_cache_size: Option<u64>,
}

/// CA certificate role configuration for the TLS certificate auth method.
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct CertRole {
    /// PEM-format CA certificate.
    #[serde(default, skip_serializing_if = "String::is_empty")]
    pub certificate: String,
    /// Deprecated combined name constraint.
    #[serde(default, skip_serializing_if = "String::is_empty")]
    pub allowed_names: String,
    /// Allowed Common Name patterns.
    #[serde(default, deserialize_with = "deserialize_bounded_string_or_vec")]
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub allowed_common_names: Vec<String>,
    /// Allowed DNS SAN patterns.
    #[serde(default, deserialize_with = "deserialize_bounded_string_or_vec")]
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub allowed_dns_sans: Vec<String>,
    /// Allowed email SAN patterns.
    #[serde(default, deserialize_with = "deserialize_bounded_string_or_vec")]
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub allowed_email_sans: Vec<String>,
    /// Allowed URI SAN patterns.
    #[serde(default, deserialize_with = "deserialize_bounded_string_or_vec")]
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub allowed_uri_sans: Vec<String>,
    /// Allowed organizational unit patterns.
    #[serde(default, deserialize_with = "deserialize_bounded_string_or_vec")]
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub allowed_organizational_units: Vec<String>,
    /// Required custom extension OID/value patterns.
    #[serde(default, deserialize_with = "deserialize_bounded_string_or_vec")]
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub required_extensions: Vec<String>,
    /// Metadata extension OIDs to copy into the auth alias.
    #[serde(default, deserialize_with = "deserialize_bounded_string_or_vec")]
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub allowed_metadata_extensions: Vec<String>,
    /// Enables OCSP revocation checks.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub ocsp_enabled: Option<bool>,
    /// Base64 encoded PEM CA certificates for OCSP response verification.
    #[serde(default, skip_serializing_if = "String::is_empty")]
    pub ocsp_ca_certificates: String,
    /// OCSP responder override URLs.
    #[serde(default, deserialize_with = "deserialize_bounded_string_or_vec")]
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub ocsp_servers_override: Vec<String>,
    /// Whether OCSP lookup errors should allow login to continue.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub ocsp_fail_open: Option<bool>,
    /// Requires all OCSP responders to agree.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub ocsp_query_all_servers: Option<bool>,
    /// Token display name.
    #[serde(default, skip_serializing_if = "String::is_empty")]
    pub display_name: String,
    /// Deprecated policy field.
    #[serde(default, deserialize_with = "deserialize_bounded_string_or_vec")]
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub policies: Vec<String>,
    /// Policies attached to generated tokens.
    #[serde(default, deserialize_with = "deserialize_bounded_string_or_vec")]
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub token_policies: Vec<String>,
    /// CIDR blocks allowed for login and token use.
    #[serde(default, deserialize_with = "deserialize_bounded_string_or_vec")]
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub token_bound_cidrs: Vec<String>,
    /// Bind the generated token to the source IP.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub token_strictly_bind_ip: Option<bool>,
    /// Token TTL such as `30m`.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub token_ttl: Option<String>,
    /// Token max TTL such as `2h`.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub token_max_ttl: Option<String>,
    /// Token explicit max TTL.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub token_explicit_max_ttl: Option<String>,
    /// Excludes the default policy from generated tokens.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub token_no_default_policy: Option<bool>,
    /// Maximum use count for generated tokens.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub token_num_uses: Option<u64>,
    /// Periodic token period.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub token_period: Option<String>,
    /// Generated token type.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub token_type: Option<String>,
}

impl CertRole {
    fn validate(&self) -> Result<()> {
        crate::validation::validate_cidr_list(
            &self.token_bound_cidrs,
            "cert auth token_bound_cidrs",
        )
    }
}

/// Certificate role list.
#[derive(Clone, Debug, Default, Deserialize)]
pub struct CertRoleList {
    /// Role names.
    #[serde(
        default,
        deserialize_with = "crate::response::deserialize_bounded_string_vec"
    )]
    pub keys: Vec<String>,
}

impl ListEntries for CertRoleList {
    fn entries(&self) -> &[String] {
        &self.keys
    }
}

/// CRL configuration for the TLS certificate auth method.
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct CertCrl {
    /// PEM-format CRL. If `crl` and `url` are both set, OpenBao uses `crl`.
    #[serde(default, skip_serializing_if = "String::is_empty")]
    pub crl: String,
    /// URL for a CRL distribution point.
    #[serde(default, skip_serializing_if = "String::is_empty")]
    pub url: String,
}

/// CRL name list.
#[derive(Clone, Debug, Default, Deserialize)]
pub struct CertCrlList {
    /// CRL names.
    #[serde(
        default,
        deserialize_with = "crate::response::deserialize_bounded_string_vec"
    )]
    pub keys: Vec<String>,
}

impl ListEntries for CertCrlList {
    fn entries(&self) -> &[String] {
        &self.keys
    }
}

/// CRL serial-number information.
#[derive(Clone, Debug, Default, Deserialize)]
pub struct CertCrlInfo {
    /// Revoked certificate serial numbers.
    #[serde(default, deserialize_with = "deserialize_bounded_serial_map")]
    pub serials: Vec<String>,
}

/// Metadata returned after a successful TLS certificate login.
#[derive(Debug, Deserialize)]
pub struct CertLoginMetadata {
    /// Token accessor. Accessors can revoke or look up token metadata, so they
    /// are treated as secret material when present.
    #[serde(default)]
    pub accessor: Option<SecretString>,
    /// Policies attached to the token.
    #[serde(
        default,
        deserialize_with = "crate::response::deserialize_bounded_string_vec"
    )]
    pub policies: Vec<String>,
    /// Token lease duration in seconds.
    #[serde(default)]
    pub lease_duration: u64,
    /// Whether the token is renewable.
    #[serde(default)]
    pub renewable: bool,
    /// Metadata returned by OpenBao for the certificate identity.
    #[serde(
        default,
        deserialize_with = "deserialize_bounded_string_map_or_default"
    )]
    pub metadata: BTreeMap<String, String>,
}

#[derive(Serialize)]
struct CertLoginRequest<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    name: Option<&'a str>,
}

#[derive(Deserialize)]
struct CertLoginResponse {
    auth: Option<CertLoginAuth>,
}

#[derive(Deserialize)]
struct CertLoginAuth {
    client_token: SecretString,
    #[serde(default)]
    accessor: Option<SecretString>,
    #[serde(
        default,
        deserialize_with = "crate::response::deserialize_bounded_string_vec"
    )]
    policies: Vec<String>,
    #[serde(default)]
    lease_duration: u64,
    #[serde(default)]
    renewable: bool,
    #[serde(
        default,
        deserialize_with = "deserialize_bounded_string_map_or_default"
    )]
    metadata: BTreeMap<String, String>,
}

impl Client<Unauthenticated> {
    /// Uses the TLS certificate auth method mounted at `auth/cert`.
    pub fn cert(&self) -> Result<CertAuth<'_>> {
        self.cert_at("cert")
    }

    /// Uses the TLS certificate auth method mounted at `auth/{mount}`.
    pub fn cert_at(&self, mount: impl Into<String>) -> Result<CertAuth<'_>> {
        Ok(CertAuth {
            client: self,
            mount: validate_mount_path(&mount.into())?.join("/"),
        })
    }

    /// Logs in with TLS certificate auth at `auth/cert`.
    ///
    /// The client configuration must include a mutual TLS client identity.
    pub async fn login_cert(
        self,
        role: Option<&str>,
    ) -> Result<(Client<Authenticated>, CertLoginMetadata)> {
        let response = self.cert()?.login_response(role).await?;
        let (token, metadata) = split_login_auth(response);
        Ok((self.try_with_token(token)?, metadata))
    }
}

impl Client<Authenticated> {
    /// Administers the TLS certificate auth method mounted at `auth/cert`.
    pub fn cert_admin(&self) -> Result<CertAuthAdmin<'_>> {
        self.cert_admin_at("cert")
    }

    /// Administers the TLS certificate auth method mounted at `auth/{mount}`.
    pub fn cert_admin_at(&self, mount: impl Into<String>) -> Result<CertAuthAdmin<'_>> {
        Ok(CertAuthAdmin {
            client: self,
            mount: validate_mount_path(&mount.into())?.join("/"),
        })
    }
}

impl CertAuth<'_> {
    /// Logs in and returns token metadata plus an authenticated client.
    ///
    /// The client configuration must include a mutual TLS client identity.
    pub async fn login(
        self,
        role: Option<&str>,
    ) -> Result<(Client<Authenticated>, CertLoginMetadata)> {
        let response = self.login_response(role).await?;
        let (token, metadata) = split_login_auth(response);
        Ok((
            self.client.clone_without_state().try_with_token(token)?,
            metadata,
        ))
    }

    async fn login_response(&self, role: Option<&str>) -> Result<CertLoginAuth> {
        let role = match role {
            Some(role) => Some(validate_mount_path(role)?.join("/")),
            None => None,
        };
        let request = CertLoginRequest {
            name: role.as_deref(),
        };
        let response: CertLoginResponse = self
            .client
            .request_json(
                Method::POST,
                &format!("auth/{}/login", self.mount),
                Some(&request),
            )
            .await?;
        response.auth.ok_or(Error::MissingField("auth"))
    }
}

impl CertAuthAdmin<'_> {
    /// Configures the TLS certificate auth method.
    pub async fn configure(&self, config: &CertAuthConfig) -> Result<Empty> {
        self.client
            .request_json(
                Method::POST,
                &format!("auth/{}/config", self.mount),
                Some(config),
            )
            .await
    }

    /// Creates or updates a CA certificate role.
    pub async fn write_role(&self, name: &str, role: &CertRole) -> Result<Empty> {
        role.validate()?;
        let name = validate_mount_path(name)?.join("/");
        self.client
            .request_json(
                Method::POST,
                &format!("auth/{}/certs/{name}", self.mount),
                Some(role),
            )
            .await
    }

    /// Reads a CA certificate role.
    pub async fn read_role(&self, name: &str) -> Result<CertRole> {
        let name = validate_mount_path(name)?.join("/");
        let envelope: ResponseEnvelope<CertRole> = self
            .client
            .request_json(
                Method::GET,
                &format!("auth/{}/certs/{name}", self.mount),
                Option::<&Empty>::None,
            )
            .await?;
        Ok(envelope.data)
    }

    /// Lists CA certificate role names.
    pub async fn list_roles(
        &self,
        after: Option<&str>,
        limit: Option<u64>,
    ) -> Result<CertRoleList> {
        let method =
            Method::from_bytes(b"LIST").map_err(|error| Error::InvalidHeader(error.to_string()))?;
        let query = ListPageOptions::from_after_limit(after, limit)?.query_pairs();
        let envelope: ResponseEnvelope<CertRoleList> = self
            .client
            .request_json_query_accepting(
                method,
                &format!("auth/{}/certs", self.mount),
                &query,
                Option::<&Empty>::None,
                &[StatusCode::OK],
            )
            .await?;
        Ok(envelope.data)
    }

    /// Deletes a CA certificate role.
    pub async fn delete_role(&self, name: &str) -> Result<Empty> {
        let name = validate_mount_path(name)?.join("/");
        self.client
            .request_json_accepting(
                Method::DELETE,
                &format!("auth/{}/certs/{name}", self.mount),
                Option::<&Empty>::None,
                &[StatusCode::OK, StatusCode::NO_CONTENT],
            )
            .await
    }

    /// Creates or updates a named CRL.
    pub async fn write_crl(&self, name: &str, crl: &CertCrl) -> Result<Empty> {
        let name = validate_mount_path(name)?.join("/");
        self.client
            .request_json(
                Method::POST,
                &format!("auth/{}/crls/{name}", self.mount),
                Some(crl),
            )
            .await
    }

    /// Reads CRL serial-number information.
    pub async fn read_crl(&self, name: &str) -> Result<CertCrlInfo> {
        let name = validate_mount_path(name)?.join("/");
        let envelope: ResponseEnvelope<CertCrlInfo> = self
            .client
            .request_json(
                Method::GET,
                &format!("auth/{}/crls/{name}", self.mount),
                Option::<&Empty>::None,
            )
            .await?;
        Ok(envelope.data)
    }

    /// Lists CRL names.
    pub async fn list_crls(&self, after: Option<&str>, limit: Option<u64>) -> Result<CertCrlList> {
        let method =
            Method::from_bytes(b"LIST").map_err(|error| Error::InvalidHeader(error.to_string()))?;
        let query = ListPageOptions::from_after_limit(after, limit)?.query_pairs();
        let envelope: ResponseEnvelope<CertCrlList> = self
            .client
            .request_json_query_accepting(
                method,
                &format!("auth/{}/crls", self.mount),
                &query,
                Option::<&Empty>::None,
                &[StatusCode::OK],
            )
            .await?;
        Ok(envelope.data)
    }

    /// Deletes a CRL.
    pub async fn delete_crl(&self, name: &str) -> Result<Empty> {
        let name = validate_mount_path(name)?.join("/");
        self.client
            .request_json_accepting(
                Method::DELETE,
                &format!("auth/{}/crls/{name}", self.mount),
                Option::<&Empty>::None,
                &[StatusCode::OK, StatusCode::NO_CONTENT],
            )
            .await
    }
}

fn split_login_auth(auth: CertLoginAuth) -> (SecretString, CertLoginMetadata) {
    let CertLoginAuth {
        client_token,
        accessor,
        policies,
        lease_duration,
        renewable,
        metadata,
    } = auth;
    let metadata = CertLoginMetadata {
        accessor,
        policies,
        lease_duration,
        renewable,
        metadata,
    };
    (client_token, metadata)
}

fn deserialize_bounded_string_or_vec<'de, D>(
    deserializer: D,
) -> core::result::Result<Vec<String>, D::Error>
where
    D: Deserializer<'de>,
{
    deserializer.deserialize_any(StringOrListVisitor::<{ crate::response::MAX_RESPONSE_STRINGS }>)
}

struct StringOrListVisitor<const MAX: usize>;

impl<'de, const MAX: usize> Visitor<'de> for StringOrListVisitor<MAX> {
    type Value = Vec<String>;

    fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(
            formatter,
            "a comma-separated string or a list of at most {MAX} strings"
        )
    }

    fn visit_unit<E>(self) -> core::result::Result<Self::Value, E>
    where
        E: serde::de::Error,
    {
        Ok(Vec::new())
    }

    fn visit_str<E>(self, value: &str) -> core::result::Result<Self::Value, E>
    where
        E: serde::de::Error,
    {
        if value.trim().is_empty() {
            return Ok(Vec::new());
        }
        let values: Vec<String> = value
            .split(',')
            .map(str::trim)
            .filter(|part| !part.is_empty())
            .map(str::to_owned)
            .collect();
        if values.len() > MAX {
            return Err(E::custom("OpenBao string list exceeds item limit"));
        }
        Ok(values)
    }

    fn visit_string<E>(self, value: String) -> core::result::Result<Self::Value, E>
    where
        E: serde::de::Error,
    {
        self.visit_str(&value)
    }

    fn visit_seq<A>(self, mut seq: A) -> core::result::Result<Self::Value, A::Error>
    where
        A: SeqAccess<'de>,
    {
        let mut values = Vec::new();
        while values.len() < MAX {
            let Some(value) = seq.next_element::<String>()? else {
                return Ok(values);
            };
            values.push(value);
        }
        if seq.next_element::<IgnoredAny>()?.is_some() {
            return Err(serde::de::Error::custom(
                "OpenBao string list exceeds item limit",
            ));
        }
        Ok(values)
    }
}

fn deserialize_bounded_serial_map<'de, D>(
    deserializer: D,
) -> core::result::Result<Vec<String>, D::Error>
where
    D: Deserializer<'de>,
{
    deserializer.deserialize_map(SerialMapVisitor::<{ crate::response::MAX_RESPONSE_STRINGS }>)
}

struct SerialMapVisitor<const MAX: usize>;

impl<'de, const MAX: usize> Visitor<'de> for SerialMapVisitor<MAX> {
    type Value = Vec<String>;

    fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(formatter, "a map of at most {MAX} certificate serials")
    }

    fn visit_map<A>(self, mut map: A) -> core::result::Result<Self::Value, A::Error>
    where
        A: MapAccess<'de>,
    {
        let mut serials = Vec::new();
        while serials.len() < MAX {
            let Some((serial, _value)) = map.next_entry::<String, IgnoredAny>()? else {
                return Ok(serials);
            };
            serials.push(serial);
        }
        if map.next_entry::<IgnoredAny, IgnoredAny>()?.is_some() {
            return Err(serde::de::Error::custom(
                "OpenBao CRL serial map exceeds item limit",
            ));
        }
        Ok(serials)
    }
}

#[cfg(test)]
mod tests {
    #![allow(clippy::panic)]

    use secrecy::{ExposeSecret, SecretString};

    use super::{CertCrlInfo, CertLoginResponse, CertRole, CertRoleList};

    #[test]
    fn cert_login_auth_deserializes_secret_token_fields() {
        let response: CertLoginResponse = serde_json::from_str(
            r#"{"auth":{"client_token":"token-value","accessor":"accessor-value","policies":["web"]}}"#,
        )
        .unwrap_or_else(|error| panic!("{error}"));
        let auth = response.auth.unwrap_or_else(|| panic!("auth missing"));

        assert_eq!(auth.client_token.expose_secret(), "token-value");
        assert_eq!(
            auth.accessor.as_ref().map(SecretString::expose_secret),
            Some("accessor-value")
        );
        assert_eq!(auth.policies, ["web"]);
    }

    #[test]
    fn cert_role_accepts_string_and_array_lists() {
        let role: CertRole = serde_json::from_str(
            r#"{"certificate":"pem","allowed_dns_sans":"a.example,b.example","token_policies":["web"]}"#,
        )
        .unwrap_or_else(|error| panic!("{error}"));
        assert_eq!(role.allowed_dns_sans, ["a.example", "b.example"]);
        assert_eq!(role.token_policies, ["web"]);
    }

    #[test]
    fn cert_role_list_is_bounded() {
        let mut keys = Vec::new();
        for index in 0..=crate::response::MAX_RESPONSE_STRINGS {
            keys.push(format!("cert-{index}"));
        }
        let value = serde_json::json!({ "keys": keys });
        let error = match serde_json::from_value::<CertRoleList>(value) {
            Ok(_) => panic!("oversized cert role list unexpectedly decoded"),
            Err(error) => error,
        };
        assert!(error.to_string().contains("exceeds item limit"));
    }

    #[test]
    fn cert_crl_serial_map_is_bounded() {
        let mut serials = serde_json::Map::new();
        for index in 0..=crate::response::MAX_RESPONSE_STRINGS {
            serials.insert(index.to_string(), serde_json::json!({}));
        }
        let value = serde_json::json!({ "serials": serials });
        let error = match serde_json::from_value::<CertCrlInfo>(value) {
            Ok(_) => panic!("oversized cert CRL serial map unexpectedly decoded"),
            Err(error) => error,
        };
        assert!(error.to_string().contains("exceeds item limit"));
    }
}