From e276d39704e15b49f80c34b23578b1a07c9563b6 Mon Sep 17 00:00:00 2001 From: Anton Voyl Date: Mon, 12 Feb 2018 15:58:09 +0100 Subject: [PATCH] core: remove protobuf_macros (#146) Fixes #129 --- Cargo.lock | 1 - core/Cargo.toml | 1 - core/build.rs | 8 ----- core/src/connection/handshake.rs | 51 ++++++++++++++++++-------------- core/src/connection/mod.rs | 37 ++++++++++++++--------- core/src/lib.in.rs | 2 -- core/src/lib.rs | 3 +- 7 files changed, 52 insertions(+), 51 deletions(-) delete mode 100644 core/src/lib.in.rs diff --git a/Cargo.lock b/Cargo.lock index 08433771..1441ac07 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -398,7 +398,6 @@ dependencies = [ "num-integer 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", "protobuf 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "protobuf_macros 0.6.0 (git+https://github.com/plietar/rust-protobuf-macros)", "rand 0.3.20 (registry+https://github.com/rust-lang/crates.io-index)", "rpassword 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "rust-crypto 0.2.36 (git+https://github.com/awmath/rust-crypto.git?branch=avx2)", diff --git a/core/Cargo.toml b/core/Cargo.toml index 8bb36214..f563f315 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -32,6 +32,5 @@ tokio-io = "0.1" uuid = { version = "0.4", features = ["v4"] } [build-dependencies] -protobuf_macros = { git = "https://github.com/plietar/rust-protobuf-macros", features = ["with-syntex"] } rand = "0.3.13" vergen = "0.1.0" diff --git a/core/build.rs b/core/build.rs index d57d57a9..0240a8fe 100644 --- a/core/build.rs +++ b/core/build.rs @@ -1,4 +1,3 @@ -extern crate protobuf_macros; extern crate rand; extern crate vergen; @@ -34,11 +33,4 @@ pub fn build_id() -> &'static str {{ if let Err(e) = version_file.write_all(build_id_fn.as_bytes()) { println!("{}", e); } - - protobuf_macros::expand("src/lib.in.rs", &out.join("lib.rs")).unwrap(); - - println!("cargo:rerun-if-changed=src/lib.in.rs"); - println!("cargo:rerun-if-changed=src/connection/mod.rs"); - println!("cargo:rerun-if-changed=src/connection/codec.rs"); - println!("cargo:rerun-if-changed=src/connection/handshake.rs"); } diff --git a/core/src/connection/handshake.rs b/core/src/connection/handshake.rs index c47364b4..db945162 100644 --- a/core/src/connection/handshake.rs +++ b/core/src/connection/handshake.rs @@ -82,22 +82,27 @@ impl Future for Handshake { } fn client_hello(connection: T, gc: Vec) -> WriteAll> { - let packet = protobuf_init!(ClientHello::new(), { - build_info => { - product: protocol::keyexchange::Product::PRODUCT_PARTNER, - platform: protocol::keyexchange::Platform::PLATFORM_LINUX_X86, - version: 0x10800000000, - }, - cryptosuites_supported => [ - protocol::keyexchange::Cryptosuite::CRYPTO_SUITE_SHANNON, - ], - login_crypto_hello.diffie_hellman => { - gc: gc, - server_keys_known: 1, - }, - client_nonce: util::rand_vec(&mut thread_rng(), 0x10), - padding: vec![0x1e], - }); + let mut packet = ClientHello::new(); + packet + .mut_build_info() + .set_product(protocol::keyexchange::Product::PRODUCT_PARTNER); + packet + .mut_build_info() + .set_platform(protocol::keyexchange::Platform::PLATFORM_LINUX_X86); + packet.mut_build_info().set_version(0x10800000000); + packet + .mut_cryptosuites_supported() + .push(protocol::keyexchange::Cryptosuite::CRYPTO_SUITE_SHANNON); + packet + .mut_login_crypto_hello() + .mut_diffie_hellman() + .set_gc(gc); + packet + .mut_login_crypto_hello() + .mut_diffie_hellman() + .set_server_keys_known(1); + packet.set_client_nonce(util::rand_vec(&mut thread_rng(), 0x10)); + packet.set_padding(vec![0x1e]); let mut buffer = vec![0, 4]; let size = 2 + 4 + packet.compute_size(); @@ -108,13 +113,13 @@ fn client_hello(connection: T, gc: Vec) -> WriteAll(connection: T, challenge: Vec) -> WriteAll> { - let packet = protobuf_init!(ClientResponsePlaintext::new(), { - login_crypto_response.diffie_hellman => { - hmac: challenge - }, - pow_response => {}, - crypto_response => {}, - }); + let mut packet = ClientResponsePlaintext::new(); + packet + .mut_login_crypto_response() + .mut_diffie_hellman() + .set_hmac(challenge); + packet.mut_pow_response(); + packet.mut_crypto_response(); let mut buffer = vec![]; let size = 4 + packet.compute_size(); diff --git a/core/src/connection/mod.rs b/core/src/connection/mod.rs index fae4092a..7d365f6e 100644 --- a/core/src/connection/mod.rs +++ b/core/src/connection/mod.rs @@ -35,20 +35,29 @@ pub fn authenticate( ) -> Box> { use protocol::authentication::{APWelcome, ClientResponseEncrypted, CpuFamily, Os}; - let packet = protobuf_init!(ClientResponseEncrypted::new(), { - login_credentials => { - username: credentials.username, - typ: credentials.auth_type, - auth_data: credentials.auth_data, - }, - system_info => { - cpu_family: CpuFamily::CPU_UNKNOWN, - os: Os::OS_UNKNOWN, - system_information_string: format!("librespot_{}_{}", version::short_sha(), version::build_id()), - device_id: device_id, - }, - version_string: version::version_string(), - }); + let mut packet = ClientResponseEncrypted::new(); + packet + .mut_login_credentials() + .set_username(credentials.username); + packet + .mut_login_credentials() + .set_typ(credentials.auth_type); + packet + .mut_login_credentials() + .set_auth_data(credentials.auth_data); + packet + .mut_system_info() + .set_cpu_family(CpuFamily::CPU_UNKNOWN); + packet.mut_system_info().set_os(Os::OS_UNKNOWN); + packet + .mut_system_info() + .set_system_information_string(format!( + "librespot_{}_{}", + version::short_sha(), + version::build_id() + )); + packet.mut_system_info().set_device_id(device_id); + packet.set_version_string(version::version_string()); let cmd = 0xab; let data = packet.write_to_bytes().unwrap(); diff --git a/core/src/lib.in.rs b/core/src/lib.in.rs deleted file mode 100644 index cd8fbdaf..00000000 --- a/core/src/lib.in.rs +++ /dev/null @@ -1,2 +0,0 @@ -#[allow(unused_mut)] -mod connection; diff --git a/core/src/lib.rs b/core/src/lib.rs index 4cc44448..207c7656 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -39,11 +39,10 @@ pub mod authentication; pub mod cache; pub mod channel; pub mod config; +mod connection; pub mod diffie_hellman; pub mod keymaster; pub mod mercury; pub mod session; pub mod util; pub mod version; - -include!(concat!(env!("OUT_DIR"), "/lib.rs"));