use crate::PemLabel;
pub const DEFAULT_MAX_PEM_INPUT_LEN: usize = 1024 * 1024;
pub const DEFAULT_MAX_DER_LEN: usize = 1024 * 1024;
pub const DEFAULT_PEM_LINE_WIDTH: usize = 64;
pub const DEFAULT_ALLOWED_LABELS: &[PemLabel] = &[
PemLabel::PrivateKey,
PemLabel::EcPrivateKey,
PemLabel::PublicKey,
];
#[derive(Debug, Clone, Copy)]
pub struct PemDecodePolicy<'a> {
pub allowed_labels: &'a [PemLabel],
pub max_input_len: usize,
pub max_der_len: usize,
}
impl Default for PemDecodePolicy<'_> {
fn default() -> Self {
Self {
allowed_labels: DEFAULT_ALLOWED_LABELS,
max_input_len: DEFAULT_MAX_PEM_INPUT_LEN,
max_der_len: DEFAULT_MAX_DER_LEN,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PemLineEnding {
Lf,
Crlf,
}
impl PemLineEnding {
pub(crate) const fn as_str(self) -> &'static str {
match self {
Self::Lf => "\n",
Self::Crlf => "\r\n",
}
}
}
#[derive(Debug, Clone, Copy)]
pub struct PemEncodeOptions {
pub max_der_len: usize,
pub line_width: usize,
pub line_ending: PemLineEnding,
}
impl Default for PemEncodeOptions {
fn default() -> Self {
Self {
max_der_len: DEFAULT_MAX_DER_LEN,
line_width: DEFAULT_PEM_LINE_WIDTH,
line_ending: PemLineEnding::Lf,
}
}
}