Skip to content

Commit

Permalink
hide the ASCII_ARMOR symbol
Browse files Browse the repository at this point in the history
There appears to be some interaction between once_cell and the 32-bit
toolchain for windows that is causing the ASCII_ARMOR symbol to be
mis-linked. To work around the issue reported in #29, hide the
ASCII_ARMOR symbol inside of a function so that it is not even
crate-wide available but is only available inside the function.
  • Loading branch information
jcreekmore committed Oct 25, 2021
1 parent 4137641 commit fb15d5c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.0.1

- hide the ASCII_ARMOR symbol to work around a linking issue with 32-bit windows builds

# 1.0

- `pem::parse_many` now returns a `Result<Vec<Pem>>` instead of a `Vec<Pem>` that silently discarded invalid sections.
15 changes: 10 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,14 @@ const REGEX_STR: &str =
/// The line length for PEM encoding
const LINE_WRAP: usize = 64;

static ASCII_ARMOR: Lazy<Regex> = Lazy::new(|| {
Regex::new(REGEX_STR).unwrap()
});

fn ascii_armor() -> &'static Regex {
static ASCII_ARMOR: Lazy<Regex> = Lazy::new(|| {
Regex::new(REGEX_STR).unwrap()
});

&ASCII_ARMOR
}

/// Enum describing line endings
#[derive(Debug, Clone, Copy)]
Expand Down Expand Up @@ -242,7 +247,7 @@ impl Pem {
/// assert_eq!(pem.tag, "RSA PRIVATE KEY");
/// ```
pub fn parse<B: AsRef<[u8]>>(input: B) -> Result<Pem> {
ASCII_ARMOR
ascii_armor()
.captures(&input.as_ref())
.ok_or_else(|| PemError::MalformedFraming)
.and_then(Pem::new_from_captures)
Expand Down Expand Up @@ -319,7 +324,7 @@ pub fn parse<B: AsRef<[u8]>>(input: B) -> Result<Pem> {
/// ```
pub fn parse_many<B: AsRef<[u8]>>(input: B) -> Result<Vec<Pem>> {
// Each time our regex matches a PEM section, we need to decode it.
ASCII_ARMOR
ascii_armor()
.captures_iter(&input.as_ref())
.map(|caps| Pem::new_from_captures(caps))
.collect()
Expand Down

0 comments on commit fb15d5c

Please sign in to comment.