1use crate::PemLabel;
6
7pub const DEFAULT_MAX_PEM_INPUT_LEN: usize = 1024 * 1024;
9
10pub const DEFAULT_MAX_DER_LEN: usize = 1024 * 1024;
12
13pub const DEFAULT_PEM_LINE_WIDTH: usize = 64;
15
16pub const DEFAULT_ALLOWED_LABELS: &[PemLabel] = &[
18 PemLabel::PrivateKey,
19 PemLabel::EcPrivateKey,
20 PemLabel::PublicKey,
21];
22
23#[derive(Debug, Clone, Copy)]
25pub struct PemDecodePolicy<'a> {
26 pub allowed_labels: &'a [PemLabel],
28 pub max_input_len: usize,
30 pub max_der_len: usize,
32}
33
34impl Default for PemDecodePolicy<'_> {
35 fn default() -> Self {
36 Self {
37 allowed_labels: DEFAULT_ALLOWED_LABELS,
38 max_input_len: DEFAULT_MAX_PEM_INPUT_LEN,
39 max_der_len: DEFAULT_MAX_DER_LEN,
40 }
41 }
42}
43
44#[derive(Debug, Clone, Copy, PartialEq, Eq)]
46#[non_exhaustive]
47pub enum PemLineEnding {
48 Lf,
50 Crlf,
52}
53
54impl PemLineEnding {
55 pub(crate) const fn as_str(self) -> &'static str {
56 match self {
57 Self::Lf => "\n",
58 Self::Crlf => "\r\n",
59 }
60 }
61}
62
63#[derive(Debug, Clone, Copy)]
65pub struct PemEncodeOptions {
66 pub max_der_len: usize,
68 pub line_width: usize,
70 pub line_ending: PemLineEnding,
72}
73
74impl Default for PemEncodeOptions {
75 fn default() -> Self {
76 Self {
77 max_der_len: DEFAULT_MAX_DER_LEN,
78 line_width: DEFAULT_PEM_LINE_WIDTH,
79 line_ending: PemLineEnding::Lf,
80 }
81 }
82}