Skip to content

Commit

Permalink
get rid of warnings related to new API of base64 crate
Browse files Browse the repository at this point in the history
  • Loading branch information
snshn committed Jan 14, 2024
1 parent b7a38c9 commit 727eae2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/html.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use base64;
use base64::prelude::*;
use chrono::prelude::*;
use encoding_rs::Encoding;
use html5ever::interface::QualName;
Expand Down Expand Up @@ -65,15 +65,15 @@ pub fn check_integrity(data: &[u8], integrity: &str) -> bool {
if integrity.starts_with("sha256-") {
let mut hasher = Sha256::new();
hasher.update(data);
base64::encode(hasher.finalize()) == integrity[7..]
BASE64_STANDARD.encode(hasher.finalize()) == integrity[7..]
} else if integrity.starts_with("sha384-") {
let mut hasher = Sha384::new();
hasher.update(data);
base64::encode(hasher.finalize()) == integrity[7..]
BASE64_STANDARD.encode(hasher.finalize()) == integrity[7..]
} else if integrity.starts_with("sha512-") {
let mut hasher = Sha512::new();
hasher.update(data);
base64::encode(hasher.finalize()) == integrity[7..]
BASE64_STANDARD.encode(hasher.finalize()) == integrity[7..]
} else {
false
}
Expand Down
14 changes: 11 additions & 3 deletions src/url.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use base64;
use base64::prelude::*;
use percent_encoding::percent_decode_str;
use url::Url;

Expand Down Expand Up @@ -33,7 +33,15 @@ pub fn create_data_url(media_type: &str, charset: &str, data: &[u8], final_asset
"".to_string()
};

data_url.set_path(format!("{}{};base64,{}", media_type, c, base64::encode(data)).as_str());
data_url.set_path(
format!(
"{}{};base64,{}",
media_type,
c,
BASE64_STANDARD.encode(data)
)
.as_str(),
);

data_url
}
Expand Down Expand Up @@ -63,7 +71,7 @@ pub fn parse_data_url(url: &Url) -> (String, String, Vec<u8>) {
// Parse raw data into vector of bytes
let text: String = percent_decode_str(&data).decode_utf8_lossy().to_string();
let blob: Vec<u8> = if is_base64 {
base64::decode(&text).unwrap_or(vec![])
BASE64_STANDARD.decode(&text).unwrap_or(vec![])
} else {
text.as_bytes().to_vec()
};
Expand Down

0 comments on commit 727eae2

Please sign in to comment.