Skip to content

Commit

Permalink
Bump base64 to 0.21
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed Jan 10, 2023
1 parent 5aeb841 commit 2117403
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repository = "https://github.com/rustls/pemfile"
categories = ["network-programming", "cryptography"]

[dependencies]
base64 = "0.13.0"
base64 = "0.21"

[dev-dependencies]
criterion = "0.3"
Expand Down
18 changes: 15 additions & 3 deletions src/pemfile.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::io::{self, ErrorKind};

use base64;

/// The contents of a single recognised block in a PEM file.
#[non_exhaustive]
#[derive(Debug, PartialEq)]
Expand Down Expand Up @@ -96,7 +94,8 @@ pub fn read_one(rd: &mut dyn io::BufRead) -> Result<Option<Item>, io::Error> {

if let Some((section_type, end_marker)) = section.as_ref() {
if line.starts_with(end_marker) {
let der = base64::decode(&b64buf)
let der = base64::ENGINE
.decode(&b64buf)
.map_err(|err| io::Error::new(ErrorKind::InvalidData, err))?;

if let Some(item) = Item::from_start_line(&section_type, der) {
Expand Down Expand Up @@ -132,3 +131,16 @@ pub fn read_all(rd: &mut dyn io::BufRead) -> Result<Vec<Item>, io::Error> {
}
}
}

mod base64 {
use base64::alphabet::STANDARD;
use base64::engine::general_purpose::{GeneralPurpose, GeneralPurposeConfig};
use base64::engine::DecodePaddingMode;
pub(super) use base64::engine::Engine;

pub(super) const ENGINE: GeneralPurpose = GeneralPurpose::new(
&STANDARD,
GeneralPurposeConfig::new().with_decode_padding_mode(DecodePaddingMode::Indifferent),
);
}
use self::base64::Engine;

0 comments on commit 2117403

Please sign in to comment.