diff --git a/Cargo.lock b/Cargo.lock index 5e3948c63321..a586bdf60104 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -135,6 +135,14 @@ dependencies = [ "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "base64" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "bincode" version = "1.0.0-alpha2" @@ -1671,6 +1679,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "net" version = "0.0.1" dependencies = [ + "base64 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "brotli 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", "cookie 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "devtools_traits 0.0.1", @@ -1688,7 +1697,6 @@ dependencies = [ "openssl 0.7.14 (registry+https://github.com/rust-lang/crates.io-index)", "openssl-verify 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "profile_traits 0.0.1", - "rustc-serialize 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.9.11 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 0.9.11 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 0.9.9 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2241,6 +2249,7 @@ dependencies = [ "app_units 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "atomic_refcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "audio-video-metadata 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "base64 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "bluetooth_traits 0.0.1", "byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2285,7 +2294,6 @@ dependencies = [ "ref_filter_map 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "ref_slice 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-serialize 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)", "script_layout_interface 0.0.1", "script_plugins 0.0.1", "script_traits 0.0.1", @@ -3157,6 +3165,7 @@ dependencies = [ name = "webdriver_server" version = "0.0.1" dependencies = [ + "base64 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "cookie 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.9.18 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3336,6 +3345,7 @@ dependencies = [ "checksum azure 0.15.0 (git+https://github.com/servo/rust-azure)" = "" "checksum backtrace 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f551bc2ddd53aea015d453ef0b635af89444afa5ed2405dd0b2062ad5d600d80" "checksum backtrace-sys 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "d192fd129132fbc97497c1f2ec2c2c5174e376b95f535199ef4fe0a293d33842" +"checksum base64 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9892882c3bd89ed02dec391c128984c772b663a29700c32b5de0b33861cdf2bd" "checksum bincode 1.0.0-alpha2 (registry+https://github.com/rust-lang/crates.io-index)" = "62650bb5651ba8f0580cebf4ef255d791b8b0ef53800322661e1bb5791d42966" "checksum bindgen 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)" = "facc480c409c373db3c870e377ce223e5e07d979efc2604691dc6f583e8ded0f" "checksum bit-set 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d9bf6104718e80d7b26a68fdbacff3481cfc05df670821affc7e9cbc1884400c" diff --git a/components/net/Cargo.toml b/components/net/Cargo.toml index 0751f05d212b..22366e90c5c3 100644 --- a/components/net/Cargo.toml +++ b/components/net/Cargo.toml @@ -10,6 +10,7 @@ name = "net" path = "lib.rs" [dependencies] +base64 = "0.4.1" brotli = "1.0.6" cookie = "0.2.5" devtools_traits = {path = "../devtools_traits"} @@ -27,7 +28,6 @@ net_traits = {path = "../net_traits"} openssl = "0.7.6" openssl-verify = "0.1" profile_traits = {path = "../profile_traits"} -rustc-serialize = "0.3" serde = "0.9" serde_derive = "0.9" serde_json = "0.9" diff --git a/components/net/data_loader.rs b/components/net/data_loader.rs index 9b2b8ce2ac74..b95a2ab34123 100644 --- a/components/net/data_loader.rs +++ b/components/net/data_loader.rs @@ -2,8 +2,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +use base64; use hyper::mime::{Attr, Mime, SubLevel, TopLevel, Value}; -use rustc_serialize::base64::FromBase64; use servo_url::ServoUrl; use url::Position; use url::percent_encoding::percent_decode; @@ -46,7 +46,7 @@ pub fn decode(url: &ServoUrl) -> Result { // FIXME(#2909): It’s unclear what to do with non-alphabet characters, // but Acid 3 apparently depends on spaces being ignored. bytes = bytes.into_iter().filter(|&b| b != b' ').collect::>(); - match bytes.from_base64() { + match base64::decode(&bytes) { Err(..) => return Err(DecodeError::NonBase64DataUri), Ok(data) => bytes = data, } diff --git a/components/net/lib.rs b/components/net/lib.rs index 90999cfcf62d..f7724b082224 100644 --- a/components/net/lib.rs +++ b/components/net/lib.rs @@ -7,6 +7,7 @@ #![feature(mpsc_select)] #![feature(step_by)] +extern crate base64; extern crate brotli; extern crate cookie as cookie_rs; extern crate devtools_traits; @@ -25,7 +26,6 @@ extern crate net_traits; extern crate openssl; extern crate openssl_verify; extern crate profile_traits; -extern crate rustc_serialize; extern crate serde; #[macro_use] extern crate serde_derive; diff --git a/components/net/subresource_integrity.rs b/components/net/subresource_integrity.rs index 7268edbf80e5..bddef7d18a89 100644 --- a/components/net/subresource_integrity.rs +++ b/components/net/subresource_integrity.rs @@ -2,9 +2,9 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +use base64; use net_traits::response::{Response, ResponseBody, ResponseType}; use openssl::crypto::hash::{hash, Type as MessageDigest}; -use rustc_serialize::base64::{STANDARD, ToBase64}; use std::iter::Filter; use std::str::Split; use std::sync::MutexGuard; @@ -120,7 +120,7 @@ fn apply_algorithm_to_response(body: MutexGuard, -> String { if let ResponseBody::Done(ref vec) = *body { let response_digest = hash(message_digest, vec); - response_digest.to_base64(STANDARD) + base64::encode(&response_digest) } else { unreachable!("Tried to calculate digest of incomplete response body") } diff --git a/components/script/Cargo.toml b/components/script/Cargo.toml index 266dc4c2ce88..699574f30dad 100644 --- a/components/script/Cargo.toml +++ b/components/script/Cargo.toml @@ -28,6 +28,7 @@ angle = {git = "https://github.com/servo/angle", branch = "servo"} app_units = "0.4" audio-video-metadata = "0.1.2" atomic_refcell = "0.1" +base64 = "0.4.1" bitflags = "0.7" bluetooth_traits = {path = "../bluetooth_traits"} byteorder = "1.0" @@ -69,7 +70,6 @@ range = {path = "../range"} ref_filter_map = "1.0.1" ref_slice = "1.0" regex = "0.2" -rustc-serialize = "0.3" script_layout_interface = {path = "../script_layout_interface"} script_plugins = {path = "../script_plugins"} script_traits = {path = "../script_traits"} diff --git a/components/script/dom/filereader.rs b/components/script/dom/filereader.rs index e28c08b5efa7..61da63a57e68 100644 --- a/components/script/dom/filereader.rs +++ b/components/script/dom/filereader.rs @@ -2,6 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +use base64; use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::BlobBinding::BlobMethods; use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull; @@ -29,7 +30,6 @@ use js::jsapi::JSAutoCompartment; use js::jsapi::JSContext; use js::jsval::{self, JSVal}; use js::typedarray::{ArrayBuffer, CreateWith}; -use rustc_serialize::base64::{CharacterSet, Config, Newline, ToBase64}; use script_thread::RunnableWrapper; use servo_atoms::Atom; use std::cell::Cell; @@ -247,13 +247,7 @@ impl FileReader { //https://w3c.github.io/FileAPI/#dfn-readAsDataURL fn perform_readasdataurl(result: &DOMRefCell>, data: ReadMetaData, bytes: &[u8]) { - let config = Config { - char_set: CharacterSet::UrlSafe, - newline: Newline::LF, - pad: true, - line_length: None - }; - let base64 = bytes.to_base64(config); + let base64 = base64::encode(bytes); let output = if data.blobtype.is_empty() { format!("data:base64,{}", base64) diff --git a/components/script/dom/htmlcanvaselement.rs b/components/script/dom/htmlcanvaselement.rs index dbbf695b2d42..ed8aca71c1d5 100644 --- a/components/script/dom/htmlcanvaselement.rs +++ b/components/script/dom/htmlcanvaselement.rs @@ -2,6 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +use base64; use canvas_traits::{CanvasMsg, FromScriptMsg}; use dom::attr::Attr; use dom::bindings::cell::DOMRefCell; @@ -33,7 +34,6 @@ use ipc_channel::ipc::{self, IpcSender}; use js::error::throw_type_error; use js::jsapi::{HandleValue, JSContext}; use offscreen_gl_context::GLContextAttributes; -use rustc_serialize::base64::{STANDARD, ToBase64}; use script_layout_interface::HTMLCanvasData; use std::iter::repeat; use style::attr::AttrValue; @@ -296,7 +296,7 @@ impl HTMLCanvasElementMethods for HTMLCanvasElement { encoder.encode(&raw_data, self.Width(), self.Height(), ColorType::RGBA(8)).unwrap(); } - let encoded = encoded.to_base64(STANDARD); + let encoded = base64::encode(&encoded); Ok(DOMString::from(format!("data:{};base64,{}", mime_type, encoded))) } } diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index b390c44217ad..9f25edc3a076 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -3,6 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use app_units::Au; +use base64; use bluetooth_traits::BluetoothRequest; use cssparser::Parser; use devtools_traits::{ScriptToDevtoolsControlMsg, TimelineMarker, TimelineMarkerType}; @@ -68,7 +69,6 @@ use num_traits::ToPrimitive; use open; use profile_traits::mem::ProfilerChan as MemProfilerChan; use profile_traits::time::ProfilerChan as TimeProfilerChan; -use rustc_serialize::base64::{FromBase64, STANDARD, ToBase64}; use script_layout_interface::{TrustedNodeAddress, PendingImageState}; use script_layout_interface::message::{Msg, Reflow, ReflowQueryType, ScriptReflow}; use script_layout_interface::reporter::CSSErrorReporter; @@ -410,16 +410,13 @@ pub fn base64_btoa(input: DOMString) -> Fallible { // "and then must apply the base64 algorithm to that sequence of // octets, and return the result. [RFC4648]" - Ok(DOMString::from(octets.to_base64(STANDARD))) + Ok(DOMString::from(base64::encode(&octets))) } } // https://html.spec.whatwg.org/multipage/#atob pub fn base64_atob(input: DOMString) -> Fallible { // "Remove all space characters from input." - // serialize::base64::from_base64 ignores \r and \n, - // but it treats the other space characters as - // invalid input. fn is_html_space(c: char) -> bool { HTML_SPACE_CHARACTERS.iter().any(|&m| m == c) } @@ -456,7 +453,7 @@ pub fn base64_atob(input: DOMString) -> Fallible { return Err(Error::InvalidCharacter) } - match input.from_base64() { + match base64::decode(&input) { Ok(data) => Ok(DOMString::from(data.iter().map(|&b| b as char).collect::())), Err(..) => Err(Error::InvalidCharacter) } diff --git a/components/script/lib.rs b/components/script/lib.rs index aa2e2f4baf5c..ade3543bbe82 100644 --- a/components/script/lib.rs +++ b/components/script/lib.rs @@ -28,6 +28,7 @@ extern crate angle; extern crate app_units; extern crate atomic_refcell; extern crate audio_video_metadata; +extern crate base64; #[macro_use] extern crate bitflags; extern crate bluetooth_traits; @@ -78,7 +79,6 @@ extern crate range; extern crate ref_filter_map; extern crate ref_slice; extern crate regex; -extern crate rustc_serialize; extern crate script_layout_interface; extern crate script_traits; extern crate selectors; diff --git a/components/webdriver_server/Cargo.toml b/components/webdriver_server/Cargo.toml index e84f1ff0662d..08f21a60b5dc 100644 --- a/components/webdriver_server/Cargo.toml +++ b/components/webdriver_server/Cargo.toml @@ -10,6 +10,7 @@ name = "webdriver_server" path = "lib.rs" [dependencies] +base64 = "0.4.1" cookie = "0.2.5" euclid = "0.11" hyper = "0.9.9" diff --git a/components/webdriver_server/lib.rs b/components/webdriver_server/lib.rs index 831a8d323def..d0aa102e2e9e 100644 --- a/components/webdriver_server/lib.rs +++ b/components/webdriver_server/lib.rs @@ -7,6 +7,7 @@ #![deny(unsafe_code)] +extern crate base64; extern crate cookie as cookie_rs; extern crate euclid; extern crate hyper; @@ -34,7 +35,6 @@ use keys::keycodes_to_keys; use msg::constellation_msg::{FrameId, PipelineId, TraversalDirection}; use net_traits::image::base::PixelFormat; use regex::Captures; -use rustc_serialize::base64::{CharacterSet, Config, Newline, ToBase64}; use rustc_serialize::json::{Json, ToJson}; use script_traits::{ConstellationMsg, LoadData, WebDriverCommandMsg}; use script_traits::webdriver_msg::{LoadStatus, WebDriverCookieError, WebDriverFrameId}; @@ -831,13 +831,7 @@ impl Handler { let mut png_data = Vec::new(); DynamicImage::ImageRgb8(rgb).save(&mut png_data, ImageFormat::PNG).unwrap(); - let config = Config { - char_set: CharacterSet::Standard, - newline: Newline::LF, - pad: true, - line_length: None - }; - let encoded = png_data.to_base64(config); + let encoded = base64::encode(&png_data); Ok(WebDriverResponse::Generic(ValueResponse::new(encoded.to_json()))) }