diff --git a/Cargo.lock b/Cargo.lock index 4c63ef8b..158ac63c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3954,8 +3954,6 @@ dependencies = [ "oauth2", "parking_lot", "protobuf", - "psst-protocol", - "quick-protobuf", "rand 0.9.1", "rangemap", "rb", @@ -4009,13 +4007,6 @@ dependencies = [ "winres", ] -[[package]] -name = "psst-protocol" -version = "0.1.0" -dependencies = [ - "quick-protobuf", -] - [[package]] name = "publicsuffix" version = "1.5.6" @@ -4050,15 +4041,6 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3" -[[package]] -name = "quick-protobuf" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d6da84cc204722a989e01ba2f6e1e276e190f22263d0cb6ce8526fcdb0d2e1f" -dependencies = [ - "byteorder", -] - [[package]] name = "quote" version = "1.0.40" diff --git a/Cargo.toml b/Cargo.toml index 1a3db316..59994a36 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] resolver = "2" -members = ["psst-protocol", "psst-core", "psst-cli", "psst-gui"] +members = ["psst-core", "psst-cli", "psst-gui"] [profile.dev] opt-level = 1 diff --git a/README.md b/README.md index 7c4233dd..4ec8454e 100644 --- a/README.md +++ b/README.md @@ -164,7 +164,6 @@ Here's the basic project structure: - `/psst-core` - Core library, takes care of Spotify TCP session, audio file retrieval, decoding, audio output, playback queue, etc. - `/psst-gui` - GUI application built with [Druid](https://github.com/linebender/druid) - `/psst-cli` - Example CLI that plays a track. Credentials must be configured in the code. -- `/psst-protocol` - Internal Protobuf definitions used for Spotify communication. ## Privacy Policy diff --git a/psst-core/Cargo.toml b/psst-core/Cargo.toml index eb7d4c28..5c2edce4 100644 --- a/psst-core/Cargo.toml +++ b/psst-core/Cargo.toml @@ -10,14 +10,6 @@ gix-config = "0.45.1" time = { version = "0.3.36", features = ["local-offset"] } [dependencies] -psst-protocol = { path = "../psst-protocol" } -rustfm-scrobble = "1.1.1" - -# Login5 dependencies -librespot-protocol = "0.7.1" -protobuf = "3" -sysinfo = "0.35.0" -data-encoding = "2.9" # Common byteorder = { version = "1.5.0" } @@ -28,13 +20,17 @@ num-bigint = { version = "0.4.6", features = ["rand"] } num-traits = { version = "0.2.19" } oauth2 = { version = "4.4.2" } parking_lot = { version = "0.12.3" } -quick-protobuf = { version = "0.8.1" } +librespot-protocol = "0.7.1" +protobuf = "3" +sysinfo = "0.35.0" +data-encoding = "2.9" rand = { version = "0.9.1" } rangemap = { version = "1.5.1" } serde = { version = "1.0.210", features = ["derive"] } serde_json = { version = "1.0.132" } socks = { version = "0.3.4" } tempfile = { version = "3.13.0" } +rustfm-scrobble = "1.1.1" ureq = { version = "3.0.11", features = ["json"] } url = { version = "2.5.2" } diff --git a/psst-core/src/cache.rs b/psst-core/src/cache.rs index 739253a4..b792daa3 100644 --- a/psst-core/src/cache.rs +++ b/psst-core/src/cache.rs @@ -8,10 +8,11 @@ use crate::{ audio::decrypt::AudioKey, error::Error, item_id::{FileId, ItemId}, - protocol::metadata::{Episode, Track}, - util::{deserialize_protobuf, serialize_protobuf}, }; +use librespot_protocol::metadata::{Episode, Track}; +use protobuf::Message; + pub type CacheHandle = Arc; #[derive(Debug)] @@ -61,12 +62,12 @@ impl Cache { impl Cache { pub fn get_track(&self, item_id: ItemId) -> Option { let buf = fs::read(self.track_path(item_id)).ok()?; - deserialize_protobuf(&buf).ok() + Track::parse_from_bytes(&buf).ok() } pub fn save_track(&self, item_id: ItemId, track: &Track) -> Result<(), Error> { log::debug!("saving track to cache: {item_id:?}"); - fs::write(self.track_path(item_id), serialize_protobuf(track)?)?; + fs::write(self.track_path(item_id), track.write_to_bytes()?)?; Ok(()) } @@ -79,12 +80,12 @@ impl Cache { impl Cache { pub fn get_episode(&self, item_id: ItemId) -> Option { let buf = fs::read(self.episode_path(item_id)).ok()?; - deserialize_protobuf(&buf).ok() + Episode::parse_from_bytes(&buf).ok() } pub fn save_episode(&self, item_id: ItemId, episode: &Episode) -> Result<(), Error> { log::debug!("saving episode to cache: {item_id:?}"); - fs::write(self.episode_path(item_id), serialize_protobuf(episode)?)?; + fs::write(self.episode_path(item_id), episode.write_to_bytes()?)?; Ok(()) } diff --git a/psst-core/src/connection/mod.rs b/psst-core/src/connection/mod.rs index bd9daf5a..1c30af2d 100644 --- a/psst-core/src/connection/mod.rs +++ b/psst-core/src/connection/mod.rs @@ -21,13 +21,12 @@ use crate::{ shannon_codec::{ShannonDecoder, ShannonEncoder, ShannonMsg}, }, error::Error, - protocol::authentication::AuthenticationType, - util::{ - default_ureq_agent_builder, deserialize_protobuf, serialize_protobuf, NET_CONNECT_TIMEOUT, - NET_IO_TIMEOUT, - }, + util::{default_ureq_agent_builder, NET_CONNECT_TIMEOUT, NET_IO_TIMEOUT}, }; +use librespot_protocol::authentication::AuthenticationType; +use protobuf::{Enum, Message, MessageField, SpecialFields}; + // Device ID used for authentication message. const DEVICE_ID: &str = "Psst"; @@ -76,7 +75,7 @@ impl From for Credentials { Self { username: Some(value.username), auth_data: value.auth_data.into_bytes(), - auth_type: value.auth_type.into(), + auth_type: AuthenticationType::from_i32(value.auth_type).unwrap_or_default(), } } } @@ -215,7 +214,7 @@ impl Transport { } pub fn exchange_keys(mut stream: TcpStream) -> Result { - use crate::protocol::keyexchange::APResponseMessage; + use librespot_protocol::keyexchange::APResponseMessage; let local_keys = DHLocalKeys::random(); @@ -232,17 +231,18 @@ impl Transport { // hashed together with the shared secret to make a key pair). log::trace!("waiting for AP response"); let apresp_packet = read_packet(&mut stream)?; - let apresp: APResponseMessage = deserialize_protobuf(&apresp_packet[4..])?; + let apresp = APResponseMessage::parse_from_bytes(&apresp_packet[4..])?; log::trace!("received AP response"); // Compute the challenge response and the sending/receiving keys. - let remote_key = &apresp + let remote_key = apresp .challenge - .expect("Missing data") .login_crypto_challenge .diffie_hellman - .expect("Missing data") - .gs; + .gs + .as_ref() + .expect("Missing data"); + let (challenge, send_key, recv_key) = compute_keys( &local_keys.shared_secret(remote_key), &hello_packet, @@ -268,7 +268,7 @@ impl Transport { } pub fn authenticate(&mut self, credentials: Credentials) -> Result { - use crate::protocol::{authentication::APWelcome, keyexchange::APLoginFailed}; + use librespot_protocol::{authentication::APWelcome, keyexchange::APLoginFailed}; // Send a login request with the client credentials. let request = client_response_encrypted(credentials); @@ -279,19 +279,20 @@ impl Transport { match response.cmd { ShannonMsg::AP_WELCOME => { - let welcome_data: APWelcome = - deserialize_protobuf(&response.payload).expect("Missing data"); + let welcome_data = + APWelcome::parse_from_bytes(&response.payload).expect("Missing data"); + Ok(Credentials { - username: Some(welcome_data.canonical_username), - auth_data: welcome_data.reusable_auth_credentials, - auth_type: welcome_data.reusable_auth_credentials_type, + username: Some(welcome_data.canonical_username().to_string()), + auth_data: welcome_data.reusable_auth_credentials().to_vec(), + auth_type: welcome_data.reusable_auth_credentials_type(), }) } ShannonMsg::AUTH_FAILURE => { - let error_data: APLoginFailed = - deserialize_protobuf(&response.payload).expect("Missing data"); + let error_data = + APLoginFailed::parse_from_bytes(&response.payload).expect("Missing data"); Err(Error::AuthFailed { - code: error_data.error_code as _, + code: error_data.error_code() as _, }) } _ => { @@ -321,44 +322,57 @@ fn make_packet(prefix: &[u8], data: &[u8]) -> Vec { } fn client_hello(public_key: Vec, nonce: Vec) -> Vec { - use crate::protocol::keyexchange::*; + use librespot_protocol::keyexchange::*; let hello = ClientHello { - build_info: BuildInfo { - platform: Platform::PLATFORM_LINUX_X86, - product: Product::PRODUCT_PARTNER, + build_info: MessageField::some(BuildInfo { + platform: Some(Platform::PLATFORM_LINUX_X86.into()), + product: Some(Product::PRODUCT_PARTNER.into()), product_flags: vec![], - version: 109_800_078, - }, - cryptosuites_supported: vec![Cryptosuite::CRYPTO_SUITE_SHANNON], + version: Some(109_800_078), + special_fields: SpecialFields::new(), + }), + cryptosuites_supported: vec![Cryptosuite::CRYPTO_SUITE_SHANNON.into()], fingerprints_supported: vec![], powschemes_supported: vec![], - login_crypto_hello: LoginCryptoHelloUnion { - diffie_hellman: Some(LoginCryptoDiffieHellmanHello { - gc: public_key, - server_keys_known: 1, + login_crypto_hello: MessageField::some(LoginCryptoHelloUnion { + diffie_hellman: MessageField::some(LoginCryptoDiffieHellmanHello { + gc: Some(public_key), + server_keys_known: Some(1), + special_fields: SpecialFields::new(), }), - }, - client_nonce: nonce, + special_fields: SpecialFields::new(), + }), + client_nonce: Some(nonce), padding: Some(vec![0x1e]), - feature_set: None, + feature_set: None.into(), + special_fields: SpecialFields::new(), }; - serialize_protobuf(&hello).expect("Failed to serialize") + hello + .write_to_bytes() + .expect("Failed to serialize client hello") } fn client_response_plaintext(challenge: Vec) -> Vec { - use crate::protocol::keyexchange::*; + use librespot_protocol::keyexchange::*; let response = ClientResponsePlaintext { - login_crypto_response: LoginCryptoResponseUnion { - diffie_hellman: Some(LoginCryptoDiffieHellmanResponse { hmac: challenge }), - }, - pow_response: PoWResponseUnion::default(), - crypto_response: CryptoResponseUnion::default(), + login_crypto_response: MessageField::some(LoginCryptoResponseUnion { + diffie_hellman: MessageField::some(LoginCryptoDiffieHellmanResponse { + hmac: Some(challenge), + special_fields: SpecialFields::new(), + }), + special_fields: SpecialFields::new(), + }), + pow_response: MessageField::some(PoWResponseUnion::default()), + crypto_response: MessageField::some(CryptoResponseUnion::default()), + special_fields: SpecialFields::new(), }; - serialize_protobuf(&response).expect("Failed to serialize") + response + .write_to_bytes() + .expect("Failed to serialize client response") } fn compute_keys( @@ -389,22 +403,27 @@ fn compute_keys( } fn client_response_encrypted(credentials: Credentials) -> ShannonMsg { - use crate::protocol::authentication::{ClientResponseEncrypted, LoginCredentials, SystemInfo}; + use librespot_protocol::authentication::{ + ClientResponseEncrypted, LoginCredentials, SystemInfo, Os, CpuFamily + }; let response = ClientResponseEncrypted { - login_credentials: LoginCredentials { + login_credentials: MessageField::some(LoginCredentials { username: credentials.username, auth_data: Some(credentials.auth_data), - typ: credentials.auth_type, - }, - system_info: SystemInfo { + typ: Some(credentials.auth_type.into()), + special_fields: SpecialFields::new(), + }), + system_info: MessageField::some(SystemInfo { device_id: Some(DEVICE_ID.to_string()), system_information_string: Some("librespot_but_actually_psst".to_string()), + os: Some(Os::default().into()), + cpu_family: Some(CpuFamily::default().into()), ..SystemInfo::default() - }, + }), ..ClientResponseEncrypted::default() }; - let buf = serialize_protobuf(&response).expect("Failed to serialize"); + let buf = response.write_to_bytes().expect("Failed to serialize"); ShannonMsg::new(ShannonMsg::LOGIN, buf) } diff --git a/psst-core/src/lib.rs b/psst-core/src/lib.rs index 2dd2d8ca..a141a2c8 100644 --- a/psst-core/src/lib.rs +++ b/psst-core/src/lib.rs @@ -20,5 +20,3 @@ pub mod player; pub mod session; pub mod system_info; pub mod util; - -pub use psst_protocol as protocol; diff --git a/psst-core/src/metadata.rs b/psst-core/src/metadata.rs index b044af81..7eaec7f3 100644 --- a/psst-core/src/metadata.rs +++ b/psst-core/src/metadata.rs @@ -1,16 +1,16 @@ use std::time::Duration; -use quick_protobuf::MessageRead; - use crate::{ error::Error, item_id::{FileId, ItemId, ItemIdType}, player::file::{AudioFormat, MediaFile, MediaPath}, - protocol::metadata::{AudioFile, Episode, Restriction, Track}, session::SessionService, }; -pub trait Fetch: MessageRead<'static> { +use librespot_protocol::metadata::restriction::Country_restriction; +use librespot_protocol::metadata::{AudioFile, Episode, Restriction, Track}; + +pub trait Fetch: protobuf::Message { fn uri(id: ItemId) -> String; fn fetch(session: &SessionService, id: ItemId) -> Result { session.connected()?.get_mercury_protobuf(Self::uri(id)) @@ -55,7 +55,7 @@ impl ToMediaPath for Track { Some(MediaPath { item_id: ItemId::from_raw(self.gid.as_ref()?, ItemIdType::Track)?, file_id: FileId::from_raw(file.file_id.as_ref()?)?, - file_format: AudioFormat::from_protocol(file.format?), + file_format: AudioFormat::from_protocol(file.format()), duration: Duration::from_millis(self.duration? as u64), }) } @@ -73,11 +73,11 @@ impl ToMediaPath for Episode { } fn to_media_path(&self, preferred_bitrate: usize) -> Option { - let file = select_preferred_file(&self.file, preferred_bitrate)?; + let file = select_preferred_file(&self.audio, preferred_bitrate)?; Some(MediaPath { item_id: ItemId::from_raw(self.gid.as_ref()?, ItemIdType::Podcast)?, file_id: FileId::from_raw(file.file_id.as_ref()?)?, - file_format: AudioFormat::from_protocol(file.format?), + file_format: AudioFormat::from_protocol(file.format()), duration: Duration::from_millis(self.duration? as u64), }) } @@ -89,16 +89,21 @@ fn select_preferred_file(files: &[AudioFile], preferred_bitrate: usize) -> Optio .find_map(|&preferred_format| { files .iter() - .find(|file| file.format == Some(preferred_format)) + .find(|file| file.format == Some(preferred_format.into())) }) } fn is_restricted_in_region(restriction: &Restriction, country: &str) -> bool { - if let Some(allowed) = &restriction.countries_allowed { - return !is_country_in_list(allowed.as_bytes(), country.as_bytes()); - } - if let Some(forbidden) = &restriction.countries_forbidden { - return is_country_in_list(forbidden.as_bytes(), country.as_bytes()); + if let Some(list) = &restriction.country_restriction { + return match list { + Country_restriction::CountriesAllowed(allowed) => { + !is_country_in_list(allowed.as_bytes(), country.as_bytes()) + } + Country_restriction::CountriesForbidden(forbidden) => { + is_country_in_list(forbidden.as_bytes(), country.as_bytes()) + } + _ => false, + }; } false } diff --git a/psst-core/src/player/file.rs b/psst-core/src/player/file.rs index 46f5fbcb..b919c4fd 100644 --- a/psst-core/src/player/file.rs +++ b/psst-core/src/player/file.rs @@ -20,10 +20,11 @@ use crate::{ cdn::{CdnHandle, CdnUrl}, error::Error, item_id::{FileId, ItemId}, - protocol::metadata::mod_AudioFile::Format, util::OffsetFile, }; +use librespot_protocol::metadata::audio_file::Format; + use super::storage::{StreamRequest, StreamStorage, StreamWriter}; #[derive(Debug, Clone, Copy)] diff --git a/psst-core/src/player/item.rs b/psst-core/src/player/item.rs index ebd76a6b..6b9c9718 100644 --- a/psst-core/src/player/item.rs +++ b/psst-core/src/player/item.rs @@ -9,10 +9,11 @@ use crate::{ error::Error, item_id::{ItemId, ItemIdType, LocalItemRegistry}, metadata::{Fetch, ToMediaPath}, - protocol::metadata::{Episode, Track}, session::SessionService, }; +use librespot_protocol::metadata::{Episode, Track}; + use super::{ file::{AudioFormat, MediaFile, MediaPath}, PlaybackConfig, diff --git a/psst-core/src/session/mercury.rs b/psst-core/src/session/mercury.rs index cd66be92..cea881c0 100644 --- a/psst-core/src/session/mercury.rs +++ b/psst-core/src/session/mercury.rs @@ -6,12 +6,10 @@ use std::{ use byteorder::{ReadBytesExt, BE}; use crossbeam_channel::Sender; -use crate::{ - connection::shannon_codec::ShannonMsg, - error::Error, - protocol::mercury::Header, - util::{deserialize_protobuf, serialize_protobuf, Sequence}, -}; +use crate::{connection::shannon_codec::ShannonMsg, util::Sequence}; + +use librespot_protocol::mercury::Header; +use protobuf::Message; pub struct MercuryDispatcher { sequence: Sequence, @@ -100,7 +98,10 @@ impl MercuryRequest { method: Some(self.method), ..Header::default() }; - let header_part = serialize_protobuf(&header).expect("Failed to serialize message header"); + let header_part = header + .write_to_bytes() + .expect("Failed to serialize message header"); + let mut parts = self.payload; parts.insert(0, header_part); parts @@ -117,8 +118,9 @@ pub struct MercuryResponse { impl MercuryResponse { fn decode_from_parts(mut parts: Vec>) -> Self { let header_part = parts.remove(0); - let header: Header = - deserialize_protobuf(&header_part).expect("Failed to deserialize message header"); + let header = Header::parse_from_bytes(&header_part) + .expect("Failed to deserialize message header"); + Self { uri: header.uri.unwrap(), status_code: header.status_code.unwrap(), @@ -214,10 +216,4 @@ impl Msg { results } -} - -impl From for Error { - fn from(err: quick_protobuf::Error) -> Self { - Error::IoError(err.into()) - } -} +} \ No newline at end of file diff --git a/psst-core/src/session/mod.rs b/psst-core/src/session/mod.rs index fd6ece41..7e6aacb7 100644 --- a/psst-core/src/session/mod.rs +++ b/psst-core/src/session/mod.rs @@ -17,7 +17,6 @@ use std::{ use crossbeam_channel::{unbounded, Receiver, Sender}; use parking_lot::Mutex; -use quick_protobuf::MessageRead; use serde::de::DeserializeOwned; use crate::{ @@ -28,7 +27,6 @@ use crate::{ }, error::Error, item_id::{FileId, ItemId}, - util::deserialize_protobuf, }; use self::{ @@ -214,10 +212,10 @@ pub struct SessionHandle { impl SessionHandle { pub fn get_mercury_protobuf(&self, uri: String) -> Result where - T: MessageRead<'static>, + T: protobuf::Message, { let payload = self.get_mercury_bytes(uri)?; - let message = deserialize_protobuf(&payload)?; + let message = T::parse_from_bytes(&payload)?; Ok(message) } diff --git a/psst-core/src/util.rs b/psst-core/src/util.rs index 07de7b18..376a7f83 100644 --- a/psst-core/src/util.rs +++ b/psst-core/src/util.rs @@ -1,7 +1,6 @@ use crate::error::Error; use byteorder::{BigEndian, ByteOrder}; use num_traits::{One, WrappingAdd}; -use quick_protobuf::{BytesReader, MessageRead, MessageWrite, Writer}; use sha1::{Digest, Sha1}; use std::time::Instant; use std::{io, io::SeekFrom, mem, time::Duration}; @@ -165,31 +164,3 @@ where self.stream.seek(pos) } } - -pub fn serialize_protobuf(msg: &T) -> Result, Error> -where - T: MessageWrite, -{ - let mut buf = Vec::with_capacity(msg.get_size()); - let mut writer = Writer::new(&mut buf); - msg.write_message(&mut writer)?; - Ok(buf) -} - -pub fn deserialize_protobuf(buf: &[u8]) -> Result -where - T: MessageRead<'static>, -{ - let mut reader = BytesReader::from_bytes(buf); - let msg = { - let static_buf: &'static [u8] = unsafe { - // Sigh. While `quick-protobuf` supports `--owned` variations of messages, they - // are not compatible with `--dont_use_cow` flag, which, by itself, is already - // producing messages that fully own their fields. Therefore, we can pretend - // the byte slice is static, because `msg` does not retain it. - std::mem::transmute(buf) - }; - T::from_reader(&mut reader, static_buf)? - }; - Ok(msg) -} diff --git a/psst-protocol/Cargo.toml b/psst-protocol/Cargo.toml deleted file mode 100644 index 9e7ecb0d..00000000 --- a/psst-protocol/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "psst-protocol" -version = "0.1.0" -authors = ["Jan Pochyla "] -edition = "2021" - -[dependencies] -quick-protobuf = "0.8.1" diff --git a/psst-protocol/build.sh b/psst-protocol/build.sh deleted file mode 100755 index 82f55603..00000000 --- a/psst-protocol/build.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh - -pb-rs \ - --dont_use_cow \ - --output_directory src \ - "proto/authentication.proto" \ - "proto/keyexchange.proto" \ - "proto/mercury.proto" \ - "proto/metadata.proto" -rm src/mod.rs diff --git a/psst-protocol/proto/authentication.proto b/psst-protocol/proto/authentication.proto deleted file mode 100644 index e11699fb..00000000 --- a/psst-protocol/proto/authentication.proto +++ /dev/null @@ -1,167 +0,0 @@ -syntax = "proto2"; - -package authentication; - -message ClientResponseEncrypted { - required LoginCredentials login_credentials = 0xa; - optional AccountCreation account_creation = 0x14; - optional FingerprintResponseUnion fingerprint_response = 0x1e; - optional PeerTicketUnion peer_ticket = 0x28; - required SystemInfo system_info = 0x32; - optional string platform_model = 0x3c; - optional string version_string = 0x46; - optional LibspotifyAppKey appkey = 0x50; - optional ClientInfo client_info = 0x5a; -} - -message LoginCredentials { - optional string username = 0xa; - required AuthenticationType typ = 0x14; - optional bytes auth_data = 0x1e; -} - -enum AuthenticationType { - AUTHENTICATION_USER_PASS = 0x0; - AUTHENTICATION_STORED_SPOTIFY_CREDENTIALS = 0x1; - AUTHENTICATION_STORED_FACEBOOK_CREDENTIALS = 0x2; - AUTHENTICATION_SPOTIFY_TOKEN = 0x3; - AUTHENTICATION_FACEBOOK_TOKEN = 0x4; -} - -enum AccountCreation { - ACCOUNT_CREATION_ALWAYS_PROMPT = 0x1; - ACCOUNT_CREATION_ALWAYS_CREATE = 0x3; -} - -message FingerprintResponseUnion { - optional FingerprintGrainResponse grain = 0xa; - optional FingerprintHmacRipemdResponse hmac_ripemd = 0x14; -} - -message FingerprintGrainResponse { - required bytes encrypted_key = 0xa; -} - -message FingerprintHmacRipemdResponse { - required bytes hmac = 0xa; -} - -message PeerTicketUnion { - optional PeerTicketPublicKey public_key = 0xa; - optional PeerTicketOld old_ticket = 0x14; -} - -message PeerTicketPublicKey { - required bytes public_key = 0xa; -} - -message PeerTicketOld { - required bytes peer_ticket = 0xa; - required bytes peer_ticket_signature = 0x14; -} - -message SystemInfo { - required CpuFamily cpu_family = 0xa; - optional uint32 cpu_subtype = 0x14; - optional uint32 cpu_ext = 0x1e; - optional Brand brand = 0x28; - optional uint32 brand_flags = 0x32; - required Os os = 0x3c; - optional uint32 os_version = 0x46; - optional uint32 os_ext = 0x50; - optional string system_information_string = 0x5a; - optional string device_id = 0x64; -} - -enum CpuFamily { - CPU_UNKNOWN = 0x0; - CPU_X86 = 0x1; - CPU_X86_64 = 0x2; - CPU_PPC = 0x3; - CPU_PPC_64 = 0x4; - CPU_ARM = 0x5; - CPU_IA64 = 0x6; - CPU_SH = 0x7; - CPU_MIPS = 0x8; - CPU_BLACKFIN = 0x9; -} - -enum Brand { - BRAND_UNBRANDED = 0x0; - BRAND_INQ = 0x1; - BRAND_HTC = 0x2; - BRAND_NOKIA = 0x3; -} - -enum Os { - OS_UNKNOWN = 0x0; - OS_WINDOWS = 0x1; - OS_OSX = 0x2; - OS_IPHONE = 0x3; - OS_S60 = 0x4; - OS_LINUX = 0x5; - OS_WINDOWS_CE = 0x6; - OS_ANDROID = 0x7; - OS_PALM = 0x8; - OS_FREEBSD = 0x9; - OS_BLACKBERRY = 0xa; - OS_SONOS = 0xb; - OS_LOGITECH = 0xc; - OS_WP7 = 0xd; - OS_ONKYO = 0xe; - OS_PHILIPS = 0xf; - OS_WD = 0x10; - OS_VOLVO = 0x11; - OS_TIVO = 0x12; - OS_AWOX = 0x13; - OS_MEEGO = 0x14; - OS_QNXNTO = 0x15; - OS_BCO = 0x16; -} - -message LibspotifyAppKey { - required uint32 version = 0x1; - required bytes devkey = 0x2; - required bytes signature = 0x3; - required string useragent = 0x4; - required bytes callback_hash = 0x5; -} - -message ClientInfo { - optional bool limited = 0x1; - optional ClientInfoFacebook fb = 0x2; - optional string language = 0x3; -} - -message ClientInfoFacebook { - optional string machine_id = 0x1; -} - -message APWelcome { - required string canonical_username = 0xa; - required AccountType account_type_logged_in = 0x14; - required AccountType credentials_type_logged_in = 0x19; - required AuthenticationType reusable_auth_credentials_type = 0x1e; - required bytes reusable_auth_credentials = 0x28; - optional bytes lfs_secret = 0x32; - optional AccountInfo account_info = 0x3c; - optional AccountInfoFacebook fb = 0x46; -} - -enum AccountType { - Spotify = 0x0; - Facebook = 0x1; -} - -message AccountInfo { - optional AccountInfoSpotify spotify = 0x1; - optional AccountInfoFacebook facebook = 0x2; -} - -message AccountInfoSpotify { -} - -message AccountInfoFacebook { - optional string access_token = 0x1; - optional string machine_id = 0x2; -} diff --git a/psst-protocol/proto/keyexchange.proto b/psst-protocol/proto/keyexchange.proto deleted file mode 100644 index 6f122fd8..00000000 --- a/psst-protocol/proto/keyexchange.proto +++ /dev/null @@ -1,230 +0,0 @@ -syntax = "proto2"; - -package keyexchange; - -message ClientHello { - required BuildInfo build_info = 0xa; - repeated Fingerprint fingerprints_supported = 0x14; - repeated Cryptosuite cryptosuites_supported = 0x1e; - repeated Powscheme powschemes_supported = 0x28; - required LoginCryptoHelloUnion login_crypto_hello = 0x32; - required bytes client_nonce = 0x3c; - optional bytes padding = 0x46; - optional FeatureSet feature_set = 0x50; -} - - -message BuildInfo { - required Product product = 0xa; - repeated ProductFlags product_flags = 0x14; - required Platform platform = 0x1e; - required uint64 version = 0x28; -} - -enum Product { - PRODUCT_CLIENT = 0x0; - PRODUCT_LIBSPOTIFY= 0x1; - PRODUCT_MOBILE = 0x2; - PRODUCT_PARTNER = 0x3; - PRODUCT_LIBSPOTIFY_EMBEDDED = 0x5; -} - -enum ProductFlags { - PRODUCT_FLAG_NONE = 0x0; - PRODUCT_FLAG_DEV_BUILD = 0x1; -} - -enum Platform { - PLATFORM_WIN32_X86 = 0x0; - PLATFORM_OSX_X86 = 0x1; - PLATFORM_LINUX_X86 = 0x2; - PLATFORM_IPHONE_ARM = 0x3; - PLATFORM_S60_ARM = 0x4; - PLATFORM_OSX_PPC = 0x5; - PLATFORM_ANDROID_ARM = 0x6; - PLATFORM_WINDOWS_CE_ARM = 0x7; - PLATFORM_LINUX_X86_64 = 0x8; - PLATFORM_OSX_X86_64 = 0x9; - PLATFORM_PALM_ARM = 0xa; - PLATFORM_LINUX_SH = 0xb; - PLATFORM_FREEBSD_X86 = 0xc; - PLATFORM_FREEBSD_X86_64 = 0xd; - PLATFORM_BLACKBERRY_ARM = 0xe; - PLATFORM_SONOS = 0xf; - PLATFORM_LINUX_MIPS = 0x10; - PLATFORM_LINUX_ARM = 0x11; - PLATFORM_LOGITECH_ARM = 0x12; - PLATFORM_LINUX_BLACKFIN = 0x13; - PLATFORM_WP7_ARM = 0x14; - PLATFORM_ONKYO_ARM = 0x15; - PLATFORM_QNXNTO_ARM = 0x16; - PLATFORM_BCO_ARM = 0x17; -} - -enum Fingerprint { - FINGERPRINT_GRAIN = 0x0; - FINGERPRINT_HMAC_RIPEMD = 0x1; -} - -enum Cryptosuite { - CRYPTO_SUITE_SHANNON = 0x0; - CRYPTO_SUITE_RC4_SHA1_HMAC = 0x1; -} - -enum Powscheme { - POW_HASH_CASH = 0x0; -} - - -message LoginCryptoHelloUnion { - optional LoginCryptoDiffieHellmanHello diffie_hellman = 0xa; -} - - -message LoginCryptoDiffieHellmanHello { - required bytes gc = 0xa; - required uint32 server_keys_known = 0x14; -} - - -message FeatureSet { - optional bool autoupdate2 = 0x1; - optional bool current_location = 0x2; -} - - -message APResponseMessage { - optional APChallenge challenge = 0xa; - optional UpgradeRequiredMessage upgrade = 0x14; - optional APLoginFailed login_failed = 0x1e; -} - -message APChallenge { - required LoginCryptoChallengeUnion login_crypto_challenge = 0xa; - required FingerprintChallengeUnion fingerprint_challenge = 0x14; - required PoWChallengeUnion pow_challenge = 0x1e; - required CryptoChallengeUnion crypto_challenge = 0x28; - required bytes server_nonce = 0x32; - optional bytes padding = 0x3c; -} - -message LoginCryptoChallengeUnion { - optional LoginCryptoDiffieHellmanChallenge diffie_hellman = 0xa; -} - -message LoginCryptoDiffieHellmanChallenge { - required bytes gs = 0xa; - required int32 server_signature_key = 0x14; - required bytes gs_signature = 0x1e; -} - -message FingerprintChallengeUnion { - optional FingerprintGrainChallenge grain = 0xa; - optional FingerprintHmacRipemdChallenge hmac_ripemd = 0x14; -} - - -message FingerprintGrainChallenge { - required bytes kek = 0xa; -} - - -message FingerprintHmacRipemdChallenge { - required bytes challenge = 0xa; -} - - -message PoWChallengeUnion { - optional PoWHashCashChallenge hash_cash = 0xa; -} - -message PoWHashCashChallenge { - optional bytes prefix = 0xa; - optional int32 length = 0x14; - optional int32 target = 0x1e; -} - - -message CryptoChallengeUnion { - optional CryptoShannonChallenge shannon = 0xa; - optional CryptoRc4Sha1HmacChallenge rc4_sha1_hmac = 0x14; -} - - -message CryptoShannonChallenge { -} - - -message CryptoRc4Sha1HmacChallenge { -} - - -message UpgradeRequiredMessage { - required bytes upgrade_signed_part = 0xa; - required bytes signature = 0x14; - optional string http_suffix = 0x1e; -} - -message APLoginFailed { - required ErrorCode error_code = 0xa; - optional int32 retry_delay = 0x14; - optional int32 expiry = 0x1e; - optional string error_description = 0x28; -} - -enum ErrorCode { - ProtocolError = 0x0; - TryAnotherAP = 0x2; - BadConnectionId = 0x5; - TravelRestriction = 0x9; - PremiumAccountRequired = 0xb; - BadCredentials = 0xc; - CouldNotValidateCredentials = 0xd; - AccountExists = 0xe; - ExtraVerificationRequired = 0xf; - InvalidAppKey = 0x10; - ApplicationBanned = 0x11; -} - -message ClientResponsePlaintext { - required LoginCryptoResponseUnion login_crypto_response = 0xa; - required PoWResponseUnion pow_response = 0x14; - required CryptoResponseUnion crypto_response = 0x1e; -} - - -message LoginCryptoResponseUnion { - optional LoginCryptoDiffieHellmanResponse diffie_hellman = 0xa; -} - - -message LoginCryptoDiffieHellmanResponse { - required bytes hmac = 0xa; -} - - -message PoWResponseUnion { - optional PoWHashCashResponse hash_cash = 0xa; -} - - -message PoWHashCashResponse { - required bytes hash_suffix = 0xa; -} - - -message CryptoResponseUnion { - optional CryptoShannonResponse shannon = 0xa; - optional CryptoRc4Sha1HmacResponse rc4_sha1_hmac = 0x14; -} - - -message CryptoShannonResponse { - optional int32 dummy = 0x1; -} - - -message CryptoRc4Sha1HmacResponse { - optional int32 dummy = 0x1; -} - diff --git a/psst-protocol/proto/mercury.proto b/psst-protocol/proto/mercury.proto deleted file mode 100644 index d08dfe49..00000000 --- a/psst-protocol/proto/mercury.proto +++ /dev/null @@ -1,47 +0,0 @@ -syntax = "proto2"; - -package mercury; - -message MercuryMultiGetRequest { - repeated MercuryRequest request = 0x1; -} - -message MercuryMultiGetReply { - repeated MercuryReply reply = 0x1; -} - -message MercuryRequest { - optional string uri = 0x1; - optional string content_type = 0x2; - optional bytes body = 0x3; - optional bytes etag = 0x4; -} - -message MercuryReply { - optional sint32 status_code = 0x1; - optional string status_message = 0x2; - optional CachePolicy cache_policy = 0x3; - enum CachePolicy { - CACHE_NO = 0x1; - CACHE_PRIVATE = 0x2; - CACHE_PUBLIC = 0x3; - } - optional sint32 ttl = 0x4; - optional bytes etag = 0x5; - optional string content_type = 0x6; - optional bytes body = 0x7; -} - -message Header { - optional string uri = 0x01; - optional string content_type = 0x02; - optional string method = 0x03; - optional sint32 status_code = 0x04; - repeated UserField user_fields = 0x06; -} - -message UserField { - optional string key = 0x01; - optional bytes value = 0x02; -} - diff --git a/psst-protocol/proto/metadata.proto b/psst-protocol/proto/metadata.proto deleted file mode 100644 index fee35d2c..00000000 --- a/psst-protocol/proto/metadata.proto +++ /dev/null @@ -1,268 +0,0 @@ -syntax = "proto2"; - -package metadata; - -message TopTracks { - optional string country = 0x1; - repeated Track track = 0x2; -} - -message ActivityPeriod { - optional sint32 start_year = 0x1; - optional sint32 end_year = 0x2; - optional sint32 decade = 0x3; -} - -message Artist { - optional bytes gid = 0x1; - optional string name = 0x2; - optional sint32 popularity = 0x3; - repeated TopTracks top_track = 0x4; - repeated AlbumGroup album_group = 0x5; - repeated AlbumGroup single_group = 0x6; - repeated AlbumGroup compilation_group = 0x7; - repeated AlbumGroup appears_on_group = 0x8; - repeated string genre = 0x9; - repeated ExternalId external_id = 0xa; - repeated Image portrait = 0xb; - repeated Biography biography = 0xc; - repeated ActivityPeriod activity_period = 0xd; - repeated Restriction restriction = 0xe; - repeated Artist related = 0xf; - optional bool is_portrait_album_cover = 0x10; - optional ImageGroup portrait_group = 0x11; -} - -message AlbumGroup { - repeated Album album = 0x1; -} - -message Date { - optional sint32 year = 0x1; - optional sint32 month = 0x2; - optional sint32 day = 0x3; - optional sint32 hour = 0x4; - optional sint32 minute = 0x5; -} - -message Album { - optional bytes gid = 0x1; - optional string name = 0x2; - repeated Artist artist = 0x3; - optional Type typ = 0x4; - enum Type { - ALBUM = 0x1; - SINGLE = 0x2; - COMPILATION = 0x3; - EP = 0x4; - } - optional string label = 0x5; - optional Date date = 0x6; - optional sint32 popularity = 0x7; - repeated string genre = 0x8; - repeated Image cover = 0x9; - repeated ExternalId external_id = 0xa; - repeated Disc disc = 0xb; - repeated string review = 0xc; - repeated Copyright copyright = 0xd; - repeated Restriction restriction = 0xe; - repeated Album related = 0xf; - repeated SalePeriod sale_period = 0x10; - optional ImageGroup cover_group = 0x11; -} - -message Track { - optional bytes gid = 0x1; - optional string name = 0x2; - optional Album album = 0x3; - repeated Artist artist = 0x4; - optional sint32 number = 0x5; - optional sint32 disc_number = 0x6; - optional sint32 duration = 0x7; - optional sint32 popularity = 0x8; - optional bool explicit = 0x9; - repeated ExternalId external_id = 0xa; - repeated Restriction restriction = 0xb; - repeated AudioFile file = 0xc; - repeated Track alternative = 0xd; - repeated SalePeriod sale_period = 0xe; - repeated AudioFile preview = 0xf; -} - -message Image { - optional bytes file_id = 0x1; - optional Size size = 0x2; - enum Size { - DEFAULT = 0x0; - SMALL = 0x1; - LARGE = 0x2; - XLARGE = 0x3; - } - optional sint32 width = 0x3; - optional sint32 height = 0x4; -} - -message ImageGroup { - repeated Image image = 0x1; -} - -message Biography { - optional string text = 0x1; - repeated Image portrait = 0x2; - repeated ImageGroup portrait_group = 0x3; -} - -message Disc { - optional sint32 number = 0x1; - optional string name = 0x2; - repeated Track track = 0x3; -} - -message Copyright { - optional Type typ = 0x1; - enum Type { - P = 0x0; - C = 0x1; - } - optional string text = 0x2; -} - -message Restriction { - enum Catalogue { - AD = 0; - SUBSCRIPTION = 1; - CATALOGUE_ALL = 2; - SHUFFLE = 3; - COMMERCIAL = 4; - } - enum Type { - STREAMING = 0x0; - } - repeated Catalogue catalogue = 0x1; - optional string countries_allowed = 0x2; - optional string countries_forbidden = 0x3; - optional Type typ = 0x4; - - repeated string catalogue_str = 0x5; -} - -message Availability { - repeated string catalogue_str = 0x1; - optional Date start = 0x2; -} - -message SalePeriod { - repeated Restriction restriction = 0x1; - optional Date start = 0x2; - optional Date end = 0x3; -} - -message ExternalId { - optional string typ = 0x1; - optional string id = 0x2; -} - -message AudioFile { - optional bytes file_id = 0x1; - optional Format format = 0x2; - enum Format { - OGG_VORBIS_96 = 0x0; - OGG_VORBIS_160 = 0x1; - OGG_VORBIS_320 = 0x2; - MP3_256 = 0x3; - MP3_320 = 0x4; - MP3_160 = 0x5; - MP3_96 = 0x6; - MP3_160_ENC = 0x7; - // v4 - // AAC_24 = 0x8; - // AAC_48 = 0x9; - MP4_128_DUAL = 0x8; - OTHER3 = 0x9; - AAC_160 = 0xa; - AAC_320 = 0xb; - MP4_128 = 0xc; - OTHER5 = 0xd; - } -} - -message VideoFile { - optional bytes file_id = 1; -} - -// Podcast Protos -message Show { - enum MediaType { - MIXED = 0; - AUDIO = 1; - VIDEO = 2; - } - enum ConsumptionOrder { - SEQUENTIAL = 1; - EPISODIC = 2; - RECENT = 3; - } - enum PassthroughEnum { - UNKNOWN = 0; - NONE = 1; - ALLOWED = 2; - } - optional bytes gid = 0x1; - optional string name = 0x2; - optional string description = 0x40; - optional sint32 deprecated_popularity = 0x41; - optional string publisher = 0x42; - optional string language = 0x43; - optional bool explicit = 0x44; - optional ImageGroup covers = 0x45; - repeated Episode episode = 0x46; - repeated Copyright copyright = 0x47; - repeated Restriction restriction = 0x48; - repeated string keyword = 0x49; - optional MediaType media_type = 0x4A; - optional ConsumptionOrder consumption_order = 0x4B; - optional bool interpret_restriction_using_geoip = 0x4C; - repeated Availability availability = 0x4E; - optional string country_of_origin = 0x4F; - repeated Category categories = 0x50; - optional PassthroughEnum passthrough = 0x51; -} - -message Episode { - optional bytes gid = 0x1; - optional string name = 0x2; - optional sint32 duration = 0x7; - optional sint32 popularity = 0x8; - repeated AudioFile file = 0xc; - optional string description = 0x40; - optional sint32 number = 0x41; - optional Date publish_time = 0x42; - optional sint32 deprecated_popularity = 0x43; - optional ImageGroup covers = 0x44; - optional string language = 0x45; - optional bool explicit = 0x46; - optional Show show = 0x47; - repeated VideoFile video = 0x48; - repeated VideoFile video_preview = 0x49; - repeated AudioFile audio_preview = 0x4A; - repeated Restriction restriction = 0x4B; - optional ImageGroup freeze_frame = 0x4C; - repeated string keyword = 0x4D; - // Order of these two flags might be wrong! - optional bool suppress_monetization = 0x4E; - optional bool interpret_restriction_using_geoip = 0x4F; - - optional bool allow_background_playback = 0x51; - repeated Availability availability = 0x52; - optional string external_url = 0x53; - optional OriginalAudio original_audio = 0x54; -} - -message Category { - optional string name = 0x1; - repeated Category subcategories = 0x2; -} - -message OriginalAudio { - optional bytes uuid = 0x1; -} diff --git a/psst-protocol/proto/playlist4changes.proto b/psst-protocol/proto/playlist4changes.proto deleted file mode 100644 index b5e9e649..00000000 --- a/psst-protocol/proto/playlist4changes.proto +++ /dev/null @@ -1,89 +0,0 @@ -syntax = "proto2"; - -package playlist; - -import "playlist4ops.proto"; -import "playlist4meta.proto"; -import "playlist4content.proto"; -import "playlist4issues.proto"; - -message ChangeInfo { - optional string user = 0x1; - optional int32 timestamp = 0x2; - optional bool admin = 0x3; - optional bool undo = 0x4; - optional bool redo = 0x5; - optional bool merge = 0x6; - optional bool compressed = 0x7; - optional bool migration = 0x8; -} - -message Delta { - optional bytes base_version = 0x1; - repeated Op ops = 0x2; - optional ChangeInfo info = 0x4; -} - -message Merge { - optional bytes base_version = 0x1; - optional bytes merge_version = 0x2; - optional ChangeInfo info = 0x4; -} - -message ChangeSet { - optional Kind kind = 0x1; - enum Kind { - KIND_UNKNOWN = 0x0; - DELTA = 0x2; - MERGE = 0x3; - } - optional Delta delta = 0x2; - optional Merge merge = 0x3; -} - -message RevisionTaggedChangeSet { - optional bytes revision = 0x1; - optional ChangeSet change_set = 0x2; -} - -message Diff { - optional bytes from_revision = 0x1; - repeated Op ops = 0x2; - optional bytes to_revision = 0x3; -} - -message ListDump { - optional bytes latestRevision = 0x1; - optional int32 length = 0x2; - optional ListAttributes attributes = 0x3; - optional ListChecksum checksum = 0x4; - optional ListItems contents = 0x5; - repeated Delta pendingDeltas = 0x7; -} - -message ListChanges { - optional bytes baseRevision = 0x1; - repeated Delta deltas = 0x2; - optional bool wantResultingRevisions = 0x3; - optional bool wantSyncResult = 0x4; - optional ListDump dump = 0x5; - repeated int32 nonces = 0x6; -} - -message SelectedListContent { - optional bytes revision = 0x1; - optional int32 length = 0x2; - optional ListAttributes attributes = 0x3; - optional ListChecksum checksum = 0x4; - optional ListItems contents = 0x5; - optional Diff diff = 0x6; - optional Diff syncResult = 0x7; - repeated bytes resultingRevisions = 0x8; - optional bool multipleHeads = 0x9; - optional bool upToDate = 0xa; - repeated ClientResolveAction resolveAction = 0xc; - repeated ClientIssue issues = 0xd; - repeated int32 nonces = 0xe; - optional string owner_username =0x10; -} - diff --git a/psst-protocol/proto/playlist4content.proto b/psst-protocol/proto/playlist4content.proto deleted file mode 100644 index d48b3c00..00000000 --- a/psst-protocol/proto/playlist4content.proto +++ /dev/null @@ -1,39 +0,0 @@ -syntax = "proto2"; - -package playlist; - -import "playlist4meta.proto"; -import "playlist4issues.proto"; - -message Item { - optional string uri = 0x1; - optional ItemAttributes attributes = 0x2; -} - -message ListItems { - optional int32 pos = 0x1; - optional bool truncated = 0x2; - repeated Item items = 0x3; -} - -message ContentRange { - optional int32 pos = 0x1; - optional int32 length = 0x2; -} - -message ListContentSelection { - optional bool wantRevision = 0x1; - optional bool wantLength = 0x2; - optional bool wantAttributes = 0x3; - optional bool wantChecksum = 0x4; - optional bool wantContent = 0x5; - optional ContentRange contentRange = 0x6; - optional bool wantDiff = 0x7; - optional bytes baseRevision = 0x8; - optional bytes hintRevision = 0x9; - optional bool wantNothingIfUpToDate = 0xa; - optional bool wantResolveAction = 0xc; - repeated ClientIssue issues = 0xd; - repeated ClientResolveAction resolveAction = 0xe; -} - diff --git a/psst-protocol/proto/playlist4issues.proto b/psst-protocol/proto/playlist4issues.proto deleted file mode 100644 index e04e731c..00000000 --- a/psst-protocol/proto/playlist4issues.proto +++ /dev/null @@ -1,45 +0,0 @@ -syntax = "proto2"; - -package playlist; - -message ClientIssue { - optional Level level = 0x1; - enum Level { - LEVEL_UNKNOWN = 0x0; - LEVEL_DEBUG = 0x1; - LEVEL_INFO = 0x2; - LEVEL_NOTICE = 0x3; - LEVEL_WARNING = 0x4; - LEVEL_ERROR = 0x5; - } - optional Code code = 0x2; - enum Code { - CODE_UNKNOWN = 0x0; - CODE_INDEX_OUT_OF_BOUNDS = 0x1; - CODE_VERSION_MISMATCH = 0x2; - CODE_CACHED_CHANGE = 0x3; - CODE_OFFLINE_CHANGE = 0x4; - CODE_CONCURRENT_CHANGE = 0x5; - } - optional int32 repeatCount = 0x3; -} - -message ClientResolveAction { - optional Code code = 0x1; - enum Code { - CODE_UNKNOWN = 0x0; - CODE_NO_ACTION = 0x1; - CODE_RETRY = 0x2; - CODE_RELOAD = 0x3; - CODE_DISCARD_LOCAL_CHANGES = 0x4; - CODE_SEND_DUMP = 0x5; - CODE_DISPLAY_ERROR_MESSAGE = 0x6; - } - optional Initiator initiator = 0x2; - enum Initiator { - INITIATOR_UNKNOWN = 0x0; - INITIATOR_SERVER = 0x1; - INITIATOR_CLIENT = 0x2; - } -} - diff --git a/psst-protocol/proto/playlist4meta.proto b/psst-protocol/proto/playlist4meta.proto deleted file mode 100644 index b6625096..00000000 --- a/psst-protocol/proto/playlist4meta.proto +++ /dev/null @@ -1,54 +0,0 @@ -syntax = "proto2"; - -package playlist; - -message ListChecksum { - optional int32 version = 0x1; - optional bytes sha1 = 0x4; -} - -message DownloadFormat { - optional Codec codec = 0x1; - enum Codec { - CODEC_UNKNOWN = 0x0; - OGG_VORBIS = 0x1; - FLAC = 0x2; - MPEG_1_LAYER_3 = 0x3; - } -} - -message ListAttributes { - optional string name = 0x1; - optional string description = 0x2; - optional bytes picture = 0x3; - optional bool collaborative = 0x4; - optional string pl3_version = 0x5; - optional bool deleted_by_owner = 0x6; - optional bool restricted_collaborative = 0x7; - optional int64 deprecated_client_id = 0x8; - optional bool public_starred = 0x9; - optional string client_id = 0xa; -} - -message ItemAttributes { - optional string added_by = 0x1; - optional int64 timestamp = 0x2; - optional string message = 0x3; - optional bool seen = 0x4; - optional int64 download_count = 0x5; - optional DownloadFormat download_format = 0x6; - optional string sevendigital_id = 0x7; - optional int64 sevendigital_left = 0x8; - optional int64 seen_at = 0x9; - optional bool public = 0xa; -} - -message StringAttribute { - optional string key = 0x1; - optional string value = 0x2; -} - -message StringAttributes { - repeated StringAttribute attribute = 0x1; -} - diff --git a/psst-protocol/proto/playlist4ops.proto b/psst-protocol/proto/playlist4ops.proto deleted file mode 100644 index 43e93f64..00000000 --- a/psst-protocol/proto/playlist4ops.proto +++ /dev/null @@ -1,105 +0,0 @@ -syntax = "proto2"; - -package playlist; - -import "playlist4meta.proto"; -import "playlist4content.proto"; - -message Add { - optional int32 fromIndex = 0x1; - repeated Item items = 0x2; - optional ListChecksum list_checksum = 0x3; - optional bool addLast = 0x4; - optional bool addFirst = 0x5; -} - -message Rem { - optional int32 fromIndex = 0x1; - optional int32 length = 0x2; - repeated Item items = 0x3; - optional ListChecksum list_checksum = 0x4; - optional ListChecksum items_checksum = 0x5; - optional ListChecksum uris_checksum = 0x6; - optional bool itemsAsKey = 0x7; -} - -message Mov { - optional int32 fromIndex = 0x1; - optional int32 length = 0x2; - optional int32 toIndex = 0x3; - optional ListChecksum list_checksum = 0x4; - optional ListChecksum items_checksum = 0x5; - optional ListChecksum uris_checksum = 0x6; -} - -message ItemAttributesPartialState { - optional ItemAttributes values = 0x1; - repeated ItemAttributeKind no_value = 0x2; - - enum ItemAttributeKind { - ITEM_UNKNOWN = 0x0; - ITEM_ADDED_BY = 0x1; - ITEM_TIMESTAMP = 0x2; - ITEM_MESSAGE = 0x3; - ITEM_SEEN = 0x4; - ITEM_DOWNLOAD_COUNT = 0x5; - ITEM_DOWNLOAD_FORMAT = 0x6; - ITEM_SEVENDIGITAL_ID = 0x7; - ITEM_SEVENDIGITAL_LEFT = 0x8; - ITEM_SEEN_AT = 0x9; - ITEM_PUBLIC = 0xa; - } -} - -message ListAttributesPartialState { - optional ListAttributes values = 0x1; - repeated ListAttributeKind no_value = 0x2; - - enum ListAttributeKind { - LIST_UNKNOWN = 0x0; - LIST_NAME = 0x1; - LIST_DESCRIPTION = 0x2; - LIST_PICTURE = 0x3; - LIST_COLLABORATIVE = 0x4; - LIST_PL3_VERSION = 0x5; - LIST_DELETED_BY_OWNER = 0x6; - LIST_RESTRICTED_COLLABORATIVE = 0x7; - } -} - -message UpdateItemAttributes { - optional int32 index = 0x1; - optional ItemAttributesPartialState new_attributes = 0x2; - optional ItemAttributesPartialState old_attributes = 0x3; - optional ListChecksum list_checksum = 0x4; - optional ListChecksum old_attributes_checksum = 0x5; -} - -message UpdateListAttributes { - optional ListAttributesPartialState new_attributes = 0x1; - optional ListAttributesPartialState old_attributes = 0x2; - optional ListChecksum list_checksum = 0x3; - optional ListChecksum old_attributes_checksum = 0x4; -} - -message Op { - optional Kind kind = 0x1; - enum Kind { - KIND_UNKNOWN = 0x0; - ADD = 0x2; - REM = 0x3; - MOV = 0x4; - UPDATE_ITEM_ATTRIBUTES = 0x5; - UPDATE_LIST_ATTRIBUTES = 0x6; - } - optional Add add = 0x2; - optional Rem rem = 0x3; - optional Mov mov = 0x4; - optional UpdateItemAttributes update_item_attributes = 0x5; - optional UpdateListAttributes update_list_attributes = 0x6; -} - -message OpList { - repeated Op ops = 0x1; -} - diff --git a/psst-protocol/proto/pubsub.proto b/psst-protocol/proto/pubsub.proto deleted file mode 100644 index b260129b..00000000 --- a/psst-protocol/proto/pubsub.proto +++ /dev/null @@ -1,10 +0,0 @@ -syntax = "proto2"; - -package pubsub; - -message Subscription { - optional string uri = 0x1; - optional int32 expiry = 0x2; - optional int32 status_code = 0x3; -} - diff --git a/psst-protocol/proto/spirc.proto b/psst-protocol/proto/spirc.proto deleted file mode 100644 index 3bc2a47b..00000000 --- a/psst-protocol/proto/spirc.proto +++ /dev/null @@ -1,135 +0,0 @@ -syntax = "proto2"; - -package spirc; - -message Frame { - optional uint32 version = 0x1; - optional string ident = 0x2; - optional string protocol_version = 0x3; - optional uint32 seq_nr = 0x4; - optional MessageType typ = 0x5; - optional DeviceState device_state = 0x7; - optional Goodbye goodbye = 0xb; - optional State state = 0xc; - optional uint32 position = 0xd; - optional uint32 volume = 0xe; - optional int64 state_update_id = 0x11; - repeated string recipient = 0x12; - optional bytes context_player_state = 0x13; - optional string new_name = 0x14; - optional Metadata metadata = 0x19; -} - -enum MessageType { - kMessageTypeHello = 0x1; - kMessageTypeGoodbye = 0x2; - kMessageTypeProbe = 0x3; - kMessageTypeNotify = 0xa; - kMessageTypeLoad = 0x14; - kMessageTypePlay = 0x15; - kMessageTypePause = 0x16; - kMessageTypePlayPause = 0x17; - kMessageTypeSeek = 0x18; - kMessageTypePrev = 0x19; - kMessageTypeNext = 0x1a; - kMessageTypeVolume = 0x1b; - kMessageTypeShuffle = 0x1c; - kMessageTypeRepeat = 0x1d; - kMessageTypeVolumeDown = 0x1f; - kMessageTypeVolumeUp = 0x20; - kMessageTypeReplace = 0x21; - kMessageTypeLogout = 0x22; - kMessageTypeAction = 0x23; - kMessageTypeRename = 0x24; - kMessageTypeUpdateMetadata = 0x80; -} - -message DeviceState { - optional string sw_version = 0x1; - optional bool is_active = 0xa; - optional bool can_play = 0xb; - optional uint32 volume = 0xc; - optional string name = 0xd; - optional uint32 error_code = 0xe; - optional int64 became_active_at = 0xf; - optional string error_message = 0x10; - repeated Capability capabilities = 0x11; - optional string context_player_error = 0x14; - repeated Metadata metadata = 0x19; -} - -message Capability { - optional CapabilityType typ = 0x1; - repeated int64 intValue = 0x2; - repeated string stringValue = 0x3; -} - -enum CapabilityType { - kSupportedContexts = 0x1; - kCanBePlayer = 0x2; - kRestrictToLocal = 0x3; - kDeviceType = 0x4; - kGaiaEqConnectId = 0x5; - kSupportsLogout = 0x6; - kIsObservable = 0x7; - kVolumeSteps = 0x8; - kSupportedTypes = 0x9; - kCommandAcks = 0xa; - kSupportsRename = 0xb; - kHidden = 0xc; - kSupportsPlaylistV2 = 0xd; - kSupportsExternalEpisodes = 0xe; -} - -message Goodbye { - optional string reason = 0x1; -} - -message State { - optional string context_uri = 0x2; - optional uint32 index = 0x3; - optional uint32 position_ms = 0x4; - optional PlayStatus status = 0x5; - optional uint64 position_measured_at = 0x7; - optional string context_description = 0x8; - optional bool shuffle = 0xd; - optional bool repeat = 0xe; - optional string last_command_ident = 0x14; - optional uint32 last_command_msgid = 0x15; - optional bool playing_from_fallback = 0x18; - optional uint32 row = 0x19; - optional uint32 playing_track_index = 0x1a; - repeated TrackRef track = 0x1b; - optional Ad ad = 0x1c; -} - -enum PlayStatus { - kPlayStatusStop = 0x0; - kPlayStatusPlay = 0x1; - kPlayStatusPause = 0x2; - kPlayStatusLoading = 0x3; -} - -message TrackRef { - optional bytes gid = 0x1; - optional string uri = 0x2; - optional bool queued = 0x3; - optional string context = 0x4; -} - -message Ad { - optional int32 next = 0x1; - optional bytes ogg_fid = 0x2; - optional bytes image_fid = 0x3; - optional int32 duration = 0x4; - optional string click_url = 0x5; - optional string impression_url = 0x6; - optional string product = 0x7; - optional string advertiser = 0x8; - optional bytes gid = 0x9; -} - -message Metadata { - optional string type = 0x1; - optional string metadata = 0x2; -} diff --git a/psst-protocol/src/authentication.rs b/psst-protocol/src/authentication.rs deleted file mode 100644 index 37d75631..00000000 --- a/psst-protocol/src/authentication.rs +++ /dev/null @@ -1,934 +0,0 @@ -// Automatically generated rust module for 'authentication.proto' file - -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(non_camel_case_types)] -#![allow(unused_imports)] -#![allow(unknown_lints)] -#![allow(clippy::all)] -#![cfg_attr(rustfmt, rustfmt_skip)] - - -use quick_protobuf::{MessageRead, MessageWrite, BytesReader, Writer, WriterBackend, Result}; -use quick_protobuf::sizeofs::*; -use super::*; - -#[derive(Debug, PartialEq, Eq, Clone, Copy)] -pub enum AuthenticationType { - AUTHENTICATION_USER_PASS = 0, - AUTHENTICATION_STORED_SPOTIFY_CREDENTIALS = 1, - AUTHENTICATION_STORED_FACEBOOK_CREDENTIALS = 2, - AUTHENTICATION_SPOTIFY_TOKEN = 3, - AUTHENTICATION_FACEBOOK_TOKEN = 4, -} - -impl Default for AuthenticationType { - fn default() -> Self { - AuthenticationType::AUTHENTICATION_USER_PASS - } -} - -impl From for AuthenticationType { - fn from(i: i32) -> Self { - match i { - 0 => AuthenticationType::AUTHENTICATION_USER_PASS, - 1 => AuthenticationType::AUTHENTICATION_STORED_SPOTIFY_CREDENTIALS, - 2 => AuthenticationType::AUTHENTICATION_STORED_FACEBOOK_CREDENTIALS, - 3 => AuthenticationType::AUTHENTICATION_SPOTIFY_TOKEN, - 4 => AuthenticationType::AUTHENTICATION_FACEBOOK_TOKEN, - _ => Self::default(), - } - } -} - -impl<'a> From<&'a str> for AuthenticationType { - fn from(s: &'a str) -> Self { - match s { - "AUTHENTICATION_USER_PASS" => AuthenticationType::AUTHENTICATION_USER_PASS, - "AUTHENTICATION_STORED_SPOTIFY_CREDENTIALS" => AuthenticationType::AUTHENTICATION_STORED_SPOTIFY_CREDENTIALS, - "AUTHENTICATION_STORED_FACEBOOK_CREDENTIALS" => AuthenticationType::AUTHENTICATION_STORED_FACEBOOK_CREDENTIALS, - "AUTHENTICATION_SPOTIFY_TOKEN" => AuthenticationType::AUTHENTICATION_SPOTIFY_TOKEN, - "AUTHENTICATION_FACEBOOK_TOKEN" => AuthenticationType::AUTHENTICATION_FACEBOOK_TOKEN, - _ => Self::default(), - } - } -} - -#[derive(Debug, PartialEq, Eq, Clone, Copy)] -pub enum AccountCreation { - ACCOUNT_CREATION_ALWAYS_PROMPT = 1, - ACCOUNT_CREATION_ALWAYS_CREATE = 3, -} - -impl Default for AccountCreation { - fn default() -> Self { - AccountCreation::ACCOUNT_CREATION_ALWAYS_PROMPT - } -} - -impl From for AccountCreation { - fn from(i: i32) -> Self { - match i { - 1 => AccountCreation::ACCOUNT_CREATION_ALWAYS_PROMPT, - 3 => AccountCreation::ACCOUNT_CREATION_ALWAYS_CREATE, - _ => Self::default(), - } - } -} - -impl<'a> From<&'a str> for AccountCreation { - fn from(s: &'a str) -> Self { - match s { - "ACCOUNT_CREATION_ALWAYS_PROMPT" => AccountCreation::ACCOUNT_CREATION_ALWAYS_PROMPT, - "ACCOUNT_CREATION_ALWAYS_CREATE" => AccountCreation::ACCOUNT_CREATION_ALWAYS_CREATE, - _ => Self::default(), - } - } -} - -#[derive(Debug, PartialEq, Eq, Clone, Copy)] -pub enum CpuFamily { - CPU_UNKNOWN = 0, - CPU_X86 = 1, - CPU_X86_64 = 2, - CPU_PPC = 3, - CPU_PPC_64 = 4, - CPU_ARM = 5, - CPU_IA64 = 6, - CPU_SH = 7, - CPU_MIPS = 8, - CPU_BLACKFIN = 9, -} - -impl Default for CpuFamily { - fn default() -> Self { - CpuFamily::CPU_UNKNOWN - } -} - -impl From for CpuFamily { - fn from(i: i32) -> Self { - match i { - 0 => CpuFamily::CPU_UNKNOWN, - 1 => CpuFamily::CPU_X86, - 2 => CpuFamily::CPU_X86_64, - 3 => CpuFamily::CPU_PPC, - 4 => CpuFamily::CPU_PPC_64, - 5 => CpuFamily::CPU_ARM, - 6 => CpuFamily::CPU_IA64, - 7 => CpuFamily::CPU_SH, - 8 => CpuFamily::CPU_MIPS, - 9 => CpuFamily::CPU_BLACKFIN, - _ => Self::default(), - } - } -} - -impl<'a> From<&'a str> for CpuFamily { - fn from(s: &'a str) -> Self { - match s { - "CPU_UNKNOWN" => CpuFamily::CPU_UNKNOWN, - "CPU_X86" => CpuFamily::CPU_X86, - "CPU_X86_64" => CpuFamily::CPU_X86_64, - "CPU_PPC" => CpuFamily::CPU_PPC, - "CPU_PPC_64" => CpuFamily::CPU_PPC_64, - "CPU_ARM" => CpuFamily::CPU_ARM, - "CPU_IA64" => CpuFamily::CPU_IA64, - "CPU_SH" => CpuFamily::CPU_SH, - "CPU_MIPS" => CpuFamily::CPU_MIPS, - "CPU_BLACKFIN" => CpuFamily::CPU_BLACKFIN, - _ => Self::default(), - } - } -} - -#[derive(Debug, PartialEq, Eq, Clone, Copy)] -pub enum Brand { - BRAND_UNBRANDED = 0, - BRAND_INQ = 1, - BRAND_HTC = 2, - BRAND_NOKIA = 3, -} - -impl Default for Brand { - fn default() -> Self { - Brand::BRAND_UNBRANDED - } -} - -impl From for Brand { - fn from(i: i32) -> Self { - match i { - 0 => Brand::BRAND_UNBRANDED, - 1 => Brand::BRAND_INQ, - 2 => Brand::BRAND_HTC, - 3 => Brand::BRAND_NOKIA, - _ => Self::default(), - } - } -} - -impl<'a> From<&'a str> for Brand { - fn from(s: &'a str) -> Self { - match s { - "BRAND_UNBRANDED" => Brand::BRAND_UNBRANDED, - "BRAND_INQ" => Brand::BRAND_INQ, - "BRAND_HTC" => Brand::BRAND_HTC, - "BRAND_NOKIA" => Brand::BRAND_NOKIA, - _ => Self::default(), - } - } -} - -#[derive(Debug, PartialEq, Eq, Clone, Copy)] -pub enum Os { - OS_UNKNOWN = 0, - OS_WINDOWS = 1, - OS_OSX = 2, - OS_IPHONE = 3, - OS_S60 = 4, - OS_LINUX = 5, - OS_WINDOWS_CE = 6, - OS_ANDROID = 7, - OS_PALM = 8, - OS_FREEBSD = 9, - OS_BLACKBERRY = 10, - OS_SONOS = 11, - OS_LOGITECH = 12, - OS_WP7 = 13, - OS_ONKYO = 14, - OS_PHILIPS = 15, - OS_WD = 16, - OS_VOLVO = 17, - OS_TIVO = 18, - OS_AWOX = 19, - OS_MEEGO = 20, - OS_QNXNTO = 21, - OS_BCO = 22, -} - -impl Default for Os { - fn default() -> Self { - Os::OS_UNKNOWN - } -} - -impl From for Os { - fn from(i: i32) -> Self { - match i { - 0 => Os::OS_UNKNOWN, - 1 => Os::OS_WINDOWS, - 2 => Os::OS_OSX, - 3 => Os::OS_IPHONE, - 4 => Os::OS_S60, - 5 => Os::OS_LINUX, - 6 => Os::OS_WINDOWS_CE, - 7 => Os::OS_ANDROID, - 8 => Os::OS_PALM, - 9 => Os::OS_FREEBSD, - 10 => Os::OS_BLACKBERRY, - 11 => Os::OS_SONOS, - 12 => Os::OS_LOGITECH, - 13 => Os::OS_WP7, - 14 => Os::OS_ONKYO, - 15 => Os::OS_PHILIPS, - 16 => Os::OS_WD, - 17 => Os::OS_VOLVO, - 18 => Os::OS_TIVO, - 19 => Os::OS_AWOX, - 20 => Os::OS_MEEGO, - 21 => Os::OS_QNXNTO, - 22 => Os::OS_BCO, - _ => Self::default(), - } - } -} - -impl<'a> From<&'a str> for Os { - fn from(s: &'a str) -> Self { - match s { - "OS_UNKNOWN" => Os::OS_UNKNOWN, - "OS_WINDOWS" => Os::OS_WINDOWS, - "OS_OSX" => Os::OS_OSX, - "OS_IPHONE" => Os::OS_IPHONE, - "OS_S60" => Os::OS_S60, - "OS_LINUX" => Os::OS_LINUX, - "OS_WINDOWS_CE" => Os::OS_WINDOWS_CE, - "OS_ANDROID" => Os::OS_ANDROID, - "OS_PALM" => Os::OS_PALM, - "OS_FREEBSD" => Os::OS_FREEBSD, - "OS_BLACKBERRY" => Os::OS_BLACKBERRY, - "OS_SONOS" => Os::OS_SONOS, - "OS_LOGITECH" => Os::OS_LOGITECH, - "OS_WP7" => Os::OS_WP7, - "OS_ONKYO" => Os::OS_ONKYO, - "OS_PHILIPS" => Os::OS_PHILIPS, - "OS_WD" => Os::OS_WD, - "OS_VOLVO" => Os::OS_VOLVO, - "OS_TIVO" => Os::OS_TIVO, - "OS_AWOX" => Os::OS_AWOX, - "OS_MEEGO" => Os::OS_MEEGO, - "OS_QNXNTO" => Os::OS_QNXNTO, - "OS_BCO" => Os::OS_BCO, - _ => Self::default(), - } - } -} - -#[derive(Debug, PartialEq, Eq, Clone, Copy)] -pub enum AccountType { - Spotify = 0, - Facebook = 1, -} - -impl Default for AccountType { - fn default() -> Self { - AccountType::Spotify - } -} - -impl From for AccountType { - fn from(i: i32) -> Self { - match i { - 0 => AccountType::Spotify, - 1 => AccountType::Facebook, - _ => Self::default(), - } - } -} - -impl<'a> From<&'a str> for AccountType { - fn from(s: &'a str) -> Self { - match s { - "Spotify" => AccountType::Spotify, - "Facebook" => AccountType::Facebook, - _ => Self::default(), - } - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct ClientResponseEncrypted { - pub login_credentials: authentication::LoginCredentials, - pub account_creation: Option, - pub fingerprint_response: Option, - pub peer_ticket: Option, - pub system_info: authentication::SystemInfo, - pub platform_model: Option, - pub version_string: Option, - pub appkey: Option, - pub client_info: Option, -} - -impl<'a> MessageRead<'a> for ClientResponseEncrypted { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(82) => msg.login_credentials = r.read_message::(bytes)?, - Ok(160) => msg.account_creation = Some(r.read_enum(bytes)?), - Ok(242) => msg.fingerprint_response = Some(r.read_message::(bytes)?), - Ok(322) => msg.peer_ticket = Some(r.read_message::(bytes)?), - Ok(402) => msg.system_info = r.read_message::(bytes)?, - Ok(482) => msg.platform_model = Some(r.read_string(bytes)?.to_owned()), - Ok(562) => msg.version_string = Some(r.read_string(bytes)?.to_owned()), - Ok(642) => msg.appkey = Some(r.read_message::(bytes)?), - Ok(722) => msg.client_info = Some(r.read_message::(bytes)?), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for ClientResponseEncrypted { - fn get_size(&self) -> usize { - 0 - + 1 + sizeof_len((&self.login_credentials).get_size()) - + self.account_creation.as_ref().map_or(0, |m| 2 + sizeof_varint(*(m) as u64)) - + self.fingerprint_response.as_ref().map_or(0, |m| 2 + sizeof_len((m).get_size())) - + self.peer_ticket.as_ref().map_or(0, |m| 2 + sizeof_len((m).get_size())) - + 2 + sizeof_len((&self.system_info).get_size()) - + self.platform_model.as_ref().map_or(0, |m| 2 + sizeof_len((m).len())) - + self.version_string.as_ref().map_or(0, |m| 2 + sizeof_len((m).len())) - + self.appkey.as_ref().map_or(0, |m| 2 + sizeof_len((m).get_size())) - + self.client_info.as_ref().map_or(0, |m| 2 + sizeof_len((m).get_size())) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - w.write_with_tag(82, |w| w.write_message(&self.login_credentials))?; - if let Some(ref s) = self.account_creation { w.write_with_tag(160, |w| w.write_enum(*s as i32))?; } - if let Some(ref s) = self.fingerprint_response { w.write_with_tag(242, |w| w.write_message(s))?; } - if let Some(ref s) = self.peer_ticket { w.write_with_tag(322, |w| w.write_message(s))?; } - w.write_with_tag(402, |w| w.write_message(&self.system_info))?; - if let Some(ref s) = self.platform_model { w.write_with_tag(482, |w| w.write_string(&**s))?; } - if let Some(ref s) = self.version_string { w.write_with_tag(562, |w| w.write_string(&**s))?; } - if let Some(ref s) = self.appkey { w.write_with_tag(642, |w| w.write_message(s))?; } - if let Some(ref s) = self.client_info { w.write_with_tag(722, |w| w.write_message(s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct LoginCredentials { - pub username: Option, - pub typ: authentication::AuthenticationType, - pub auth_data: Option>, -} - -impl<'a> MessageRead<'a> for LoginCredentials { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(82) => msg.username = Some(r.read_string(bytes)?.to_owned()), - Ok(160) => msg.typ = r.read_enum(bytes)?, - Ok(242) => msg.auth_data = Some(r.read_bytes(bytes)?.to_owned()), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for LoginCredentials { - fn get_size(&self) -> usize { - 0 - + self.username.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - + 2 + sizeof_varint(*(&self.typ) as u64) - + self.auth_data.as_ref().map_or(0, |m| 2 + sizeof_len((m).len())) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.username { w.write_with_tag(82, |w| w.write_string(&**s))?; } - w.write_with_tag(160, |w| w.write_enum(*&self.typ as i32))?; - if let Some(ref s) = self.auth_data { w.write_with_tag(242, |w| w.write_bytes(&**s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct FingerprintResponseUnion { - pub grain: Option, - pub hmac_ripemd: Option, -} - -impl<'a> MessageRead<'a> for FingerprintResponseUnion { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(82) => msg.grain = Some(r.read_message::(bytes)?), - Ok(162) => msg.hmac_ripemd = Some(r.read_message::(bytes)?), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for FingerprintResponseUnion { - fn get_size(&self) -> usize { - 0 - + self.grain.as_ref().map_or(0, |m| 1 + sizeof_len((m).get_size())) - + self.hmac_ripemd.as_ref().map_or(0, |m| 2 + sizeof_len((m).get_size())) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.grain { w.write_with_tag(82, |w| w.write_message(s))?; } - if let Some(ref s) = self.hmac_ripemd { w.write_with_tag(162, |w| w.write_message(s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct FingerprintGrainResponse { - pub encrypted_key: Vec, -} - -impl<'a> MessageRead<'a> for FingerprintGrainResponse { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(82) => msg.encrypted_key = r.read_bytes(bytes)?.to_owned(), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for FingerprintGrainResponse { - fn get_size(&self) -> usize { - 0 - + 1 + sizeof_len((&self.encrypted_key).len()) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - w.write_with_tag(82, |w| w.write_bytes(&**&self.encrypted_key))?; - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct FingerprintHmacRipemdResponse { - pub hmac: Vec, -} - -impl<'a> MessageRead<'a> for FingerprintHmacRipemdResponse { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(82) => msg.hmac = r.read_bytes(bytes)?.to_owned(), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for FingerprintHmacRipemdResponse { - fn get_size(&self) -> usize { - 0 - + 1 + sizeof_len((&self.hmac).len()) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - w.write_with_tag(82, |w| w.write_bytes(&**&self.hmac))?; - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct PeerTicketUnion { - pub public_key: Option, - pub old_ticket: Option, -} - -impl<'a> MessageRead<'a> for PeerTicketUnion { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(82) => msg.public_key = Some(r.read_message::(bytes)?), - Ok(162) => msg.old_ticket = Some(r.read_message::(bytes)?), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for PeerTicketUnion { - fn get_size(&self) -> usize { - 0 - + self.public_key.as_ref().map_or(0, |m| 1 + sizeof_len((m).get_size())) - + self.old_ticket.as_ref().map_or(0, |m| 2 + sizeof_len((m).get_size())) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.public_key { w.write_with_tag(82, |w| w.write_message(s))?; } - if let Some(ref s) = self.old_ticket { w.write_with_tag(162, |w| w.write_message(s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct PeerTicketPublicKey { - pub public_key: Vec, -} - -impl<'a> MessageRead<'a> for PeerTicketPublicKey { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(82) => msg.public_key = r.read_bytes(bytes)?.to_owned(), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for PeerTicketPublicKey { - fn get_size(&self) -> usize { - 0 - + 1 + sizeof_len((&self.public_key).len()) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - w.write_with_tag(82, |w| w.write_bytes(&**&self.public_key))?; - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct PeerTicketOld { - pub peer_ticket: Vec, - pub peer_ticket_signature: Vec, -} - -impl<'a> MessageRead<'a> for PeerTicketOld { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(82) => msg.peer_ticket = r.read_bytes(bytes)?.to_owned(), - Ok(162) => msg.peer_ticket_signature = r.read_bytes(bytes)?.to_owned(), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for PeerTicketOld { - fn get_size(&self) -> usize { - 0 - + 1 + sizeof_len((&self.peer_ticket).len()) - + 2 + sizeof_len((&self.peer_ticket_signature).len()) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - w.write_with_tag(82, |w| w.write_bytes(&**&self.peer_ticket))?; - w.write_with_tag(162, |w| w.write_bytes(&**&self.peer_ticket_signature))?; - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct SystemInfo { - pub cpu_family: authentication::CpuFamily, - pub cpu_subtype: Option, - pub cpu_ext: Option, - pub brand: Option, - pub brand_flags: Option, - pub os: authentication::Os, - pub os_version: Option, - pub os_ext: Option, - pub system_information_string: Option, - pub device_id: Option, -} - -impl<'a> MessageRead<'a> for SystemInfo { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(80) => msg.cpu_family = r.read_enum(bytes)?, - Ok(160) => msg.cpu_subtype = Some(r.read_uint32(bytes)?), - Ok(240) => msg.cpu_ext = Some(r.read_uint32(bytes)?), - Ok(320) => msg.brand = Some(r.read_enum(bytes)?), - Ok(400) => msg.brand_flags = Some(r.read_uint32(bytes)?), - Ok(480) => msg.os = r.read_enum(bytes)?, - Ok(560) => msg.os_version = Some(r.read_uint32(bytes)?), - Ok(640) => msg.os_ext = Some(r.read_uint32(bytes)?), - Ok(722) => msg.system_information_string = Some(r.read_string(bytes)?.to_owned()), - Ok(802) => msg.device_id = Some(r.read_string(bytes)?.to_owned()), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for SystemInfo { - fn get_size(&self) -> usize { - 0 - + 1 + sizeof_varint(*(&self.cpu_family) as u64) - + self.cpu_subtype.as_ref().map_or(0, |m| 2 + sizeof_varint(*(m) as u64)) - + self.cpu_ext.as_ref().map_or(0, |m| 2 + sizeof_varint(*(m) as u64)) - + self.brand.as_ref().map_or(0, |m| 2 + sizeof_varint(*(m) as u64)) - + self.brand_flags.as_ref().map_or(0, |m| 2 + sizeof_varint(*(m) as u64)) - + 2 + sizeof_varint(*(&self.os) as u64) - + self.os_version.as_ref().map_or(0, |m| 2 + sizeof_varint(*(m) as u64)) - + self.os_ext.as_ref().map_or(0, |m| 2 + sizeof_varint(*(m) as u64)) - + self.system_information_string.as_ref().map_or(0, |m| 2 + sizeof_len((m).len())) - + self.device_id.as_ref().map_or(0, |m| 2 + sizeof_len((m).len())) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - w.write_with_tag(80, |w| w.write_enum(*&self.cpu_family as i32))?; - if let Some(ref s) = self.cpu_subtype { w.write_with_tag(160, |w| w.write_uint32(*s))?; } - if let Some(ref s) = self.cpu_ext { w.write_with_tag(240, |w| w.write_uint32(*s))?; } - if let Some(ref s) = self.brand { w.write_with_tag(320, |w| w.write_enum(*s as i32))?; } - if let Some(ref s) = self.brand_flags { w.write_with_tag(400, |w| w.write_uint32(*s))?; } - w.write_with_tag(480, |w| w.write_enum(*&self.os as i32))?; - if let Some(ref s) = self.os_version { w.write_with_tag(560, |w| w.write_uint32(*s))?; } - if let Some(ref s) = self.os_ext { w.write_with_tag(640, |w| w.write_uint32(*s))?; } - if let Some(ref s) = self.system_information_string { w.write_with_tag(722, |w| w.write_string(&**s))?; } - if let Some(ref s) = self.device_id { w.write_with_tag(802, |w| w.write_string(&**s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct LibspotifyAppKey { - pub version: u32, - pub devkey: Vec, - pub signature: Vec, - pub useragent: String, - pub callback_hash: Vec, -} - -impl<'a> MessageRead<'a> for LibspotifyAppKey { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(8) => msg.version = r.read_uint32(bytes)?, - Ok(18) => msg.devkey = r.read_bytes(bytes)?.to_owned(), - Ok(26) => msg.signature = r.read_bytes(bytes)?.to_owned(), - Ok(34) => msg.useragent = r.read_string(bytes)?.to_owned(), - Ok(42) => msg.callback_hash = r.read_bytes(bytes)?.to_owned(), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for LibspotifyAppKey { - fn get_size(&self) -> usize { - 0 - + 1 + sizeof_varint(*(&self.version) as u64) - + 1 + sizeof_len((&self.devkey).len()) - + 1 + sizeof_len((&self.signature).len()) - + 1 + sizeof_len((&self.useragent).len()) - + 1 + sizeof_len((&self.callback_hash).len()) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - w.write_with_tag(8, |w| w.write_uint32(*&self.version))?; - w.write_with_tag(18, |w| w.write_bytes(&**&self.devkey))?; - w.write_with_tag(26, |w| w.write_bytes(&**&self.signature))?; - w.write_with_tag(34, |w| w.write_string(&**&self.useragent))?; - w.write_with_tag(42, |w| w.write_bytes(&**&self.callback_hash))?; - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct ClientInfo { - pub limited: Option, - pub fb: Option, - pub language: Option, -} - -impl<'a> MessageRead<'a> for ClientInfo { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(8) => msg.limited = Some(r.read_bool(bytes)?), - Ok(18) => msg.fb = Some(r.read_message::(bytes)?), - Ok(26) => msg.language = Some(r.read_string(bytes)?.to_owned()), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for ClientInfo { - fn get_size(&self) -> usize { - 0 - + self.limited.as_ref().map_or(0, |m| 1 + sizeof_varint(*(m) as u64)) - + self.fb.as_ref().map_or(0, |m| 1 + sizeof_len((m).get_size())) - + self.language.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.limited { w.write_with_tag(8, |w| w.write_bool(*s))?; } - if let Some(ref s) = self.fb { w.write_with_tag(18, |w| w.write_message(s))?; } - if let Some(ref s) = self.language { w.write_with_tag(26, |w| w.write_string(&**s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct ClientInfoFacebook { - pub machine_id: Option, -} - -impl<'a> MessageRead<'a> for ClientInfoFacebook { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(10) => msg.machine_id = Some(r.read_string(bytes)?.to_owned()), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for ClientInfoFacebook { - fn get_size(&self) -> usize { - 0 - + self.machine_id.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.machine_id { w.write_with_tag(10, |w| w.write_string(&**s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct APWelcome { - pub canonical_username: String, - pub account_type_logged_in: authentication::AccountType, - pub credentials_type_logged_in: authentication::AccountType, - pub reusable_auth_credentials_type: authentication::AuthenticationType, - pub reusable_auth_credentials: Vec, - pub lfs_secret: Option>, - pub account_info: Option, - pub fb: Option, -} - -impl<'a> MessageRead<'a> for APWelcome { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(82) => msg.canonical_username = r.read_string(bytes)?.to_owned(), - Ok(160) => msg.account_type_logged_in = r.read_enum(bytes)?, - Ok(200) => msg.credentials_type_logged_in = r.read_enum(bytes)?, - Ok(240) => msg.reusable_auth_credentials_type = r.read_enum(bytes)?, - Ok(322) => msg.reusable_auth_credentials = r.read_bytes(bytes)?.to_owned(), - Ok(402) => msg.lfs_secret = Some(r.read_bytes(bytes)?.to_owned()), - Ok(482) => msg.account_info = Some(r.read_message::(bytes)?), - Ok(562) => msg.fb = Some(r.read_message::(bytes)?), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for APWelcome { - fn get_size(&self) -> usize { - 0 - + 1 + sizeof_len((&self.canonical_username).len()) - + 2 + sizeof_varint(*(&self.account_type_logged_in) as u64) - + 2 + sizeof_varint(*(&self.credentials_type_logged_in) as u64) - + 2 + sizeof_varint(*(&self.reusable_auth_credentials_type) as u64) - + 2 + sizeof_len((&self.reusable_auth_credentials).len()) - + self.lfs_secret.as_ref().map_or(0, |m| 2 + sizeof_len((m).len())) - + self.account_info.as_ref().map_or(0, |m| 2 + sizeof_len((m).get_size())) - + self.fb.as_ref().map_or(0, |m| 2 + sizeof_len((m).get_size())) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - w.write_with_tag(82, |w| w.write_string(&**&self.canonical_username))?; - w.write_with_tag(160, |w| w.write_enum(*&self.account_type_logged_in as i32))?; - w.write_with_tag(200, |w| w.write_enum(*&self.credentials_type_logged_in as i32))?; - w.write_with_tag(240, |w| w.write_enum(*&self.reusable_auth_credentials_type as i32))?; - w.write_with_tag(322, |w| w.write_bytes(&**&self.reusable_auth_credentials))?; - if let Some(ref s) = self.lfs_secret { w.write_with_tag(402, |w| w.write_bytes(&**s))?; } - if let Some(ref s) = self.account_info { w.write_with_tag(482, |w| w.write_message(s))?; } - if let Some(ref s) = self.fb { w.write_with_tag(562, |w| w.write_message(s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct AccountInfo { - pub spotify: Option, - pub facebook: Option, -} - -impl<'a> MessageRead<'a> for AccountInfo { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(10) => msg.spotify = Some(r.read_message::(bytes)?), - Ok(18) => msg.facebook = Some(r.read_message::(bytes)?), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for AccountInfo { - fn get_size(&self) -> usize { - 0 - + self.spotify.as_ref().map_or(0, |m| 1 + sizeof_len((m).get_size())) - + self.facebook.as_ref().map_or(0, |m| 1 + sizeof_len((m).get_size())) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.spotify { w.write_with_tag(10, |w| w.write_message(s))?; } - if let Some(ref s) = self.facebook { w.write_with_tag(18, |w| w.write_message(s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct AccountInfoSpotify { } - -impl<'a> MessageRead<'a> for AccountInfoSpotify { - fn from_reader(r: &mut BytesReader, _: &[u8]) -> Result { - r.read_to_end(); - Ok(Self::default()) - } -} - -impl MessageWrite for AccountInfoSpotify { } - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct AccountInfoFacebook { - pub access_token: Option, - pub machine_id: Option, -} - -impl<'a> MessageRead<'a> for AccountInfoFacebook { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(10) => msg.access_token = Some(r.read_string(bytes)?.to_owned()), - Ok(18) => msg.machine_id = Some(r.read_string(bytes)?.to_owned()), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for AccountInfoFacebook { - fn get_size(&self) -> usize { - 0 - + self.access_token.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - + self.machine_id.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.access_token { w.write_with_tag(10, |w| w.write_string(&**s))?; } - if let Some(ref s) = self.machine_id { w.write_with_tag(18, |w| w.write_string(&**s))?; } - Ok(()) - } -} - diff --git a/psst-protocol/src/keyexchange.rs b/psst-protocol/src/keyexchange.rs deleted file mode 100644 index 595c5e48..00000000 --- a/psst-protocol/src/keyexchange.rs +++ /dev/null @@ -1,1269 +0,0 @@ -// Automatically generated rust module for 'keyexchange.proto' file - -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(non_camel_case_types)] -#![allow(unused_imports)] -#![allow(unknown_lints)] -#![allow(clippy::all)] -#![cfg_attr(rustfmt, rustfmt_skip)] - - -use quick_protobuf::{MessageRead, MessageWrite, BytesReader, Writer, WriterBackend, Result}; -use quick_protobuf::sizeofs::*; -use super::*; - -#[derive(Debug, PartialEq, Eq, Clone, Copy)] -pub enum Product { - PRODUCT_CLIENT = 0, - PRODUCT_LIBSPOTIFY = 1, - PRODUCT_MOBILE = 2, - PRODUCT_PARTNER = 3, - PRODUCT_LIBSPOTIFY_EMBEDDED = 5, -} - -impl Default for Product { - fn default() -> Self { - Product::PRODUCT_CLIENT - } -} - -impl From for Product { - fn from(i: i32) -> Self { - match i { - 0 => Product::PRODUCT_CLIENT, - 1 => Product::PRODUCT_LIBSPOTIFY, - 2 => Product::PRODUCT_MOBILE, - 3 => Product::PRODUCT_PARTNER, - 5 => Product::PRODUCT_LIBSPOTIFY_EMBEDDED, - _ => Self::default(), - } - } -} - -impl<'a> From<&'a str> for Product { - fn from(s: &'a str) -> Self { - match s { - "PRODUCT_CLIENT" => Product::PRODUCT_CLIENT, - "PRODUCT_LIBSPOTIFY" => Product::PRODUCT_LIBSPOTIFY, - "PRODUCT_MOBILE" => Product::PRODUCT_MOBILE, - "PRODUCT_PARTNER" => Product::PRODUCT_PARTNER, - "PRODUCT_LIBSPOTIFY_EMBEDDED" => Product::PRODUCT_LIBSPOTIFY_EMBEDDED, - _ => Self::default(), - } - } -} - -#[derive(Debug, PartialEq, Eq, Clone, Copy)] -pub enum ProductFlags { - PRODUCT_FLAG_NONE = 0, - PRODUCT_FLAG_DEV_BUILD = 1, -} - -impl Default for ProductFlags { - fn default() -> Self { - ProductFlags::PRODUCT_FLAG_NONE - } -} - -impl From for ProductFlags { - fn from(i: i32) -> Self { - match i { - 0 => ProductFlags::PRODUCT_FLAG_NONE, - 1 => ProductFlags::PRODUCT_FLAG_DEV_BUILD, - _ => Self::default(), - } - } -} - -impl<'a> From<&'a str> for ProductFlags { - fn from(s: &'a str) -> Self { - match s { - "PRODUCT_FLAG_NONE" => ProductFlags::PRODUCT_FLAG_NONE, - "PRODUCT_FLAG_DEV_BUILD" => ProductFlags::PRODUCT_FLAG_DEV_BUILD, - _ => Self::default(), - } - } -} - -#[derive(Debug, PartialEq, Eq, Clone, Copy)] -pub enum Platform { - PLATFORM_WIN32_X86 = 0, - PLATFORM_OSX_X86 = 1, - PLATFORM_LINUX_X86 = 2, - PLATFORM_IPHONE_ARM = 3, - PLATFORM_S60_ARM = 4, - PLATFORM_OSX_PPC = 5, - PLATFORM_ANDROID_ARM = 6, - PLATFORM_WINDOWS_CE_ARM = 7, - PLATFORM_LINUX_X86_64 = 8, - PLATFORM_OSX_X86_64 = 9, - PLATFORM_PALM_ARM = 10, - PLATFORM_LINUX_SH = 11, - PLATFORM_FREEBSD_X86 = 12, - PLATFORM_FREEBSD_X86_64 = 13, - PLATFORM_BLACKBERRY_ARM = 14, - PLATFORM_SONOS = 15, - PLATFORM_LINUX_MIPS = 16, - PLATFORM_LINUX_ARM = 17, - PLATFORM_LOGITECH_ARM = 18, - PLATFORM_LINUX_BLACKFIN = 19, - PLATFORM_WP7_ARM = 20, - PLATFORM_ONKYO_ARM = 21, - PLATFORM_QNXNTO_ARM = 22, - PLATFORM_BCO_ARM = 23, -} - -impl Default for Platform { - fn default() -> Self { - Platform::PLATFORM_WIN32_X86 - } -} - -impl From for Platform { - fn from(i: i32) -> Self { - match i { - 0 => Platform::PLATFORM_WIN32_X86, - 1 => Platform::PLATFORM_OSX_X86, - 2 => Platform::PLATFORM_LINUX_X86, - 3 => Platform::PLATFORM_IPHONE_ARM, - 4 => Platform::PLATFORM_S60_ARM, - 5 => Platform::PLATFORM_OSX_PPC, - 6 => Platform::PLATFORM_ANDROID_ARM, - 7 => Platform::PLATFORM_WINDOWS_CE_ARM, - 8 => Platform::PLATFORM_LINUX_X86_64, - 9 => Platform::PLATFORM_OSX_X86_64, - 10 => Platform::PLATFORM_PALM_ARM, - 11 => Platform::PLATFORM_LINUX_SH, - 12 => Platform::PLATFORM_FREEBSD_X86, - 13 => Platform::PLATFORM_FREEBSD_X86_64, - 14 => Platform::PLATFORM_BLACKBERRY_ARM, - 15 => Platform::PLATFORM_SONOS, - 16 => Platform::PLATFORM_LINUX_MIPS, - 17 => Platform::PLATFORM_LINUX_ARM, - 18 => Platform::PLATFORM_LOGITECH_ARM, - 19 => Platform::PLATFORM_LINUX_BLACKFIN, - 20 => Platform::PLATFORM_WP7_ARM, - 21 => Platform::PLATFORM_ONKYO_ARM, - 22 => Platform::PLATFORM_QNXNTO_ARM, - 23 => Platform::PLATFORM_BCO_ARM, - _ => Self::default(), - } - } -} - -impl<'a> From<&'a str> for Platform { - fn from(s: &'a str) -> Self { - match s { - "PLATFORM_WIN32_X86" => Platform::PLATFORM_WIN32_X86, - "PLATFORM_OSX_X86" => Platform::PLATFORM_OSX_X86, - "PLATFORM_LINUX_X86" => Platform::PLATFORM_LINUX_X86, - "PLATFORM_IPHONE_ARM" => Platform::PLATFORM_IPHONE_ARM, - "PLATFORM_S60_ARM" => Platform::PLATFORM_S60_ARM, - "PLATFORM_OSX_PPC" => Platform::PLATFORM_OSX_PPC, - "PLATFORM_ANDROID_ARM" => Platform::PLATFORM_ANDROID_ARM, - "PLATFORM_WINDOWS_CE_ARM" => Platform::PLATFORM_WINDOWS_CE_ARM, - "PLATFORM_LINUX_X86_64" => Platform::PLATFORM_LINUX_X86_64, - "PLATFORM_OSX_X86_64" => Platform::PLATFORM_OSX_X86_64, - "PLATFORM_PALM_ARM" => Platform::PLATFORM_PALM_ARM, - "PLATFORM_LINUX_SH" => Platform::PLATFORM_LINUX_SH, - "PLATFORM_FREEBSD_X86" => Platform::PLATFORM_FREEBSD_X86, - "PLATFORM_FREEBSD_X86_64" => Platform::PLATFORM_FREEBSD_X86_64, - "PLATFORM_BLACKBERRY_ARM" => Platform::PLATFORM_BLACKBERRY_ARM, - "PLATFORM_SONOS" => Platform::PLATFORM_SONOS, - "PLATFORM_LINUX_MIPS" => Platform::PLATFORM_LINUX_MIPS, - "PLATFORM_LINUX_ARM" => Platform::PLATFORM_LINUX_ARM, - "PLATFORM_LOGITECH_ARM" => Platform::PLATFORM_LOGITECH_ARM, - "PLATFORM_LINUX_BLACKFIN" => Platform::PLATFORM_LINUX_BLACKFIN, - "PLATFORM_WP7_ARM" => Platform::PLATFORM_WP7_ARM, - "PLATFORM_ONKYO_ARM" => Platform::PLATFORM_ONKYO_ARM, - "PLATFORM_QNXNTO_ARM" => Platform::PLATFORM_QNXNTO_ARM, - "PLATFORM_BCO_ARM" => Platform::PLATFORM_BCO_ARM, - _ => Self::default(), - } - } -} - -#[derive(Debug, PartialEq, Eq, Clone, Copy)] -pub enum Fingerprint { - FINGERPRINT_GRAIN = 0, - FINGERPRINT_HMAC_RIPEMD = 1, -} - -impl Default for Fingerprint { - fn default() -> Self { - Fingerprint::FINGERPRINT_GRAIN - } -} - -impl From for Fingerprint { - fn from(i: i32) -> Self { - match i { - 0 => Fingerprint::FINGERPRINT_GRAIN, - 1 => Fingerprint::FINGERPRINT_HMAC_RIPEMD, - _ => Self::default(), - } - } -} - -impl<'a> From<&'a str> for Fingerprint { - fn from(s: &'a str) -> Self { - match s { - "FINGERPRINT_GRAIN" => Fingerprint::FINGERPRINT_GRAIN, - "FINGERPRINT_HMAC_RIPEMD" => Fingerprint::FINGERPRINT_HMAC_RIPEMD, - _ => Self::default(), - } - } -} - -#[derive(Debug, PartialEq, Eq, Clone, Copy)] -pub enum Cryptosuite { - CRYPTO_SUITE_SHANNON = 0, - CRYPTO_SUITE_RC4_SHA1_HMAC = 1, -} - -impl Default for Cryptosuite { - fn default() -> Self { - Cryptosuite::CRYPTO_SUITE_SHANNON - } -} - -impl From for Cryptosuite { - fn from(i: i32) -> Self { - match i { - 0 => Cryptosuite::CRYPTO_SUITE_SHANNON, - 1 => Cryptosuite::CRYPTO_SUITE_RC4_SHA1_HMAC, - _ => Self::default(), - } - } -} - -impl<'a> From<&'a str> for Cryptosuite { - fn from(s: &'a str) -> Self { - match s { - "CRYPTO_SUITE_SHANNON" => Cryptosuite::CRYPTO_SUITE_SHANNON, - "CRYPTO_SUITE_RC4_SHA1_HMAC" => Cryptosuite::CRYPTO_SUITE_RC4_SHA1_HMAC, - _ => Self::default(), - } - } -} - -#[derive(Debug, PartialEq, Eq, Clone, Copy)] -pub enum Powscheme { - POW_HASH_CASH = 0, -} - -impl Default for Powscheme { - fn default() -> Self { - Powscheme::POW_HASH_CASH - } -} - -impl From for Powscheme { - fn from(i: i32) -> Self { - match i { - 0 => Powscheme::POW_HASH_CASH, - _ => Self::default(), - } - } -} - -impl<'a> From<&'a str> for Powscheme { - fn from(s: &'a str) -> Self { - match s { - "POW_HASH_CASH" => Powscheme::POW_HASH_CASH, - _ => Self::default(), - } - } -} - -#[derive(Debug, PartialEq, Eq, Clone, Copy)] -pub enum ErrorCode { - ProtocolError = 0, - TryAnotherAP = 2, - BadConnectionId = 5, - TravelRestriction = 9, - PremiumAccountRequired = 11, - BadCredentials = 12, - CouldNotValidateCredentials = 13, - AccountExists = 14, - ExtraVerificationRequired = 15, - InvalidAppKey = 16, - ApplicationBanned = 17, -} - -impl Default for ErrorCode { - fn default() -> Self { - ErrorCode::ProtocolError - } -} - -impl From for ErrorCode { - fn from(i: i32) -> Self { - match i { - 0 => ErrorCode::ProtocolError, - 2 => ErrorCode::TryAnotherAP, - 5 => ErrorCode::BadConnectionId, - 9 => ErrorCode::TravelRestriction, - 11 => ErrorCode::PremiumAccountRequired, - 12 => ErrorCode::BadCredentials, - 13 => ErrorCode::CouldNotValidateCredentials, - 14 => ErrorCode::AccountExists, - 15 => ErrorCode::ExtraVerificationRequired, - 16 => ErrorCode::InvalidAppKey, - 17 => ErrorCode::ApplicationBanned, - _ => Self::default(), - } - } -} - -impl<'a> From<&'a str> for ErrorCode { - fn from(s: &'a str) -> Self { - match s { - "ProtocolError" => ErrorCode::ProtocolError, - "TryAnotherAP" => ErrorCode::TryAnotherAP, - "BadConnectionId" => ErrorCode::BadConnectionId, - "TravelRestriction" => ErrorCode::TravelRestriction, - "PremiumAccountRequired" => ErrorCode::PremiumAccountRequired, - "BadCredentials" => ErrorCode::BadCredentials, - "CouldNotValidateCredentials" => ErrorCode::CouldNotValidateCredentials, - "AccountExists" => ErrorCode::AccountExists, - "ExtraVerificationRequired" => ErrorCode::ExtraVerificationRequired, - "InvalidAppKey" => ErrorCode::InvalidAppKey, - "ApplicationBanned" => ErrorCode::ApplicationBanned, - _ => Self::default(), - } - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct ClientHello { - pub build_info: keyexchange::BuildInfo, - pub fingerprints_supported: Vec, - pub cryptosuites_supported: Vec, - pub powschemes_supported: Vec, - pub login_crypto_hello: keyexchange::LoginCryptoHelloUnion, - pub client_nonce: Vec, - pub padding: Option>, - pub feature_set: Option, -} - -impl<'a> MessageRead<'a> for ClientHello { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(82) => msg.build_info = r.read_message::(bytes)?, - Ok(160) => msg.fingerprints_supported.push(r.read_enum(bytes)?), - Ok(240) => msg.cryptosuites_supported.push(r.read_enum(bytes)?), - Ok(320) => msg.powschemes_supported.push(r.read_enum(bytes)?), - Ok(402) => msg.login_crypto_hello = r.read_message::(bytes)?, - Ok(482) => msg.client_nonce = r.read_bytes(bytes)?.to_owned(), - Ok(562) => msg.padding = Some(r.read_bytes(bytes)?.to_owned()), - Ok(642) => msg.feature_set = Some(r.read_message::(bytes)?), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for ClientHello { - fn get_size(&self) -> usize { - 0 - + 1 + sizeof_len((&self.build_info).get_size()) - + self.fingerprints_supported.iter().map(|s| 2 + sizeof_varint(*(s) as u64)).sum::() - + self.cryptosuites_supported.iter().map(|s| 2 + sizeof_varint(*(s) as u64)).sum::() - + self.powschemes_supported.iter().map(|s| 2 + sizeof_varint(*(s) as u64)).sum::() - + 2 + sizeof_len((&self.login_crypto_hello).get_size()) - + 2 + sizeof_len((&self.client_nonce).len()) - + self.padding.as_ref().map_or(0, |m| 2 + sizeof_len((m).len())) - + self.feature_set.as_ref().map_or(0, |m| 2 + sizeof_len((m).get_size())) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - w.write_with_tag(82, |w| w.write_message(&self.build_info))?; - for s in &self.fingerprints_supported { w.write_with_tag(160, |w| w.write_enum(*s as i32))?; } - for s in &self.cryptosuites_supported { w.write_with_tag(240, |w| w.write_enum(*s as i32))?; } - for s in &self.powschemes_supported { w.write_with_tag(320, |w| w.write_enum(*s as i32))?; } - w.write_with_tag(402, |w| w.write_message(&self.login_crypto_hello))?; - w.write_with_tag(482, |w| w.write_bytes(&**&self.client_nonce))?; - if let Some(ref s) = self.padding { w.write_with_tag(562, |w| w.write_bytes(&**s))?; } - if let Some(ref s) = self.feature_set { w.write_with_tag(642, |w| w.write_message(s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct BuildInfo { - pub product: keyexchange::Product, - pub product_flags: Vec, - pub platform: keyexchange::Platform, - pub version: u64, -} - -impl<'a> MessageRead<'a> for BuildInfo { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(80) => msg.product = r.read_enum(bytes)?, - Ok(160) => msg.product_flags.push(r.read_enum(bytes)?), - Ok(240) => msg.platform = r.read_enum(bytes)?, - Ok(320) => msg.version = r.read_uint64(bytes)?, - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for BuildInfo { - fn get_size(&self) -> usize { - 0 - + 1 + sizeof_varint(*(&self.product) as u64) - + self.product_flags.iter().map(|s| 2 + sizeof_varint(*(s) as u64)).sum::() - + 2 + sizeof_varint(*(&self.platform) as u64) - + 2 + sizeof_varint(*(&self.version) as u64) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - w.write_with_tag(80, |w| w.write_enum(*&self.product as i32))?; - for s in &self.product_flags { w.write_with_tag(160, |w| w.write_enum(*s as i32))?; } - w.write_with_tag(240, |w| w.write_enum(*&self.platform as i32))?; - w.write_with_tag(320, |w| w.write_uint64(*&self.version))?; - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct LoginCryptoHelloUnion { - pub diffie_hellman: Option, -} - -impl<'a> MessageRead<'a> for LoginCryptoHelloUnion { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(82) => msg.diffie_hellman = Some(r.read_message::(bytes)?), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for LoginCryptoHelloUnion { - fn get_size(&self) -> usize { - 0 - + self.diffie_hellman.as_ref().map_or(0, |m| 1 + sizeof_len((m).get_size())) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.diffie_hellman { w.write_with_tag(82, |w| w.write_message(s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct LoginCryptoDiffieHellmanHello { - pub gc: Vec, - pub server_keys_known: u32, -} - -impl<'a> MessageRead<'a> for LoginCryptoDiffieHellmanHello { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(82) => msg.gc = r.read_bytes(bytes)?.to_owned(), - Ok(160) => msg.server_keys_known = r.read_uint32(bytes)?, - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for LoginCryptoDiffieHellmanHello { - fn get_size(&self) -> usize { - 0 - + 1 + sizeof_len((&self.gc).len()) - + 2 + sizeof_varint(*(&self.server_keys_known) as u64) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - w.write_with_tag(82, |w| w.write_bytes(&**&self.gc))?; - w.write_with_tag(160, |w| w.write_uint32(*&self.server_keys_known))?; - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct FeatureSet { - pub autoupdate2: Option, - pub current_location: Option, -} - -impl<'a> MessageRead<'a> for FeatureSet { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(8) => msg.autoupdate2 = Some(r.read_bool(bytes)?), - Ok(16) => msg.current_location = Some(r.read_bool(bytes)?), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for FeatureSet { - fn get_size(&self) -> usize { - 0 - + self.autoupdate2.as_ref().map_or(0, |m| 1 + sizeof_varint(*(m) as u64)) - + self.current_location.as_ref().map_or(0, |m| 1 + sizeof_varint(*(m) as u64)) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.autoupdate2 { w.write_with_tag(8, |w| w.write_bool(*s))?; } - if let Some(ref s) = self.current_location { w.write_with_tag(16, |w| w.write_bool(*s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct APResponseMessage { - pub challenge: Option, - pub upgrade: Option, - pub login_failed: Option, -} - -impl<'a> MessageRead<'a> for APResponseMessage { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(82) => msg.challenge = Some(r.read_message::(bytes)?), - Ok(162) => msg.upgrade = Some(r.read_message::(bytes)?), - Ok(242) => msg.login_failed = Some(r.read_message::(bytes)?), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for APResponseMessage { - fn get_size(&self) -> usize { - 0 - + self.challenge.as_ref().map_or(0, |m| 1 + sizeof_len((m).get_size())) - + self.upgrade.as_ref().map_or(0, |m| 2 + sizeof_len((m).get_size())) - + self.login_failed.as_ref().map_or(0, |m| 2 + sizeof_len((m).get_size())) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.challenge { w.write_with_tag(82, |w| w.write_message(s))?; } - if let Some(ref s) = self.upgrade { w.write_with_tag(162, |w| w.write_message(s))?; } - if let Some(ref s) = self.login_failed { w.write_with_tag(242, |w| w.write_message(s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct APChallenge { - pub login_crypto_challenge: keyexchange::LoginCryptoChallengeUnion, - pub fingerprint_challenge: keyexchange::FingerprintChallengeUnion, - pub pow_challenge: keyexchange::PoWChallengeUnion, - pub crypto_challenge: keyexchange::CryptoChallengeUnion, - pub server_nonce: Vec, - pub padding: Option>, -} - -impl<'a> MessageRead<'a> for APChallenge { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(82) => msg.login_crypto_challenge = r.read_message::(bytes)?, - Ok(162) => msg.fingerprint_challenge = r.read_message::(bytes)?, - Ok(242) => msg.pow_challenge = r.read_message::(bytes)?, - Ok(322) => msg.crypto_challenge = r.read_message::(bytes)?, - Ok(402) => msg.server_nonce = r.read_bytes(bytes)?.to_owned(), - Ok(482) => msg.padding = Some(r.read_bytes(bytes)?.to_owned()), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for APChallenge { - fn get_size(&self) -> usize { - 0 - + 1 + sizeof_len((&self.login_crypto_challenge).get_size()) - + 2 + sizeof_len((&self.fingerprint_challenge).get_size()) - + 2 + sizeof_len((&self.pow_challenge).get_size()) - + 2 + sizeof_len((&self.crypto_challenge).get_size()) - + 2 + sizeof_len((&self.server_nonce).len()) - + self.padding.as_ref().map_or(0, |m| 2 + sizeof_len((m).len())) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - w.write_with_tag(82, |w| w.write_message(&self.login_crypto_challenge))?; - w.write_with_tag(162, |w| w.write_message(&self.fingerprint_challenge))?; - w.write_with_tag(242, |w| w.write_message(&self.pow_challenge))?; - w.write_with_tag(322, |w| w.write_message(&self.crypto_challenge))?; - w.write_with_tag(402, |w| w.write_bytes(&**&self.server_nonce))?; - if let Some(ref s) = self.padding { w.write_with_tag(482, |w| w.write_bytes(&**s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct LoginCryptoChallengeUnion { - pub diffie_hellman: Option, -} - -impl<'a> MessageRead<'a> for LoginCryptoChallengeUnion { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(82) => msg.diffie_hellman = Some(r.read_message::(bytes)?), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for LoginCryptoChallengeUnion { - fn get_size(&self) -> usize { - 0 - + self.diffie_hellman.as_ref().map_or(0, |m| 1 + sizeof_len((m).get_size())) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.diffie_hellman { w.write_with_tag(82, |w| w.write_message(s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct LoginCryptoDiffieHellmanChallenge { - pub gs: Vec, - pub server_signature_key: i32, - pub gs_signature: Vec, -} - -impl<'a> MessageRead<'a> for LoginCryptoDiffieHellmanChallenge { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(82) => msg.gs = r.read_bytes(bytes)?.to_owned(), - Ok(160) => msg.server_signature_key = r.read_int32(bytes)?, - Ok(242) => msg.gs_signature = r.read_bytes(bytes)?.to_owned(), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for LoginCryptoDiffieHellmanChallenge { - fn get_size(&self) -> usize { - 0 - + 1 + sizeof_len((&self.gs).len()) - + 2 + sizeof_varint(*(&self.server_signature_key) as u64) - + 2 + sizeof_len((&self.gs_signature).len()) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - w.write_with_tag(82, |w| w.write_bytes(&**&self.gs))?; - w.write_with_tag(160, |w| w.write_int32(*&self.server_signature_key))?; - w.write_with_tag(242, |w| w.write_bytes(&**&self.gs_signature))?; - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct FingerprintChallengeUnion { - pub grain: Option, - pub hmac_ripemd: Option, -} - -impl<'a> MessageRead<'a> for FingerprintChallengeUnion { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(82) => msg.grain = Some(r.read_message::(bytes)?), - Ok(162) => msg.hmac_ripemd = Some(r.read_message::(bytes)?), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for FingerprintChallengeUnion { - fn get_size(&self) -> usize { - 0 - + self.grain.as_ref().map_or(0, |m| 1 + sizeof_len((m).get_size())) - + self.hmac_ripemd.as_ref().map_or(0, |m| 2 + sizeof_len((m).get_size())) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.grain { w.write_with_tag(82, |w| w.write_message(s))?; } - if let Some(ref s) = self.hmac_ripemd { w.write_with_tag(162, |w| w.write_message(s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct FingerprintGrainChallenge { - pub kek: Vec, -} - -impl<'a> MessageRead<'a> for FingerprintGrainChallenge { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(82) => msg.kek = r.read_bytes(bytes)?.to_owned(), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for FingerprintGrainChallenge { - fn get_size(&self) -> usize { - 0 - + 1 + sizeof_len((&self.kek).len()) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - w.write_with_tag(82, |w| w.write_bytes(&**&self.kek))?; - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct FingerprintHmacRipemdChallenge { - pub challenge: Vec, -} - -impl<'a> MessageRead<'a> for FingerprintHmacRipemdChallenge { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(82) => msg.challenge = r.read_bytes(bytes)?.to_owned(), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for FingerprintHmacRipemdChallenge { - fn get_size(&self) -> usize { - 0 - + 1 + sizeof_len((&self.challenge).len()) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - w.write_with_tag(82, |w| w.write_bytes(&**&self.challenge))?; - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct PoWChallengeUnion { - pub hash_cash: Option, -} - -impl<'a> MessageRead<'a> for PoWChallengeUnion { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(82) => msg.hash_cash = Some(r.read_message::(bytes)?), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for PoWChallengeUnion { - fn get_size(&self) -> usize { - 0 - + self.hash_cash.as_ref().map_or(0, |m| 1 + sizeof_len((m).get_size())) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.hash_cash { w.write_with_tag(82, |w| w.write_message(s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct PoWHashCashChallenge { - pub prefix: Option>, - pub length: Option, - pub target: Option, -} - -impl<'a> MessageRead<'a> for PoWHashCashChallenge { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(82) => msg.prefix = Some(r.read_bytes(bytes)?.to_owned()), - Ok(160) => msg.length = Some(r.read_int32(bytes)?), - Ok(240) => msg.target = Some(r.read_int32(bytes)?), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for PoWHashCashChallenge { - fn get_size(&self) -> usize { - 0 - + self.prefix.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - + self.length.as_ref().map_or(0, |m| 2 + sizeof_varint(*(m) as u64)) - + self.target.as_ref().map_or(0, |m| 2 + sizeof_varint(*(m) as u64)) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.prefix { w.write_with_tag(82, |w| w.write_bytes(&**s))?; } - if let Some(ref s) = self.length { w.write_with_tag(160, |w| w.write_int32(*s))?; } - if let Some(ref s) = self.target { w.write_with_tag(240, |w| w.write_int32(*s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct CryptoChallengeUnion { - pub shannon: Option, - pub rc4_sha1_hmac: Option, -} - -impl<'a> MessageRead<'a> for CryptoChallengeUnion { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(82) => msg.shannon = Some(r.read_message::(bytes)?), - Ok(162) => msg.rc4_sha1_hmac = Some(r.read_message::(bytes)?), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for CryptoChallengeUnion { - fn get_size(&self) -> usize { - 0 - + self.shannon.as_ref().map_or(0, |m| 1 + sizeof_len((m).get_size())) - + self.rc4_sha1_hmac.as_ref().map_or(0, |m| 2 + sizeof_len((m).get_size())) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.shannon { w.write_with_tag(82, |w| w.write_message(s))?; } - if let Some(ref s) = self.rc4_sha1_hmac { w.write_with_tag(162, |w| w.write_message(s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct CryptoShannonChallenge { } - -impl<'a> MessageRead<'a> for CryptoShannonChallenge { - fn from_reader(r: &mut BytesReader, _: &[u8]) -> Result { - r.read_to_end(); - Ok(Self::default()) - } -} - -impl MessageWrite for CryptoShannonChallenge { } - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct CryptoRc4Sha1HmacChallenge { } - -impl<'a> MessageRead<'a> for CryptoRc4Sha1HmacChallenge { - fn from_reader(r: &mut BytesReader, _: &[u8]) -> Result { - r.read_to_end(); - Ok(Self::default()) - } -} - -impl MessageWrite for CryptoRc4Sha1HmacChallenge { } - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct UpgradeRequiredMessage { - pub upgrade_signed_part: Vec, - pub signature: Vec, - pub http_suffix: Option, -} - -impl<'a> MessageRead<'a> for UpgradeRequiredMessage { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(82) => msg.upgrade_signed_part = r.read_bytes(bytes)?.to_owned(), - Ok(162) => msg.signature = r.read_bytes(bytes)?.to_owned(), - Ok(242) => msg.http_suffix = Some(r.read_string(bytes)?.to_owned()), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for UpgradeRequiredMessage { - fn get_size(&self) -> usize { - 0 - + 1 + sizeof_len((&self.upgrade_signed_part).len()) - + 2 + sizeof_len((&self.signature).len()) - + self.http_suffix.as_ref().map_or(0, |m| 2 + sizeof_len((m).len())) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - w.write_with_tag(82, |w| w.write_bytes(&**&self.upgrade_signed_part))?; - w.write_with_tag(162, |w| w.write_bytes(&**&self.signature))?; - if let Some(ref s) = self.http_suffix { w.write_with_tag(242, |w| w.write_string(&**s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct APLoginFailed { - pub error_code: keyexchange::ErrorCode, - pub retry_delay: Option, - pub expiry: Option, - pub error_description: Option, -} - -impl<'a> MessageRead<'a> for APLoginFailed { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(80) => msg.error_code = r.read_enum(bytes)?, - Ok(160) => msg.retry_delay = Some(r.read_int32(bytes)?), - Ok(240) => msg.expiry = Some(r.read_int32(bytes)?), - Ok(322) => msg.error_description = Some(r.read_string(bytes)?.to_owned()), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for APLoginFailed { - fn get_size(&self) -> usize { - 0 - + 1 + sizeof_varint(*(&self.error_code) as u64) - + self.retry_delay.as_ref().map_or(0, |m| 2 + sizeof_varint(*(m) as u64)) - + self.expiry.as_ref().map_or(0, |m| 2 + sizeof_varint(*(m) as u64)) - + self.error_description.as_ref().map_or(0, |m| 2 + sizeof_len((m).len())) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - w.write_with_tag(80, |w| w.write_enum(*&self.error_code as i32))?; - if let Some(ref s) = self.retry_delay { w.write_with_tag(160, |w| w.write_int32(*s))?; } - if let Some(ref s) = self.expiry { w.write_with_tag(240, |w| w.write_int32(*s))?; } - if let Some(ref s) = self.error_description { w.write_with_tag(322, |w| w.write_string(&**s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct ClientResponsePlaintext { - pub login_crypto_response: keyexchange::LoginCryptoResponseUnion, - pub pow_response: keyexchange::PoWResponseUnion, - pub crypto_response: keyexchange::CryptoResponseUnion, -} - -impl<'a> MessageRead<'a> for ClientResponsePlaintext { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(82) => msg.login_crypto_response = r.read_message::(bytes)?, - Ok(162) => msg.pow_response = r.read_message::(bytes)?, - Ok(242) => msg.crypto_response = r.read_message::(bytes)?, - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for ClientResponsePlaintext { - fn get_size(&self) -> usize { - 0 - + 1 + sizeof_len((&self.login_crypto_response).get_size()) - + 2 + sizeof_len((&self.pow_response).get_size()) - + 2 + sizeof_len((&self.crypto_response).get_size()) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - w.write_with_tag(82, |w| w.write_message(&self.login_crypto_response))?; - w.write_with_tag(162, |w| w.write_message(&self.pow_response))?; - w.write_with_tag(242, |w| w.write_message(&self.crypto_response))?; - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct LoginCryptoResponseUnion { - pub diffie_hellman: Option, -} - -impl<'a> MessageRead<'a> for LoginCryptoResponseUnion { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(82) => msg.diffie_hellman = Some(r.read_message::(bytes)?), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for LoginCryptoResponseUnion { - fn get_size(&self) -> usize { - 0 - + self.diffie_hellman.as_ref().map_or(0, |m| 1 + sizeof_len((m).get_size())) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.diffie_hellman { w.write_with_tag(82, |w| w.write_message(s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct LoginCryptoDiffieHellmanResponse { - pub hmac: Vec, -} - -impl<'a> MessageRead<'a> for LoginCryptoDiffieHellmanResponse { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(82) => msg.hmac = r.read_bytes(bytes)?.to_owned(), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for LoginCryptoDiffieHellmanResponse { - fn get_size(&self) -> usize { - 0 - + 1 + sizeof_len((&self.hmac).len()) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - w.write_with_tag(82, |w| w.write_bytes(&**&self.hmac))?; - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct PoWResponseUnion { - pub hash_cash: Option, -} - -impl<'a> MessageRead<'a> for PoWResponseUnion { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(82) => msg.hash_cash = Some(r.read_message::(bytes)?), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for PoWResponseUnion { - fn get_size(&self) -> usize { - 0 - + self.hash_cash.as_ref().map_or(0, |m| 1 + sizeof_len((m).get_size())) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.hash_cash { w.write_with_tag(82, |w| w.write_message(s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct PoWHashCashResponse { - pub hash_suffix: Vec, -} - -impl<'a> MessageRead<'a> for PoWHashCashResponse { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(82) => msg.hash_suffix = r.read_bytes(bytes)?.to_owned(), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for PoWHashCashResponse { - fn get_size(&self) -> usize { - 0 - + 1 + sizeof_len((&self.hash_suffix).len()) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - w.write_with_tag(82, |w| w.write_bytes(&**&self.hash_suffix))?; - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct CryptoResponseUnion { - pub shannon: Option, - pub rc4_sha1_hmac: Option, -} - -impl<'a> MessageRead<'a> for CryptoResponseUnion { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(82) => msg.shannon = Some(r.read_message::(bytes)?), - Ok(162) => msg.rc4_sha1_hmac = Some(r.read_message::(bytes)?), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for CryptoResponseUnion { - fn get_size(&self) -> usize { - 0 - + self.shannon.as_ref().map_or(0, |m| 1 + sizeof_len((m).get_size())) - + self.rc4_sha1_hmac.as_ref().map_or(0, |m| 2 + sizeof_len((m).get_size())) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.shannon { w.write_with_tag(82, |w| w.write_message(s))?; } - if let Some(ref s) = self.rc4_sha1_hmac { w.write_with_tag(162, |w| w.write_message(s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct CryptoShannonResponse { - pub dummy: Option, -} - -impl<'a> MessageRead<'a> for CryptoShannonResponse { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(8) => msg.dummy = Some(r.read_int32(bytes)?), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for CryptoShannonResponse { - fn get_size(&self) -> usize { - 0 - + self.dummy.as_ref().map_or(0, |m| 1 + sizeof_varint(*(m) as u64)) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.dummy { w.write_with_tag(8, |w| w.write_int32(*s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct CryptoRc4Sha1HmacResponse { - pub dummy: Option, -} - -impl<'a> MessageRead<'a> for CryptoRc4Sha1HmacResponse { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(8) => msg.dummy = Some(r.read_int32(bytes)?), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for CryptoRc4Sha1HmacResponse { - fn get_size(&self) -> usize { - 0 - + self.dummy.as_ref().map_or(0, |m| 1 + sizeof_varint(*(m) as u64)) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.dummy { w.write_with_tag(8, |w| w.write_int32(*s))?; } - Ok(()) - } -} - diff --git a/psst-protocol/src/lib.rs b/psst-protocol/src/lib.rs deleted file mode 100644 index b4a8069b..00000000 --- a/psst-protocol/src/lib.rs +++ /dev/null @@ -1,4 +0,0 @@ -pub mod authentication; -pub mod keyexchange; -pub mod mercury; -pub mod metadata; diff --git a/psst-protocol/src/mercury.rs b/psst-protocol/src/mercury.rs deleted file mode 100644 index e6d728eb..00000000 --- a/psst-protocol/src/mercury.rs +++ /dev/null @@ -1,297 +0,0 @@ -// Automatically generated rust module for 'mercury.proto' file - -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(non_camel_case_types)] -#![allow(unused_imports)] -#![allow(unknown_lints)] -#![allow(clippy::all)] -#![cfg_attr(rustfmt, rustfmt_skip)] - - -use quick_protobuf::{MessageRead, MessageWrite, BytesReader, Writer, WriterBackend, Result}; -use quick_protobuf::sizeofs::*; -use super::*; - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct MercuryMultiGetRequest { - pub request: Vec, -} - -impl<'a> MessageRead<'a> for MercuryMultiGetRequest { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(10) => msg.request.push(r.read_message::(bytes)?), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for MercuryMultiGetRequest { - fn get_size(&self) -> usize { - 0 - + self.request.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::() - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - for s in &self.request { w.write_with_tag(10, |w| w.write_message(s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct MercuryMultiGetReply { - pub reply: Vec, -} - -impl<'a> MessageRead<'a> for MercuryMultiGetReply { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(10) => msg.reply.push(r.read_message::(bytes)?), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for MercuryMultiGetReply { - fn get_size(&self) -> usize { - 0 - + self.reply.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::() - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - for s in &self.reply { w.write_with_tag(10, |w| w.write_message(s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct MercuryRequest { - pub uri: Option, - pub content_type: Option, - pub body: Option>, - pub etag: Option>, -} - -impl<'a> MessageRead<'a> for MercuryRequest { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(10) => msg.uri = Some(r.read_string(bytes)?.to_owned()), - Ok(18) => msg.content_type = Some(r.read_string(bytes)?.to_owned()), - Ok(26) => msg.body = Some(r.read_bytes(bytes)?.to_owned()), - Ok(34) => msg.etag = Some(r.read_bytes(bytes)?.to_owned()), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for MercuryRequest { - fn get_size(&self) -> usize { - 0 - + self.uri.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - + self.content_type.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - + self.body.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - + self.etag.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.uri { w.write_with_tag(10, |w| w.write_string(&**s))?; } - if let Some(ref s) = self.content_type { w.write_with_tag(18, |w| w.write_string(&**s))?; } - if let Some(ref s) = self.body { w.write_with_tag(26, |w| w.write_bytes(&**s))?; } - if let Some(ref s) = self.etag { w.write_with_tag(34, |w| w.write_bytes(&**s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct MercuryReply { - pub status_code: Option, - pub status_message: Option, - pub cache_policy: Option, - pub ttl: Option, - pub etag: Option>, - pub content_type: Option, - pub body: Option>, -} - -impl<'a> MessageRead<'a> for MercuryReply { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(8) => msg.status_code = Some(r.read_sint32(bytes)?), - Ok(18) => msg.status_message = Some(r.read_string(bytes)?.to_owned()), - Ok(24) => msg.cache_policy = Some(r.read_enum(bytes)?), - Ok(32) => msg.ttl = Some(r.read_sint32(bytes)?), - Ok(42) => msg.etag = Some(r.read_bytes(bytes)?.to_owned()), - Ok(50) => msg.content_type = Some(r.read_string(bytes)?.to_owned()), - Ok(58) => msg.body = Some(r.read_bytes(bytes)?.to_owned()), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for MercuryReply { - fn get_size(&self) -> usize { - 0 - + self.status_code.as_ref().map_or(0, |m| 1 + sizeof_sint32(*(m))) - + self.status_message.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - + self.cache_policy.as_ref().map_or(0, |m| 1 + sizeof_varint(*(m) as u64)) - + self.ttl.as_ref().map_or(0, |m| 1 + sizeof_sint32(*(m))) - + self.etag.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - + self.content_type.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - + self.body.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.status_code { w.write_with_tag(8, |w| w.write_sint32(*s))?; } - if let Some(ref s) = self.status_message { w.write_with_tag(18, |w| w.write_string(&**s))?; } - if let Some(ref s) = self.cache_policy { w.write_with_tag(24, |w| w.write_enum(*s as i32))?; } - if let Some(ref s) = self.ttl { w.write_with_tag(32, |w| w.write_sint32(*s))?; } - if let Some(ref s) = self.etag { w.write_with_tag(42, |w| w.write_bytes(&**s))?; } - if let Some(ref s) = self.content_type { w.write_with_tag(50, |w| w.write_string(&**s))?; } - if let Some(ref s) = self.body { w.write_with_tag(58, |w| w.write_bytes(&**s))?; } - Ok(()) - } -} - -pub mod mod_MercuryReply { - - -#[derive(Debug, PartialEq, Eq, Clone, Copy)] -pub enum CachePolicy { - CACHE_NO = 1, - CACHE_PRIVATE = 2, - CACHE_PUBLIC = 3, -} - -impl Default for CachePolicy { - fn default() -> Self { - CachePolicy::CACHE_NO - } -} - -impl From for CachePolicy { - fn from(i: i32) -> Self { - match i { - 1 => CachePolicy::CACHE_NO, - 2 => CachePolicy::CACHE_PRIVATE, - 3 => CachePolicy::CACHE_PUBLIC, - _ => Self::default(), - } - } -} - -impl<'a> From<&'a str> for CachePolicy { - fn from(s: &'a str) -> Self { - match s { - "CACHE_NO" => CachePolicy::CACHE_NO, - "CACHE_PRIVATE" => CachePolicy::CACHE_PRIVATE, - "CACHE_PUBLIC" => CachePolicy::CACHE_PUBLIC, - _ => Self::default(), - } - } -} - -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct Header { - pub uri: Option, - pub content_type: Option, - pub method: Option, - pub status_code: Option, - pub user_fields: Vec, -} - -impl<'a> MessageRead<'a> for Header { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(10) => msg.uri = Some(r.read_string(bytes)?.to_owned()), - Ok(18) => msg.content_type = Some(r.read_string(bytes)?.to_owned()), - Ok(26) => msg.method = Some(r.read_string(bytes)?.to_owned()), - Ok(32) => msg.status_code = Some(r.read_sint32(bytes)?), - Ok(50) => msg.user_fields.push(r.read_message::(bytes)?), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for Header { - fn get_size(&self) -> usize { - 0 - + self.uri.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - + self.content_type.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - + self.method.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - + self.status_code.as_ref().map_or(0, |m| 1 + sizeof_sint32(*(m))) - + self.user_fields.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::() - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.uri { w.write_with_tag(10, |w| w.write_string(&**s))?; } - if let Some(ref s) = self.content_type { w.write_with_tag(18, |w| w.write_string(&**s))?; } - if let Some(ref s) = self.method { w.write_with_tag(26, |w| w.write_string(&**s))?; } - if let Some(ref s) = self.status_code { w.write_with_tag(32, |w| w.write_sint32(*s))?; } - for s in &self.user_fields { w.write_with_tag(50, |w| w.write_message(s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct UserField { - pub key: Option, - pub value: Option>, -} - -impl<'a> MessageRead<'a> for UserField { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(10) => msg.key = Some(r.read_string(bytes)?.to_owned()), - Ok(18) => msg.value = Some(r.read_bytes(bytes)?.to_owned()), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for UserField { - fn get_size(&self) -> usize { - 0 - + self.key.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - + self.value.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.key { w.write_with_tag(10, |w| w.write_string(&**s))?; } - if let Some(ref s) = self.value { w.write_with_tag(18, |w| w.write_bytes(&**s))?; } - Ok(()) - } -} - diff --git a/psst-protocol/src/metadata.rs b/psst-protocol/src/metadata.rs deleted file mode 100644 index eac67b6e..00000000 --- a/psst-protocol/src/metadata.rs +++ /dev/null @@ -1,1530 +0,0 @@ -// Automatically generated rust module for 'metadata.proto' file - -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(non_camel_case_types)] -#![allow(unused_imports)] -#![allow(unknown_lints)] -#![allow(clippy::all)] -#![cfg_attr(rustfmt, rustfmt_skip)] - - -use quick_protobuf::{MessageRead, MessageWrite, BytesReader, Writer, WriterBackend, Result}; -use quick_protobuf::sizeofs::*; -use super::*; - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct TopTracks { - pub country: Option, - pub track: Vec, -} - -impl<'a> MessageRead<'a> for TopTracks { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(10) => msg.country = Some(r.read_string(bytes)?.to_owned()), - Ok(18) => msg.track.push(r.read_message::(bytes)?), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for TopTracks { - fn get_size(&self) -> usize { - 0 - + self.country.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - + self.track.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::() - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.country { w.write_with_tag(10, |w| w.write_string(&**s))?; } - for s in &self.track { w.write_with_tag(18, |w| w.write_message(s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct ActivityPeriod { - pub start_year: Option, - pub end_year: Option, - pub decade: Option, -} - -impl<'a> MessageRead<'a> for ActivityPeriod { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(8) => msg.start_year = Some(r.read_sint32(bytes)?), - Ok(16) => msg.end_year = Some(r.read_sint32(bytes)?), - Ok(24) => msg.decade = Some(r.read_sint32(bytes)?), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for ActivityPeriod { - fn get_size(&self) -> usize { - 0 - + self.start_year.as_ref().map_or(0, |m| 1 + sizeof_sint32(*(m))) - + self.end_year.as_ref().map_or(0, |m| 1 + sizeof_sint32(*(m))) - + self.decade.as_ref().map_or(0, |m| 1 + sizeof_sint32(*(m))) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.start_year { w.write_with_tag(8, |w| w.write_sint32(*s))?; } - if let Some(ref s) = self.end_year { w.write_with_tag(16, |w| w.write_sint32(*s))?; } - if let Some(ref s) = self.decade { w.write_with_tag(24, |w| w.write_sint32(*s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct Artist { - pub gid: Option>, - pub name: Option, - pub popularity: Option, - pub top_track: Vec, - pub album_group: Vec, - pub single_group: Vec, - pub compilation_group: Vec, - pub appears_on_group: Vec, - pub genre: Vec, - pub external_id: Vec, - pub portrait: Vec, - pub biography: Vec, - pub activity_period: Vec, - pub restriction: Vec, - pub related: Vec, - pub is_portrait_album_cover: Option, - pub portrait_group: Option, -} - -impl<'a> MessageRead<'a> for Artist { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(10) => msg.gid = Some(r.read_bytes(bytes)?.to_owned()), - Ok(18) => msg.name = Some(r.read_string(bytes)?.to_owned()), - Ok(24) => msg.popularity = Some(r.read_sint32(bytes)?), - Ok(34) => msg.top_track.push(r.read_message::(bytes)?), - Ok(42) => msg.album_group.push(r.read_message::(bytes)?), - Ok(50) => msg.single_group.push(r.read_message::(bytes)?), - Ok(58) => msg.compilation_group.push(r.read_message::(bytes)?), - Ok(66) => msg.appears_on_group.push(r.read_message::(bytes)?), - Ok(74) => msg.genre.push(r.read_string(bytes)?.to_owned()), - Ok(82) => msg.external_id.push(r.read_message::(bytes)?), - Ok(90) => msg.portrait.push(r.read_message::(bytes)?), - Ok(98) => msg.biography.push(r.read_message::(bytes)?), - Ok(106) => msg.activity_period.push(r.read_message::(bytes)?), - Ok(114) => msg.restriction.push(r.read_message::(bytes)?), - Ok(122) => msg.related.push(r.read_message::(bytes)?), - Ok(128) => msg.is_portrait_album_cover = Some(r.read_bool(bytes)?), - Ok(138) => msg.portrait_group = Some(r.read_message::(bytes)?), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for Artist { - fn get_size(&self) -> usize { - 0 - + self.gid.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - + self.name.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - + self.popularity.as_ref().map_or(0, |m| 1 + sizeof_sint32(*(m))) - + self.top_track.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::() - + self.album_group.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::() - + self.single_group.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::() - + self.compilation_group.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::() - + self.appears_on_group.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::() - + self.genre.iter().map(|s| 1 + sizeof_len((s).len())).sum::() - + self.external_id.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::() - + self.portrait.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::() - + self.biography.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::() - + self.activity_period.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::() - + self.restriction.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::() - + self.related.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::() - + self.is_portrait_album_cover.as_ref().map_or(0, |m| 2 + sizeof_varint(*(m) as u64)) - + self.portrait_group.as_ref().map_or(0, |m| 2 + sizeof_len((m).get_size())) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.gid { w.write_with_tag(10, |w| w.write_bytes(&**s))?; } - if let Some(ref s) = self.name { w.write_with_tag(18, |w| w.write_string(&**s))?; } - if let Some(ref s) = self.popularity { w.write_with_tag(24, |w| w.write_sint32(*s))?; } - for s in &self.top_track { w.write_with_tag(34, |w| w.write_message(s))?; } - for s in &self.album_group { w.write_with_tag(42, |w| w.write_message(s))?; } - for s in &self.single_group { w.write_with_tag(50, |w| w.write_message(s))?; } - for s in &self.compilation_group { w.write_with_tag(58, |w| w.write_message(s))?; } - for s in &self.appears_on_group { w.write_with_tag(66, |w| w.write_message(s))?; } - for s in &self.genre { w.write_with_tag(74, |w| w.write_string(&**s))?; } - for s in &self.external_id { w.write_with_tag(82, |w| w.write_message(s))?; } - for s in &self.portrait { w.write_with_tag(90, |w| w.write_message(s))?; } - for s in &self.biography { w.write_with_tag(98, |w| w.write_message(s))?; } - for s in &self.activity_period { w.write_with_tag(106, |w| w.write_message(s))?; } - for s in &self.restriction { w.write_with_tag(114, |w| w.write_message(s))?; } - for s in &self.related { w.write_with_tag(122, |w| w.write_message(s))?; } - if let Some(ref s) = self.is_portrait_album_cover { w.write_with_tag(128, |w| w.write_bool(*s))?; } - if let Some(ref s) = self.portrait_group { w.write_with_tag(138, |w| w.write_message(s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct AlbumGroup { - pub album: Vec, -} - -impl<'a> MessageRead<'a> for AlbumGroup { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(10) => msg.album.push(r.read_message::(bytes)?), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for AlbumGroup { - fn get_size(&self) -> usize { - 0 - + self.album.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::() - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - for s in &self.album { w.write_with_tag(10, |w| w.write_message(s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct Date { - pub year: Option, - pub month: Option, - pub day: Option, - pub hour: Option, - pub minute: Option, -} - -impl<'a> MessageRead<'a> for Date { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(8) => msg.year = Some(r.read_sint32(bytes)?), - Ok(16) => msg.month = Some(r.read_sint32(bytes)?), - Ok(24) => msg.day = Some(r.read_sint32(bytes)?), - Ok(32) => msg.hour = Some(r.read_sint32(bytes)?), - Ok(40) => msg.minute = Some(r.read_sint32(bytes)?), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for Date { - fn get_size(&self) -> usize { - 0 - + self.year.as_ref().map_or(0, |m| 1 + sizeof_sint32(*(m))) - + self.month.as_ref().map_or(0, |m| 1 + sizeof_sint32(*(m))) - + self.day.as_ref().map_or(0, |m| 1 + sizeof_sint32(*(m))) - + self.hour.as_ref().map_or(0, |m| 1 + sizeof_sint32(*(m))) - + self.minute.as_ref().map_or(0, |m| 1 + sizeof_sint32(*(m))) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.year { w.write_with_tag(8, |w| w.write_sint32(*s))?; } - if let Some(ref s) = self.month { w.write_with_tag(16, |w| w.write_sint32(*s))?; } - if let Some(ref s) = self.day { w.write_with_tag(24, |w| w.write_sint32(*s))?; } - if let Some(ref s) = self.hour { w.write_with_tag(32, |w| w.write_sint32(*s))?; } - if let Some(ref s) = self.minute { w.write_with_tag(40, |w| w.write_sint32(*s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct Album { - pub gid: Option>, - pub name: Option, - pub artist: Vec, - pub typ: Option, - pub label: Option, - pub date: Option, - pub popularity: Option, - pub genre: Vec, - pub cover: Vec, - pub external_id: Vec, - pub disc: Vec, - pub review: Vec, - pub copyright: Vec, - pub restriction: Vec, - pub related: Vec, - pub sale_period: Vec, - pub cover_group: Option, -} - -impl<'a> MessageRead<'a> for Album { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(10) => msg.gid = Some(r.read_bytes(bytes)?.to_owned()), - Ok(18) => msg.name = Some(r.read_string(bytes)?.to_owned()), - Ok(26) => msg.artist.push(r.read_message::(bytes)?), - Ok(32) => msg.typ = Some(r.read_enum(bytes)?), - Ok(42) => msg.label = Some(r.read_string(bytes)?.to_owned()), - Ok(50) => msg.date = Some(r.read_message::(bytes)?), - Ok(56) => msg.popularity = Some(r.read_sint32(bytes)?), - Ok(66) => msg.genre.push(r.read_string(bytes)?.to_owned()), - Ok(74) => msg.cover.push(r.read_message::(bytes)?), - Ok(82) => msg.external_id.push(r.read_message::(bytes)?), - Ok(90) => msg.disc.push(r.read_message::(bytes)?), - Ok(98) => msg.review.push(r.read_string(bytes)?.to_owned()), - Ok(106) => msg.copyright.push(r.read_message::(bytes)?), - Ok(114) => msg.restriction.push(r.read_message::(bytes)?), - Ok(122) => msg.related.push(r.read_message::(bytes)?), - Ok(130) => msg.sale_period.push(r.read_message::(bytes)?), - Ok(138) => msg.cover_group = Some(r.read_message::(bytes)?), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for Album { - fn get_size(&self) -> usize { - 0 - + self.gid.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - + self.name.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - + self.artist.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::() - + self.typ.as_ref().map_or(0, |m| 1 + sizeof_varint(*(m) as u64)) - + self.label.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - + self.date.as_ref().map_or(0, |m| 1 + sizeof_len((m).get_size())) - + self.popularity.as_ref().map_or(0, |m| 1 + sizeof_sint32(*(m))) - + self.genre.iter().map(|s| 1 + sizeof_len((s).len())).sum::() - + self.cover.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::() - + self.external_id.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::() - + self.disc.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::() - + self.review.iter().map(|s| 1 + sizeof_len((s).len())).sum::() - + self.copyright.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::() - + self.restriction.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::() - + self.related.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::() - + self.sale_period.iter().map(|s| 2 + sizeof_len((s).get_size())).sum::() - + self.cover_group.as_ref().map_or(0, |m| 2 + sizeof_len((m).get_size())) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.gid { w.write_with_tag(10, |w| w.write_bytes(&**s))?; } - if let Some(ref s) = self.name { w.write_with_tag(18, |w| w.write_string(&**s))?; } - for s in &self.artist { w.write_with_tag(26, |w| w.write_message(s))?; } - if let Some(ref s) = self.typ { w.write_with_tag(32, |w| w.write_enum(*s as i32))?; } - if let Some(ref s) = self.label { w.write_with_tag(42, |w| w.write_string(&**s))?; } - if let Some(ref s) = self.date { w.write_with_tag(50, |w| w.write_message(s))?; } - if let Some(ref s) = self.popularity { w.write_with_tag(56, |w| w.write_sint32(*s))?; } - for s in &self.genre { w.write_with_tag(66, |w| w.write_string(&**s))?; } - for s in &self.cover { w.write_with_tag(74, |w| w.write_message(s))?; } - for s in &self.external_id { w.write_with_tag(82, |w| w.write_message(s))?; } - for s in &self.disc { w.write_with_tag(90, |w| w.write_message(s))?; } - for s in &self.review { w.write_with_tag(98, |w| w.write_string(&**s))?; } - for s in &self.copyright { w.write_with_tag(106, |w| w.write_message(s))?; } - for s in &self.restriction { w.write_with_tag(114, |w| w.write_message(s))?; } - for s in &self.related { w.write_with_tag(122, |w| w.write_message(s))?; } - for s in &self.sale_period { w.write_with_tag(130, |w| w.write_message(s))?; } - if let Some(ref s) = self.cover_group { w.write_with_tag(138, |w| w.write_message(s))?; } - Ok(()) - } -} - -pub mod mod_Album { - - -#[derive(Debug, PartialEq, Eq, Clone, Copy)] -pub enum Type { - ALBUM = 1, - SINGLE = 2, - COMPILATION = 3, - EP = 4, -} - -impl Default for Type { - fn default() -> Self { - Type::ALBUM - } -} - -impl From for Type { - fn from(i: i32) -> Self { - match i { - 1 => Type::ALBUM, - 2 => Type::SINGLE, - 3 => Type::COMPILATION, - 4 => Type::EP, - _ => Self::default(), - } - } -} - -impl<'a> From<&'a str> for Type { - fn from(s: &'a str) -> Self { - match s { - "ALBUM" => Type::ALBUM, - "SINGLE" => Type::SINGLE, - "COMPILATION" => Type::COMPILATION, - "EP" => Type::EP, - _ => Self::default(), - } - } -} - -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct Track { - pub gid: Option>, - pub name: Option, - pub album: Option, - pub artist: Vec, - pub number: Option, - pub disc_number: Option, - pub duration: Option, - pub popularity: Option, - pub explicit: Option, - pub external_id: Vec, - pub restriction: Vec, - pub file: Vec, - pub alternative: Vec, - pub sale_period: Vec, - pub preview: Vec, -} - -impl<'a> MessageRead<'a> for Track { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(10) => msg.gid = Some(r.read_bytes(bytes)?.to_owned()), - Ok(18) => msg.name = Some(r.read_string(bytes)?.to_owned()), - Ok(26) => msg.album = Some(r.read_message::(bytes)?), - Ok(34) => msg.artist.push(r.read_message::(bytes)?), - Ok(40) => msg.number = Some(r.read_sint32(bytes)?), - Ok(48) => msg.disc_number = Some(r.read_sint32(bytes)?), - Ok(56) => msg.duration = Some(r.read_sint32(bytes)?), - Ok(64) => msg.popularity = Some(r.read_sint32(bytes)?), - Ok(72) => msg.explicit = Some(r.read_bool(bytes)?), - Ok(82) => msg.external_id.push(r.read_message::(bytes)?), - Ok(90) => msg.restriction.push(r.read_message::(bytes)?), - Ok(98) => msg.file.push(r.read_message::(bytes)?), - Ok(106) => msg.alternative.push(r.read_message::(bytes)?), - Ok(114) => msg.sale_period.push(r.read_message::(bytes)?), - Ok(122) => msg.preview.push(r.read_message::(bytes)?), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for Track { - fn get_size(&self) -> usize { - 0 - + self.gid.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - + self.name.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - + self.album.as_ref().map_or(0, |m| 1 + sizeof_len((m).get_size())) - + self.artist.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::() - + self.number.as_ref().map_or(0, |m| 1 + sizeof_sint32(*(m))) - + self.disc_number.as_ref().map_or(0, |m| 1 + sizeof_sint32(*(m))) - + self.duration.as_ref().map_or(0, |m| 1 + sizeof_sint32(*(m))) - + self.popularity.as_ref().map_or(0, |m| 1 + sizeof_sint32(*(m))) - + self.explicit.as_ref().map_or(0, |m| 1 + sizeof_varint(*(m) as u64)) - + self.external_id.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::() - + self.restriction.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::() - + self.file.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::() - + self.alternative.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::() - + self.sale_period.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::() - + self.preview.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::() - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.gid { w.write_with_tag(10, |w| w.write_bytes(&**s))?; } - if let Some(ref s) = self.name { w.write_with_tag(18, |w| w.write_string(&**s))?; } - if let Some(ref s) = self.album { w.write_with_tag(26, |w| w.write_message(s))?; } - for s in &self.artist { w.write_with_tag(34, |w| w.write_message(s))?; } - if let Some(ref s) = self.number { w.write_with_tag(40, |w| w.write_sint32(*s))?; } - if let Some(ref s) = self.disc_number { w.write_with_tag(48, |w| w.write_sint32(*s))?; } - if let Some(ref s) = self.duration { w.write_with_tag(56, |w| w.write_sint32(*s))?; } - if let Some(ref s) = self.popularity { w.write_with_tag(64, |w| w.write_sint32(*s))?; } - if let Some(ref s) = self.explicit { w.write_with_tag(72, |w| w.write_bool(*s))?; } - for s in &self.external_id { w.write_with_tag(82, |w| w.write_message(s))?; } - for s in &self.restriction { w.write_with_tag(90, |w| w.write_message(s))?; } - for s in &self.file { w.write_with_tag(98, |w| w.write_message(s))?; } - for s in &self.alternative { w.write_with_tag(106, |w| w.write_message(s))?; } - for s in &self.sale_period { w.write_with_tag(114, |w| w.write_message(s))?; } - for s in &self.preview { w.write_with_tag(122, |w| w.write_message(s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct Image { - pub file_id: Option>, - pub size: Option, - pub width: Option, - pub height: Option, -} - -impl<'a> MessageRead<'a> for Image { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(10) => msg.file_id = Some(r.read_bytes(bytes)?.to_owned()), - Ok(16) => msg.size = Some(r.read_enum(bytes)?), - Ok(24) => msg.width = Some(r.read_sint32(bytes)?), - Ok(32) => msg.height = Some(r.read_sint32(bytes)?), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for Image { - fn get_size(&self) -> usize { - 0 - + self.file_id.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - + self.size.as_ref().map_or(0, |m| 1 + sizeof_varint(*(m) as u64)) - + self.width.as_ref().map_or(0, |m| 1 + sizeof_sint32(*(m))) - + self.height.as_ref().map_or(0, |m| 1 + sizeof_sint32(*(m))) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.file_id { w.write_with_tag(10, |w| w.write_bytes(&**s))?; } - if let Some(ref s) = self.size { w.write_with_tag(16, |w| w.write_enum(*s as i32))?; } - if let Some(ref s) = self.width { w.write_with_tag(24, |w| w.write_sint32(*s))?; } - if let Some(ref s) = self.height { w.write_with_tag(32, |w| w.write_sint32(*s))?; } - Ok(()) - } -} - -pub mod mod_Image { - - -#[derive(Debug, PartialEq, Eq, Clone, Copy)] -pub enum Size { - DEFAULT = 0, - SMALL = 1, - LARGE = 2, - XLARGE = 3, -} - -impl Default for Size { - fn default() -> Self { - Size::DEFAULT - } -} - -impl From for Size { - fn from(i: i32) -> Self { - match i { - 0 => Size::DEFAULT, - 1 => Size::SMALL, - 2 => Size::LARGE, - 3 => Size::XLARGE, - _ => Self::default(), - } - } -} - -impl<'a> From<&'a str> for Size { - fn from(s: &'a str) -> Self { - match s { - "DEFAULT" => Size::DEFAULT, - "SMALL" => Size::SMALL, - "LARGE" => Size::LARGE, - "XLARGE" => Size::XLARGE, - _ => Self::default(), - } - } -} - -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct ImageGroup { - pub image: Vec, -} - -impl<'a> MessageRead<'a> for ImageGroup { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(10) => msg.image.push(r.read_message::(bytes)?), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for ImageGroup { - fn get_size(&self) -> usize { - 0 - + self.image.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::() - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - for s in &self.image { w.write_with_tag(10, |w| w.write_message(s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct Biography { - pub text: Option, - pub portrait: Vec, - pub portrait_group: Vec, -} - -impl<'a> MessageRead<'a> for Biography { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(10) => msg.text = Some(r.read_string(bytes)?.to_owned()), - Ok(18) => msg.portrait.push(r.read_message::(bytes)?), - Ok(26) => msg.portrait_group.push(r.read_message::(bytes)?), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for Biography { - fn get_size(&self) -> usize { - 0 - + self.text.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - + self.portrait.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::() - + self.portrait_group.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::() - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.text { w.write_with_tag(10, |w| w.write_string(&**s))?; } - for s in &self.portrait { w.write_with_tag(18, |w| w.write_message(s))?; } - for s in &self.portrait_group { w.write_with_tag(26, |w| w.write_message(s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct Disc { - pub number: Option, - pub name: Option, - pub track: Vec, -} - -impl<'a> MessageRead<'a> for Disc { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(8) => msg.number = Some(r.read_sint32(bytes)?), - Ok(18) => msg.name = Some(r.read_string(bytes)?.to_owned()), - Ok(26) => msg.track.push(r.read_message::(bytes)?), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for Disc { - fn get_size(&self) -> usize { - 0 - + self.number.as_ref().map_or(0, |m| 1 + sizeof_sint32(*(m))) - + self.name.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - + self.track.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::() - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.number { w.write_with_tag(8, |w| w.write_sint32(*s))?; } - if let Some(ref s) = self.name { w.write_with_tag(18, |w| w.write_string(&**s))?; } - for s in &self.track { w.write_with_tag(26, |w| w.write_message(s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct Copyright { - pub typ: Option, - pub text: Option, -} - -impl<'a> MessageRead<'a> for Copyright { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(8) => msg.typ = Some(r.read_enum(bytes)?), - Ok(18) => msg.text = Some(r.read_string(bytes)?.to_owned()), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for Copyright { - fn get_size(&self) -> usize { - 0 - + self.typ.as_ref().map_or(0, |m| 1 + sizeof_varint(*(m) as u64)) - + self.text.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.typ { w.write_with_tag(8, |w| w.write_enum(*s as i32))?; } - if let Some(ref s) = self.text { w.write_with_tag(18, |w| w.write_string(&**s))?; } - Ok(()) - } -} - -pub mod mod_Copyright { - - -#[derive(Debug, PartialEq, Eq, Clone, Copy)] -pub enum Type { - P = 0, - C = 1, -} - -impl Default for Type { - fn default() -> Self { - Type::P - } -} - -impl From for Type { - fn from(i: i32) -> Self { - match i { - 0 => Type::P, - 1 => Type::C, - _ => Self::default(), - } - } -} - -impl<'a> From<&'a str> for Type { - fn from(s: &'a str) -> Self { - match s { - "P" => Type::P, - "C" => Type::C, - _ => Self::default(), - } - } -} - -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct Restriction { - pub catalogue: Vec, - pub countries_allowed: Option, - pub countries_forbidden: Option, - pub typ: Option, - pub catalogue_str: Vec, -} - -impl<'a> MessageRead<'a> for Restriction { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(8) => msg.catalogue.push(r.read_enum(bytes)?), - Ok(18) => msg.countries_allowed = Some(r.read_string(bytes)?.to_owned()), - Ok(26) => msg.countries_forbidden = Some(r.read_string(bytes)?.to_owned()), - Ok(32) => msg.typ = Some(r.read_enum(bytes)?), - Ok(42) => msg.catalogue_str.push(r.read_string(bytes)?.to_owned()), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for Restriction { - fn get_size(&self) -> usize { - 0 - + self.catalogue.iter().map(|s| 1 + sizeof_varint(*(s) as u64)).sum::() - + self.countries_allowed.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - + self.countries_forbidden.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - + self.typ.as_ref().map_or(0, |m| 1 + sizeof_varint(*(m) as u64)) - + self.catalogue_str.iter().map(|s| 1 + sizeof_len((s).len())).sum::() - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - for s in &self.catalogue { w.write_with_tag(8, |w| w.write_enum(*s as i32))?; } - if let Some(ref s) = self.countries_allowed { w.write_with_tag(18, |w| w.write_string(&**s))?; } - if let Some(ref s) = self.countries_forbidden { w.write_with_tag(26, |w| w.write_string(&**s))?; } - if let Some(ref s) = self.typ { w.write_with_tag(32, |w| w.write_enum(*s as i32))?; } - for s in &self.catalogue_str { w.write_with_tag(42, |w| w.write_string(&**s))?; } - Ok(()) - } -} - -pub mod mod_Restriction { - - -#[derive(Debug, PartialEq, Eq, Clone, Copy)] -pub enum Catalogue { - AD = 0, - SUBSCRIPTION = 1, - CATALOGUE_ALL = 2, - SHUFFLE = 3, - COMMERCIAL = 4, -} - -impl Default for Catalogue { - fn default() -> Self { - Catalogue::AD - } -} - -impl From for Catalogue { - fn from(i: i32) -> Self { - match i { - 0 => Catalogue::AD, - 1 => Catalogue::SUBSCRIPTION, - 2 => Catalogue::CATALOGUE_ALL, - 3 => Catalogue::SHUFFLE, - 4 => Catalogue::COMMERCIAL, - _ => Self::default(), - } - } -} - -impl<'a> From<&'a str> for Catalogue { - fn from(s: &'a str) -> Self { - match s { - "AD" => Catalogue::AD, - "SUBSCRIPTION" => Catalogue::SUBSCRIPTION, - "CATALOGUE_ALL" => Catalogue::CATALOGUE_ALL, - "SHUFFLE" => Catalogue::SHUFFLE, - "COMMERCIAL" => Catalogue::COMMERCIAL, - _ => Self::default(), - } - } -} - -#[derive(Debug, PartialEq, Eq, Clone, Copy)] -pub enum Type { - STREAMING = 0, -} - -impl Default for Type { - fn default() -> Self { - Type::STREAMING - } -} - -impl From for Type { - fn from(i: i32) -> Self { - match i { - 0 => Type::STREAMING, - _ => Self::default(), - } - } -} - -impl<'a> From<&'a str> for Type { - fn from(s: &'a str) -> Self { - match s { - "STREAMING" => Type::STREAMING, - _ => Self::default(), - } - } -} - -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct Availability { - pub catalogue_str: Vec, - pub start: Option, -} - -impl<'a> MessageRead<'a> for Availability { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(10) => msg.catalogue_str.push(r.read_string(bytes)?.to_owned()), - Ok(18) => msg.start = Some(r.read_message::(bytes)?), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for Availability { - fn get_size(&self) -> usize { - 0 - + self.catalogue_str.iter().map(|s| 1 + sizeof_len((s).len())).sum::() - + self.start.as_ref().map_or(0, |m| 1 + sizeof_len((m).get_size())) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - for s in &self.catalogue_str { w.write_with_tag(10, |w| w.write_string(&**s))?; } - if let Some(ref s) = self.start { w.write_with_tag(18, |w| w.write_message(s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct SalePeriod { - pub restriction: Vec, - pub start: Option, - pub end: Option, -} - -impl<'a> MessageRead<'a> for SalePeriod { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(10) => msg.restriction.push(r.read_message::(bytes)?), - Ok(18) => msg.start = Some(r.read_message::(bytes)?), - Ok(26) => msg.end = Some(r.read_message::(bytes)?), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for SalePeriod { - fn get_size(&self) -> usize { - 0 - + self.restriction.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::() - + self.start.as_ref().map_or(0, |m| 1 + sizeof_len((m).get_size())) - + self.end.as_ref().map_or(0, |m| 1 + sizeof_len((m).get_size())) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - for s in &self.restriction { w.write_with_tag(10, |w| w.write_message(s))?; } - if let Some(ref s) = self.start { w.write_with_tag(18, |w| w.write_message(s))?; } - if let Some(ref s) = self.end { w.write_with_tag(26, |w| w.write_message(s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct ExternalId { - pub typ: Option, - pub id: Option, -} - -impl<'a> MessageRead<'a> for ExternalId { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(10) => msg.typ = Some(r.read_string(bytes)?.to_owned()), - Ok(18) => msg.id = Some(r.read_string(bytes)?.to_owned()), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for ExternalId { - fn get_size(&self) -> usize { - 0 - + self.typ.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - + self.id.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.typ { w.write_with_tag(10, |w| w.write_string(&**s))?; } - if let Some(ref s) = self.id { w.write_with_tag(18, |w| w.write_string(&**s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct AudioFile { - pub file_id: Option>, - pub format: Option, -} - -impl<'a> MessageRead<'a> for AudioFile { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(10) => msg.file_id = Some(r.read_bytes(bytes)?.to_owned()), - Ok(16) => msg.format = Some(r.read_enum(bytes)?), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for AudioFile { - fn get_size(&self) -> usize { - 0 - + self.file_id.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - + self.format.as_ref().map_or(0, |m| 1 + sizeof_varint(*(m) as u64)) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.file_id { w.write_with_tag(10, |w| w.write_bytes(&**s))?; } - if let Some(ref s) = self.format { w.write_with_tag(16, |w| w.write_enum(*s as i32))?; } - Ok(()) - } -} - -pub mod mod_AudioFile { - - -#[derive(Debug, PartialEq, Eq, Clone, Copy)] -pub enum Format { - OGG_VORBIS_96 = 0, - OGG_VORBIS_160 = 1, - OGG_VORBIS_320 = 2, - MP3_256 = 3, - MP3_320 = 4, - MP3_160 = 5, - MP3_96 = 6, - MP3_160_ENC = 7, - MP4_128_DUAL = 8, - OTHER3 = 9, - AAC_160 = 10, - AAC_320 = 11, - MP4_128 = 12, - OTHER5 = 13, -} - -impl Default for Format { - fn default() -> Self { - Format::OGG_VORBIS_96 - } -} - -impl From for Format { - fn from(i: i32) -> Self { - match i { - 0 => Format::OGG_VORBIS_96, - 1 => Format::OGG_VORBIS_160, - 2 => Format::OGG_VORBIS_320, - 3 => Format::MP3_256, - 4 => Format::MP3_320, - 5 => Format::MP3_160, - 6 => Format::MP3_96, - 7 => Format::MP3_160_ENC, - 8 => Format::MP4_128_DUAL, - 9 => Format::OTHER3, - 10 => Format::AAC_160, - 11 => Format::AAC_320, - 12 => Format::MP4_128, - 13 => Format::OTHER5, - _ => Self::default(), - } - } -} - -impl<'a> From<&'a str> for Format { - fn from(s: &'a str) -> Self { - match s { - "OGG_VORBIS_96" => Format::OGG_VORBIS_96, - "OGG_VORBIS_160" => Format::OGG_VORBIS_160, - "OGG_VORBIS_320" => Format::OGG_VORBIS_320, - "MP3_256" => Format::MP3_256, - "MP3_320" => Format::MP3_320, - "MP3_160" => Format::MP3_160, - "MP3_96" => Format::MP3_96, - "MP3_160_ENC" => Format::MP3_160_ENC, - "MP4_128_DUAL" => Format::MP4_128_DUAL, - "OTHER3" => Format::OTHER3, - "AAC_160" => Format::AAC_160, - "AAC_320" => Format::AAC_320, - "MP4_128" => Format::MP4_128, - "OTHER5" => Format::OTHER5, - _ => Self::default(), - } - } -} - -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct VideoFile { - pub file_id: Option>, -} - -impl<'a> MessageRead<'a> for VideoFile { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(10) => msg.file_id = Some(r.read_bytes(bytes)?.to_owned()), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for VideoFile { - fn get_size(&self) -> usize { - 0 - + self.file_id.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.file_id { w.write_with_tag(10, |w| w.write_bytes(&**s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct Show { - pub gid: Option>, - pub name: Option, - pub description: Option, - pub deprecated_popularity: Option, - pub publisher: Option, - pub language: Option, - pub explicit: Option, - pub covers: Option, - pub episode: Vec, - pub copyright: Vec, - pub restriction: Vec, - pub keyword: Vec, - pub media_type: Option, - pub consumption_order: Option, - pub interpret_restriction_using_geoip: Option, - pub availability: Vec, - pub country_of_origin: Option, - pub categories: Vec, - pub passthrough: Option, -} - -impl<'a> MessageRead<'a> for Show { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(10) => msg.gid = Some(r.read_bytes(bytes)?.to_owned()), - Ok(18) => msg.name = Some(r.read_string(bytes)?.to_owned()), - Ok(514) => msg.description = Some(r.read_string(bytes)?.to_owned()), - Ok(520) => msg.deprecated_popularity = Some(r.read_sint32(bytes)?), - Ok(530) => msg.publisher = Some(r.read_string(bytes)?.to_owned()), - Ok(538) => msg.language = Some(r.read_string(bytes)?.to_owned()), - Ok(544) => msg.explicit = Some(r.read_bool(bytes)?), - Ok(554) => msg.covers = Some(r.read_message::(bytes)?), - Ok(562) => msg.episode.push(r.read_message::(bytes)?), - Ok(570) => msg.copyright.push(r.read_message::(bytes)?), - Ok(578) => msg.restriction.push(r.read_message::(bytes)?), - Ok(586) => msg.keyword.push(r.read_string(bytes)?.to_owned()), - Ok(592) => msg.media_type = Some(r.read_enum(bytes)?), - Ok(600) => msg.consumption_order = Some(r.read_enum(bytes)?), - Ok(608) => msg.interpret_restriction_using_geoip = Some(r.read_bool(bytes)?), - Ok(626) => msg.availability.push(r.read_message::(bytes)?), - Ok(634) => msg.country_of_origin = Some(r.read_string(bytes)?.to_owned()), - Ok(642) => msg.categories.push(r.read_message::(bytes)?), - Ok(648) => msg.passthrough = Some(r.read_enum(bytes)?), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for Show { - fn get_size(&self) -> usize { - 0 - + self.gid.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - + self.name.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - + self.description.as_ref().map_or(0, |m| 2 + sizeof_len((m).len())) - + self.deprecated_popularity.as_ref().map_or(0, |m| 2 + sizeof_sint32(*(m))) - + self.publisher.as_ref().map_or(0, |m| 2 + sizeof_len((m).len())) - + self.language.as_ref().map_or(0, |m| 2 + sizeof_len((m).len())) - + self.explicit.as_ref().map_or(0, |m| 2 + sizeof_varint(*(m) as u64)) - + self.covers.as_ref().map_or(0, |m| 2 + sizeof_len((m).get_size())) - + self.episode.iter().map(|s| 2 + sizeof_len((s).get_size())).sum::() - + self.copyright.iter().map(|s| 2 + sizeof_len((s).get_size())).sum::() - + self.restriction.iter().map(|s| 2 + sizeof_len((s).get_size())).sum::() - + self.keyword.iter().map(|s| 2 + sizeof_len((s).len())).sum::() - + self.media_type.as_ref().map_or(0, |m| 2 + sizeof_varint(*(m) as u64)) - + self.consumption_order.as_ref().map_or(0, |m| 2 + sizeof_varint(*(m) as u64)) - + self.interpret_restriction_using_geoip.as_ref().map_or(0, |m| 2 + sizeof_varint(*(m) as u64)) - + self.availability.iter().map(|s| 2 + sizeof_len((s).get_size())).sum::() - + self.country_of_origin.as_ref().map_or(0, |m| 2 + sizeof_len((m).len())) - + self.categories.iter().map(|s| 2 + sizeof_len((s).get_size())).sum::() - + self.passthrough.as_ref().map_or(0, |m| 2 + sizeof_varint(*(m) as u64)) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.gid { w.write_with_tag(10, |w| w.write_bytes(&**s))?; } - if let Some(ref s) = self.name { w.write_with_tag(18, |w| w.write_string(&**s))?; } - if let Some(ref s) = self.description { w.write_with_tag(514, |w| w.write_string(&**s))?; } - if let Some(ref s) = self.deprecated_popularity { w.write_with_tag(520, |w| w.write_sint32(*s))?; } - if let Some(ref s) = self.publisher { w.write_with_tag(530, |w| w.write_string(&**s))?; } - if let Some(ref s) = self.language { w.write_with_tag(538, |w| w.write_string(&**s))?; } - if let Some(ref s) = self.explicit { w.write_with_tag(544, |w| w.write_bool(*s))?; } - if let Some(ref s) = self.covers { w.write_with_tag(554, |w| w.write_message(s))?; } - for s in &self.episode { w.write_with_tag(562, |w| w.write_message(s))?; } - for s in &self.copyright { w.write_with_tag(570, |w| w.write_message(s))?; } - for s in &self.restriction { w.write_with_tag(578, |w| w.write_message(s))?; } - for s in &self.keyword { w.write_with_tag(586, |w| w.write_string(&**s))?; } - if let Some(ref s) = self.media_type { w.write_with_tag(592, |w| w.write_enum(*s as i32))?; } - if let Some(ref s) = self.consumption_order { w.write_with_tag(600, |w| w.write_enum(*s as i32))?; } - if let Some(ref s) = self.interpret_restriction_using_geoip { w.write_with_tag(608, |w| w.write_bool(*s))?; } - for s in &self.availability { w.write_with_tag(626, |w| w.write_message(s))?; } - if let Some(ref s) = self.country_of_origin { w.write_with_tag(634, |w| w.write_string(&**s))?; } - for s in &self.categories { w.write_with_tag(642, |w| w.write_message(s))?; } - if let Some(ref s) = self.passthrough { w.write_with_tag(648, |w| w.write_enum(*s as i32))?; } - Ok(()) - } -} - -pub mod mod_Show { - - -#[derive(Debug, PartialEq, Eq, Clone, Copy)] -pub enum MediaType { - MIXED = 0, - AUDIO = 1, - VIDEO = 2, -} - -impl Default for MediaType { - fn default() -> Self { - MediaType::MIXED - } -} - -impl From for MediaType { - fn from(i: i32) -> Self { - match i { - 0 => MediaType::MIXED, - 1 => MediaType::AUDIO, - 2 => MediaType::VIDEO, - _ => Self::default(), - } - } -} - -impl<'a> From<&'a str> for MediaType { - fn from(s: &'a str) -> Self { - match s { - "MIXED" => MediaType::MIXED, - "AUDIO" => MediaType::AUDIO, - "VIDEO" => MediaType::VIDEO, - _ => Self::default(), - } - } -} - -#[derive(Debug, PartialEq, Eq, Clone, Copy)] -pub enum ConsumptionOrder { - SEQUENTIAL = 1, - EPISODIC = 2, - RECENT = 3, -} - -impl Default for ConsumptionOrder { - fn default() -> Self { - ConsumptionOrder::SEQUENTIAL - } -} - -impl From for ConsumptionOrder { - fn from(i: i32) -> Self { - match i { - 1 => ConsumptionOrder::SEQUENTIAL, - 2 => ConsumptionOrder::EPISODIC, - 3 => ConsumptionOrder::RECENT, - _ => Self::default(), - } - } -} - -impl<'a> From<&'a str> for ConsumptionOrder { - fn from(s: &'a str) -> Self { - match s { - "SEQUENTIAL" => ConsumptionOrder::SEQUENTIAL, - "EPISODIC" => ConsumptionOrder::EPISODIC, - "RECENT" => ConsumptionOrder::RECENT, - _ => Self::default(), - } - } -} - -#[derive(Debug, PartialEq, Eq, Clone, Copy)] -pub enum PassthroughEnum { - UNKNOWN = 0, - NONE = 1, - ALLOWED = 2, -} - -impl Default for PassthroughEnum { - fn default() -> Self { - PassthroughEnum::UNKNOWN - } -} - -impl From for PassthroughEnum { - fn from(i: i32) -> Self { - match i { - 0 => PassthroughEnum::UNKNOWN, - 1 => PassthroughEnum::NONE, - 2 => PassthroughEnum::ALLOWED, - _ => Self::default(), - } - } -} - -impl<'a> From<&'a str> for PassthroughEnum { - fn from(s: &'a str) -> Self { - match s { - "UNKNOWN" => PassthroughEnum::UNKNOWN, - "NONE" => PassthroughEnum::NONE, - "ALLOWED" => PassthroughEnum::ALLOWED, - _ => Self::default(), - } - } -} - -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct Episode { - pub gid: Option>, - pub name: Option, - pub duration: Option, - pub popularity: Option, - pub file: Vec, - pub description: Option, - pub number: Option, - pub publish_time: Option, - pub deprecated_popularity: Option, - pub covers: Option, - pub language: Option, - pub explicit: Option, - pub show: Option, - pub video: Vec, - pub video_preview: Vec, - pub audio_preview: Vec, - pub restriction: Vec, - pub freeze_frame: Option, - pub keyword: Vec, - pub suppress_monetization: Option, - pub interpret_restriction_using_geoip: Option, - pub allow_background_playback: Option, - pub availability: Vec, - pub external_url: Option, - pub original_audio: Option, -} - -impl<'a> MessageRead<'a> for Episode { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(10) => msg.gid = Some(r.read_bytes(bytes)?.to_owned()), - Ok(18) => msg.name = Some(r.read_string(bytes)?.to_owned()), - Ok(56) => msg.duration = Some(r.read_sint32(bytes)?), - Ok(64) => msg.popularity = Some(r.read_sint32(bytes)?), - Ok(98) => msg.file.push(r.read_message::(bytes)?), - Ok(514) => msg.description = Some(r.read_string(bytes)?.to_owned()), - Ok(520) => msg.number = Some(r.read_sint32(bytes)?), - Ok(530) => msg.publish_time = Some(r.read_message::(bytes)?), - Ok(536) => msg.deprecated_popularity = Some(r.read_sint32(bytes)?), - Ok(546) => msg.covers = Some(r.read_message::(bytes)?), - Ok(554) => msg.language = Some(r.read_string(bytes)?.to_owned()), - Ok(560) => msg.explicit = Some(r.read_bool(bytes)?), - Ok(570) => msg.show = Some(r.read_message::(bytes)?), - Ok(578) => msg.video.push(r.read_message::(bytes)?), - Ok(586) => msg.video_preview.push(r.read_message::(bytes)?), - Ok(594) => msg.audio_preview.push(r.read_message::(bytes)?), - Ok(602) => msg.restriction.push(r.read_message::(bytes)?), - Ok(610) => msg.freeze_frame = Some(r.read_message::(bytes)?), - Ok(618) => msg.keyword.push(r.read_string(bytes)?.to_owned()), - Ok(624) => msg.suppress_monetization = Some(r.read_bool(bytes)?), - Ok(632) => msg.interpret_restriction_using_geoip = Some(r.read_bool(bytes)?), - Ok(648) => msg.allow_background_playback = Some(r.read_bool(bytes)?), - Ok(658) => msg.availability.push(r.read_message::(bytes)?), - Ok(666) => msg.external_url = Some(r.read_string(bytes)?.to_owned()), - Ok(674) => msg.original_audio = Some(r.read_message::(bytes)?), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for Episode { - fn get_size(&self) -> usize { - 0 - + self.gid.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - + self.name.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - + self.duration.as_ref().map_or(0, |m| 1 + sizeof_sint32(*(m))) - + self.popularity.as_ref().map_or(0, |m| 1 + sizeof_sint32(*(m))) - + self.file.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::() - + self.description.as_ref().map_or(0, |m| 2 + sizeof_len((m).len())) - + self.number.as_ref().map_or(0, |m| 2 + sizeof_sint32(*(m))) - + self.publish_time.as_ref().map_or(0, |m| 2 + sizeof_len((m).get_size())) - + self.deprecated_popularity.as_ref().map_or(0, |m| 2 + sizeof_sint32(*(m))) - + self.covers.as_ref().map_or(0, |m| 2 + sizeof_len((m).get_size())) - + self.language.as_ref().map_or(0, |m| 2 + sizeof_len((m).len())) - + self.explicit.as_ref().map_or(0, |m| 2 + sizeof_varint(*(m) as u64)) - + self.show.as_ref().map_or(0, |m| 2 + sizeof_len((m).get_size())) - + self.video.iter().map(|s| 2 + sizeof_len((s).get_size())).sum::() - + self.video_preview.iter().map(|s| 2 + sizeof_len((s).get_size())).sum::() - + self.audio_preview.iter().map(|s| 2 + sizeof_len((s).get_size())).sum::() - + self.restriction.iter().map(|s| 2 + sizeof_len((s).get_size())).sum::() - + self.freeze_frame.as_ref().map_or(0, |m| 2 + sizeof_len((m).get_size())) - + self.keyword.iter().map(|s| 2 + sizeof_len((s).len())).sum::() - + self.suppress_monetization.as_ref().map_or(0, |m| 2 + sizeof_varint(*(m) as u64)) - + self.interpret_restriction_using_geoip.as_ref().map_or(0, |m| 2 + sizeof_varint(*(m) as u64)) - + self.allow_background_playback.as_ref().map_or(0, |m| 2 + sizeof_varint(*(m) as u64)) - + self.availability.iter().map(|s| 2 + sizeof_len((s).get_size())).sum::() - + self.external_url.as_ref().map_or(0, |m| 2 + sizeof_len((m).len())) - + self.original_audio.as_ref().map_or(0, |m| 2 + sizeof_len((m).get_size())) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.gid { w.write_with_tag(10, |w| w.write_bytes(&**s))?; } - if let Some(ref s) = self.name { w.write_with_tag(18, |w| w.write_string(&**s))?; } - if let Some(ref s) = self.duration { w.write_with_tag(56, |w| w.write_sint32(*s))?; } - if let Some(ref s) = self.popularity { w.write_with_tag(64, |w| w.write_sint32(*s))?; } - for s in &self.file { w.write_with_tag(98, |w| w.write_message(s))?; } - if let Some(ref s) = self.description { w.write_with_tag(514, |w| w.write_string(&**s))?; } - if let Some(ref s) = self.number { w.write_with_tag(520, |w| w.write_sint32(*s))?; } - if let Some(ref s) = self.publish_time { w.write_with_tag(530, |w| w.write_message(s))?; } - if let Some(ref s) = self.deprecated_popularity { w.write_with_tag(536, |w| w.write_sint32(*s))?; } - if let Some(ref s) = self.covers { w.write_with_tag(546, |w| w.write_message(s))?; } - if let Some(ref s) = self.language { w.write_with_tag(554, |w| w.write_string(&**s))?; } - if let Some(ref s) = self.explicit { w.write_with_tag(560, |w| w.write_bool(*s))?; } - if let Some(ref s) = self.show { w.write_with_tag(570, |w| w.write_message(s))?; } - for s in &self.video { w.write_with_tag(578, |w| w.write_message(s))?; } - for s in &self.video_preview { w.write_with_tag(586, |w| w.write_message(s))?; } - for s in &self.audio_preview { w.write_with_tag(594, |w| w.write_message(s))?; } - for s in &self.restriction { w.write_with_tag(602, |w| w.write_message(s))?; } - if let Some(ref s) = self.freeze_frame { w.write_with_tag(610, |w| w.write_message(s))?; } - for s in &self.keyword { w.write_with_tag(618, |w| w.write_string(&**s))?; } - if let Some(ref s) = self.suppress_monetization { w.write_with_tag(624, |w| w.write_bool(*s))?; } - if let Some(ref s) = self.interpret_restriction_using_geoip { w.write_with_tag(632, |w| w.write_bool(*s))?; } - if let Some(ref s) = self.allow_background_playback { w.write_with_tag(648, |w| w.write_bool(*s))?; } - for s in &self.availability { w.write_with_tag(658, |w| w.write_message(s))?; } - if let Some(ref s) = self.external_url { w.write_with_tag(666, |w| w.write_string(&**s))?; } - if let Some(ref s) = self.original_audio { w.write_with_tag(674, |w| w.write_message(s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct Category { - pub name: Option, - pub subcategories: Vec, -} - -impl<'a> MessageRead<'a> for Category { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(10) => msg.name = Some(r.read_string(bytes)?.to_owned()), - Ok(18) => msg.subcategories.push(r.read_message::(bytes)?), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for Category { - fn get_size(&self) -> usize { - 0 - + self.name.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - + self.subcategories.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::() - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.name { w.write_with_tag(10, |w| w.write_string(&**s))?; } - for s in &self.subcategories { w.write_with_tag(18, |w| w.write_message(s))?; } - Ok(()) - } -} - -#[derive(Debug, Default, PartialEq, Clone)] -pub struct OriginalAudio { - pub uuid: Option>, -} - -impl<'a> MessageRead<'a> for OriginalAudio { - fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result { - let mut msg = Self::default(); - while !r.is_eof() { - match r.next_tag(bytes) { - Ok(10) => msg.uuid = Some(r.read_bytes(bytes)?.to_owned()), - Ok(t) => { r.read_unknown(bytes, t)?; } - Err(e) => return Err(e), - } - } - Ok(msg) - } -} - -impl MessageWrite for OriginalAudio { - fn get_size(&self) -> usize { - 0 - + self.uuid.as_ref().map_or(0, |m| 1 + sizeof_len((m).len())) - } - - fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.uuid { w.write_with_tag(10, |w| w.write_bytes(&**s))?; } - Ok(()) - } -} -