codec_pem/error.rs
1// SPDX-FileCopyrightText: 2026 ReallyMe Technologies Limited
2//
3// SPDX-License-Identifier: MIT OR 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 /// A block-count or bounded allocation limit was exceeded.
12 #[error("pem: resource limit exceeded")]
13 ResourceLimitExceeded,
14 /// The input text exceeded the configured maximum size.
15 #[error("pem: input too large")]
16 InputTooLarge,
17 /// The decoded DER body exceeded the configured maximum size.
18 #[error("pem: der body too large")]
19 DerTooLarge,
20 /// The PEM document did not contain a BEGIN boundary.
21 #[error("pem: missing begin boundary")]
22 MissingBegin,
23 /// The PEM document did not contain a matching END boundary.
24 #[error("pem: missing end boundary")]
25 MissingEnd,
26 /// The BEGIN and END labels did not match.
27 #[error("pem: label mismatch")]
28 LabelMismatch,
29 /// The label is not part of the configured allowlist.
30 #[error("pem: unsupported label")]
31 UnsupportedLabel,
32 /// A boundary line was malformed.
33 #[error("pem: invalid boundary")]
34 InvalidBoundary,
35 /// The base64 body was malformed.
36 #[error("pem: invalid base64")]
37 InvalidBase64,
38 /// The body was empty or contained invalid armor data.
39 #[error("pem: invalid body")]
40 InvalidBody,
41 /// The encode options were invalid.
42 #[error("pem: invalid options")]
43 InvalidOptions,
44 /// The PEM text was empty.
45 #[error("pem: empty input")]
46 EmptyInput,
47 /// The DER body supplied for encoding was empty.
48 #[error("pem: empty der body")]
49 EmptyDer,
50}