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)]
46pub enum PemLineEnding {
47 Lf,
49 Crlf,
51}
52
53impl PemLineEnding {
54 pub(crate) const fn as_str(self) -> &'static str {
55 match self {
56 Self::Lf => "\n",
57 Self::Crlf => "\r\n",
58 }
59 }
60}
61
62#[derive(Debug, Clone, Copy)]
64pub struct PemEncodeOptions {
65 pub max_der_len: usize,
67 pub line_width: usize,
69 pub line_ending: PemLineEnding,
71}
72
73impl Default for PemEncodeOptions {
74 fn default() -> Self {
75 Self {
76 max_der_len: DEFAULT_MAX_DER_LEN,
77 line_width: DEFAULT_PEM_LINE_WIDTH,
78 line_ending: PemLineEnding::Lf,
79 }
80 }
81}