Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pem-rfc7468/src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ fn decode_encapsulated_text<'i, 'o>(
}
Ok(())
}
/// Decode the encapsulation boundaries of a PEM document according to RFC 7468's "Strict" grammar.
///
/// On success, returning the decoded label.
pub fn decode_label(pem: &[u8]) -> Result<&str> {
Ok(Encapsulation::try_from(pem)?.label())
}

/// Decode a PEM document according to RFC 7468's "Strict" grammar.
///
Expand Down
2 changes: 1 addition & 1 deletion pem-rfc7468/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ mod error;
mod grammar;

pub use crate::{
decoder::decode,
decoder::{decode, decode_label},
encoder::{encode, encoded_len, LineEnding},
error::{Error, Result},
};
Expand Down
4 changes: 4 additions & 0 deletions pem-rfc7468/tests/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ fn pkcs1_enc_example() {
Err(pem_rfc7468::Error::HeaderDetected) => (),
_ => panic!("Expected HeaderDetected error"),
}
let label = pem_rfc7468::decode_label(pem).unwrap();
assert_eq!(label, "RSA PRIVATE KEY");
}

#[test]
Expand All @@ -37,6 +39,8 @@ fn header_of_length_64() {
Err(pem_rfc7468::Error::HeaderDetected) => (),
_ => panic!("Expected HeaderDetected error"),
}
let label = pem_rfc7468::decode_label(pem).unwrap();
assert_eq!(label, "RSA PRIVATE KEY");
}

#[test]
Expand Down