diff --git a/src/bc/de.rs b/src/bc/de.rs index 33bdc48..24ba5d0 100644 --- a/src/bc/de.rs +++ b/src/bc/de.rs @@ -3,7 +3,7 @@ use nom::IResult; use nom::{bytes::streaming::take, number::streaming::*, combinator::*, sequence::*}; use std::io::Read; use super::model::*; -use super::xml::Body; +use super::xml::BcXml; use super::xml_crypto; #[derive(Debug, Error)] @@ -132,7 +132,7 @@ fn bc_modern_msg<'a, 'b>(header: &'a BcHeader, buf: &'b [u8]) // thing is the same idiom Nom uses internally. use nom::{Err, error::{make_error, ErrorKind}}; let xml = if end_of_xml > 0 { - let parsed = Body::try_parse(processed_body_buf) + let parsed = BcXml::try_parse(processed_body_buf) .map_err(|_| Err::Error(make_error(buf, ErrorKind::MapRes)))?; Some(parsed) } else { None }; diff --git a/src/bc/model.rs b/src/bc/model.rs index b579893..bbe2708 100644 --- a/src/bc/model.rs +++ b/src/bc/model.rs @@ -1,4 +1,4 @@ -use super::xml::Body; +use super::xml::BcXml; pub(super) const MAGIC_HEADER: u32 = 0xabcdef0; @@ -21,7 +21,7 @@ pub enum BcBody { #[derive(Debug, Default, PartialEq, Eq)] pub struct ModernMsg { - pub xml: Option, + pub xml: Option, pub binary: Option>, } diff --git a/src/bc/ser.rs b/src/bc/ser.rs index 21a6549..2c1bc62 100644 --- a/src/bc/ser.rs +++ b/src/bc/ser.rs @@ -4,7 +4,7 @@ use cookie_factory::sequence::tuple; use cookie_factory::{GenError, SerializeFn, WriteContext}; use std::io::Write; use super::model::*; -use super::xml::Body; +use super::xml::BcXml; use super::xml_crypto; pub type Error = GenError; @@ -50,7 +50,7 @@ impl Bc { } } -fn bc_xml(enc_offset: u32, xml: &Body) -> impl SerializeFn +fn bc_xml(enc_offset: u32, xml: &BcXml) -> impl SerializeFn { let xml_bytes = xml.serialize(vec!()).unwrap(); let enc_bytes = xml_crypto::crypt(enc_offset, &xml_bytes); diff --git a/src/bc/xml.rs b/src/bc/xml.rs index 15b8fbf..051d4fb 100644 --- a/src/bc/xml.rs +++ b/src/bc/xml.rs @@ -14,7 +14,7 @@ use indoc::indoc; #[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)] #[yaserde(rename="body")] -pub struct Body { +pub struct BcXml { #[yaserde(rename="Encryption")] pub encryption: Option, #[yaserde(rename="LoginUser")] @@ -25,7 +25,7 @@ pub struct Body { pub device_info: Option, } -impl Body { +impl BcXml { pub fn try_parse(s: impl Read) -> Result { yaserde::de::from_reader(s) } @@ -102,7 +102,7 @@ fn test_encryption_deser() { 9E6D1FCB9E69846D "#); - let b: Body = yaserde::de::from_str(sample).unwrap(); + let b: BcXml = yaserde::de::from_str(sample).unwrap(); let enc = b.encryption.unwrap(); assert_eq!(enc.version, "1.1"); @@ -125,7 +125,7 @@ fn test_login_deser() { 0 "#); - let b: Body = yaserde::de::from_str(sample).unwrap(); + let b: BcXml = yaserde::de::from_str(sample).unwrap(); let login_user = b.login_user.unwrap(); let login_net = b.login_net.unwrap(); @@ -155,7 +155,7 @@ fn test_login_ser() { "#); - let b = Body { + let b = BcXml { login_user: Some(LoginUser { version: "1.1".to_string(), user_name: "9F07915E819A076E2E14169830769D6".to_string(), @@ -167,11 +167,11 @@ fn test_login_ser() { type_: "LAN".to_string(), udp_port: 0, }), - ..Body::default() + ..BcXml::default() }; - let b2 = Body::try_parse(sample.as_bytes()).unwrap(); - let b3 = Body::try_parse(b.serialize(vec!()).unwrap().as_slice()).unwrap(); + let b2 = BcXml::try_parse(sample.as_bytes()).unwrap(); + let b3 = BcXml::try_parse(b.serialize(vec!()).unwrap().as_slice()).unwrap(); assert_eq!(b, b2); assert_eq!(b, b3); @@ -203,10 +203,10 @@ fn test_deviceinfo_partial_deser() { "#); // Needs to ignore all the other crap that we don't care about - let b = Body::try_parse(sample.as_bytes()).unwrap(); + let b = BcXml::try_parse(sample.as_bytes()).unwrap(); println!("{:?}", b); match b { - Body { + BcXml { device_info: Some(DeviceInfo { resolution: Resolution { width: 3840, diff --git a/src/bc_protocol.rs b/src/bc_protocol.rs index 4f7c0cf..fa34f0a 100644 --- a/src/bc_protocol.rs +++ b/src/bc_protocol.rs @@ -103,7 +103,7 @@ impl BcCamera { let nonce; match legacy_reply.body { BcBody::ModernMsg(ModernMsg { - xml: Some(Body { encryption: Some(encryption), .. }), .. + xml: Some(BcXml { encryption: Some(encryption), .. }), .. }) => { nonce = encryption.nonce; } @@ -135,7 +135,7 @@ impl BcCamera { class: 0x6414, }, body: BcBody::ModernMsg(ModernMsg { - xml: Some(Body { + xml: Some(BcXml { login_user: Some(LoginUser { version: xml_ver(), user_name: md5_username, @@ -155,7 +155,7 @@ impl BcCamera { let device_info; match modern_reply.body { BcBody::ModernMsg(ModernMsg { - xml: Some(Body { device_info: Some(info), .. }), .. + xml: Some(BcXml { device_info: Some(info), .. }), .. }) => { // Login succeeded! self.logged_in = true;