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] = &[PemLabel::PublicKey];
18
19#[derive(Debug, Clone, Copy)]
21pub struct PemDecodePolicy<'a> {
22 pub allowed_labels: &'a [PemLabel],
24 pub max_input_len: usize,
26 pub max_der_len: usize,
28}
29
30impl Default for PemDecodePolicy<'_> {
31 fn default() -> Self {
32 Self {
33 allowed_labels: DEFAULT_ALLOWED_LABELS,
34 max_input_len: DEFAULT_MAX_PEM_INPUT_LEN,
35 max_der_len: DEFAULT_MAX_DER_LEN,
36 }
37 }
38}
39
40#[derive(Debug, Clone, Copy, PartialEq, Eq)]
42#[non_exhaustive]
43pub enum PemLineEnding {
44 Lf,
46 Crlf,
48}
49
50impl PemLineEnding {
51 pub(crate) const fn as_str(self) -> &'static str {
52 match self {
53 Self::Lf => "\n",
54 Self::Crlf => "\r\n",
55 }
56 }
57}
58
59#[derive(Debug, Clone, Copy)]
61pub struct PemEncodeOptions {
62 pub max_der_len: usize,
64 pub line_width: usize,
66 pub line_ending: PemLineEnding,
68}
69
70impl Default for PemEncodeOptions {
71 fn default() -> Self {
72 Self {
73 max_der_len: DEFAULT_MAX_DER_LEN,
74 line_width: DEFAULT_PEM_LINE_WIDTH,
75 line_ending: PemLineEnding::Lf,
76 }
77 }
78}