bump base64 from 0.10 to 0.21 (#29804)

* bump base64 from 0.10 to 0.21

* Fix configuration of bitflags

---------

Co-authored-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Tuna 2023-08-03 00:25:37 +03:00 committed by GitHub
parent ad0fa77456
commit 4c8db6af87
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 103 additions and 86 deletions

View file

@ -25,7 +25,7 @@ use crate::realms::enter_realm;
use crate::script_runtime::JSContext;
use crate::task_source::file_reading::FileReadingTask;
use crate::task_source::{TaskSource, TaskSourceName};
use base64;
use base64::Engine;
use dom_struct::dom_struct;
use encoding_rs::{Encoding, UTF_8};
use js::jsapi::Heap;
@ -89,7 +89,7 @@ pub struct FileReaderSharedFunctionality;
impl FileReaderSharedFunctionality {
pub fn dataurl_format(blob_contents: &[u8], blob_type: String) -> DOMString {
let base64 = base64::encode(&blob_contents);
let base64 = base64::engine::general_purpose::STANDARD.encode(&blob_contents);
let dataurl = if blob_type.is_empty() {
format!("data:base64,{}", base64)

View file

@ -31,7 +31,7 @@ use crate::dom::virtualmethods::VirtualMethods;
use crate::dom::webgl2renderingcontext::WebGL2RenderingContext;
use crate::dom::webglrenderingcontext::WebGLRenderingContext;
use crate::script_runtime::JSContext;
use base64;
use base64::Engine;
use canvas_traits::canvas::{CanvasId, CanvasMsg, FromScriptMsg};
use canvas_traits::webgl::{GLContextAttributes, WebGLVersion};
use dom_struct::dom_struct;
@ -434,7 +434,7 @@ impl HTMLCanvasElementMethods for HTMLCanvasElement {
let mut url = "data:image/png;base64,".to_owned();
// FIXME(nox): Should this use base64::URL_SAFE?
// FIXME(nox): https://github.com/marshallpierce/rust-base64/pull/56
base64::encode_config_buf(&png, base64::STANDARD, &mut url);
base64::engine::general_purpose::STANDARD.encode_string(&png, &mut url);
Ok(USVString(url))
}

View file

@ -77,7 +77,7 @@ use crate::webdriver_handlers::jsval_to_webdriver;
use crate::window_named_properties;
use app_units::Au;
use backtrace::Backtrace;
use base64;
use base64::Engine;
use bluetooth_traits::BluetoothRequest;
use canvas_traits::webgl::WebGLChan;
use crossbeam_channel::{unbounded, Sender, TryRecvError};
@ -577,7 +577,10 @@ pub fn base64_btoa(input: DOMString) -> Fallible<DOMString> {
// "and then must apply the base64 algorithm to that sequence of
// octets, and return the result. [RFC4648]"
Ok(DOMString::from(base64::encode(&octets)))
let config =
base64::engine::general_purpose::GeneralPurposeConfig::new().with_encode_padding(true);
let engine = base64::engine::GeneralPurpose::new(&base64::alphabet::STANDARD, config);
Ok(DOMString::from(engine.encode(&octets)))
}
}
@ -624,8 +627,12 @@ pub fn base64_atob(input: DOMString) -> Fallible<DOMString> {
return Err(Error::InvalidCharacter);
}
let data = base64::decode_config(&input, base64::STANDARD.decode_allow_trailing_bits(true))
.map_err(|_| Error::InvalidCharacter)?;
let config = base64::engine::general_purpose::GeneralPurposeConfig::new()
.with_decode_padding_mode(base64::engine::DecodePaddingMode::RequireNone)
.with_decode_allow_trailing_bits(true);
let engine = base64::engine::GeneralPurpose::new(&base64::alphabet::STANDARD, config);
let data = engine.decode(&input).map_err(|_| Error::InvalidCharacter)?;
Ok(data.iter().map(|&b| b as char).collect::<String>().into())
}