Skip to main content

codec_pem/
error.rs

1// SPDX-FileCopyrightText: Copyright © 2026 ReallyMe LLC. All rights reserved
2//
3// SPDX-License-Identifier: Apache-2.0
4
5use thiserror::Error;
6
7/// Error returned when PEM text armor cannot be parsed or encoded.
8#[derive(Debug, Error, Clone, Copy, PartialEq, Eq)]
9#[non_exhaustive]
10pub enum PemError {
11    /// The input text exceeded the configured maximum size.
12    #[error("pem: input too large")]
13    InputTooLarge,
14    /// The decoded DER body exceeded the configured maximum size.
15    #[error("pem: der body too large")]
16    DerTooLarge,
17    /// The PEM document did not contain a BEGIN boundary.
18    #[error("pem: missing begin boundary")]
19    MissingBegin,
20    /// The PEM document did not contain a matching END boundary.
21    #[error("pem: missing end boundary")]
22    MissingEnd,
23    /// The BEGIN and END labels did not match.
24    #[error("pem: label mismatch")]
25    LabelMismatch,
26    /// The label is not part of the configured allowlist.
27    #[error("pem: unsupported label")]
28    UnsupportedLabel,
29    /// A boundary line was malformed.
30    #[error("pem: invalid boundary")]
31    InvalidBoundary,
32    /// The base64 body was malformed.
33    #[error("pem: invalid base64")]
34    InvalidBase64,
35    /// The body was empty or contained invalid armor data.
36    #[error("pem: invalid body")]
37    InvalidBody,
38    /// The encode options were invalid.
39    #[error("pem: invalid options")]
40    InvalidOptions,
41}