1use crate::PemError;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9#[non_exhaustive]
10pub enum PemLabel {
11 PrivateKey,
13 EcPrivateKey,
15 PublicKey,
17}
18
19impl PemLabel {
20 pub const fn as_str(self) -> &'static str {
22 match self {
23 Self::PrivateKey => "PRIVATE KEY",
24 Self::EcPrivateKey => "EC PRIVATE KEY",
25 Self::PublicKey => "PUBLIC KEY",
26 }
27 }
28
29 pub(crate) fn parse(input: &str) -> Result<Self, PemError> {
30 match input {
31 "PRIVATE KEY" => Ok(Self::PrivateKey),
32 "EC PRIVATE KEY" => Ok(Self::EcPrivateKey),
33 "PUBLIC KEY" => Ok(Self::PublicKey),
34 _ => Err(PemError::UnsupportedLabel),
35 }
36 }
37}