Skip to content

Commit

Permalink
core: remove protobuf_macros (plietar#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
awiouy authored and plietar committed Feb 12, 2018
1 parent 0cf11da commit e276d39
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 51 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
8 changes: 0 additions & 8 deletions core/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate protobuf_macros;
extern crate rand;
extern crate vergen;

Expand Down Expand Up @@ -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");
}
51 changes: 28 additions & 23 deletions core/src/connection/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,27 @@ impl<T: AsyncRead + AsyncWrite> Future for Handshake<T> {
}

fn client_hello<T: AsyncWrite>(connection: T, gc: Vec<u8>) -> WriteAll<T, Vec<u8>> {
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();
Expand All @@ -108,13 +113,13 @@ fn client_hello<T: AsyncWrite>(connection: T, gc: Vec<u8>) -> WriteAll<T, Vec<u8
}

fn client_response<T: AsyncWrite>(connection: T, challenge: Vec<u8>) -> WriteAll<T, Vec<u8>> {
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();
Expand Down
37 changes: 23 additions & 14 deletions core/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,29 @@ pub fn authenticate(
) -> Box<Future<Item = (Transport, Credentials), Error = io::Error>> {
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();
Expand Down
2 changes: 0 additions & 2 deletions core/src/lib.in.rs

This file was deleted.

3 changes: 1 addition & 2 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));

0 comments on commit e276d39

Please sign in to comment.