Skip to content

Commit

Permalink
Replace use of rustc_serialize::base64 by base64
Browse files Browse the repository at this point in the history
  • Loading branch information
nox committed Mar 26, 2017
1 parent c2d9f66 commit 0ed4df2
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 34 deletions.
14 changes: 12 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion components/net/Cargo.toml
Expand Up @@ -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"}
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions components/net/data_loader.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -46,7 +46,7 @@ pub fn decode(url: &ServoUrl) -> Result<DecodeData, DecodeError> {
// 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::<Vec<u8>>();
match bytes.from_base64() {
match base64::decode(&bytes) {
Err(..) => return Err(DecodeError::NonBase64DataUri),
Ok(data) => bytes = data,
}
Expand Down
2 changes: 1 addition & 1 deletion components/net/lib.rs
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions components/net/subresource_integrity.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -120,7 +120,7 @@ fn apply_algorithm_to_response(body: MutexGuard<ResponseBody>,
-> 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")
}
Expand Down
2 changes: 1 addition & 1 deletion components/script/Cargo.toml
Expand Up @@ -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"
Expand Down Expand Up @@ -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"}
Expand Down
10 changes: 2 additions & 8 deletions components/script/dom/filereader.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -247,13 +247,7 @@ impl FileReader {

//https://w3c.github.io/FileAPI/#dfn-readAsDataURL
fn perform_readasdataurl(result: &DOMRefCell<Option<FileReaderResult>>, 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)
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/htmlcanvaselement.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)))
}
}
Expand Down
9 changes: 3 additions & 6 deletions components/script/dom/window.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -410,16 +410,13 @@ 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(octets.to_base64(STANDARD)))
Ok(DOMString::from(base64::encode(&octets)))
}
}

// https://html.spec.whatwg.org/multipage/#atob
pub fn base64_atob(input: DOMString) -> Fallible<DOMString> {
// "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)
}
Expand Down Expand Up @@ -456,7 +453,7 @@ pub fn base64_atob(input: DOMString) -> Fallible<DOMString> {
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::<String>())),
Err(..) => Err(Error::InvalidCharacter)
}
Expand Down
2 changes: 1 addition & 1 deletion components/script/lib.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions components/webdriver_server/Cargo.toml
Expand Up @@ -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"
Expand Down
10 changes: 2 additions & 8 deletions components/webdriver_server/lib.rs
Expand Up @@ -7,6 +7,7 @@

#![deny(unsafe_code)]

extern crate base64;
extern crate cookie as cookie_rs;
extern crate euclid;
extern crate hyper;
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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())))
}

Expand Down

0 comments on commit 0ed4df2

Please sign in to comment.