Bc: xml: rename from Body
This commit is contained in:
1 parent
7b10c32a99
commit
09d4488166
5 files changed
+19
-19
No files matched your search
+2
-2
@@ -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 };
|
||||
|
||||
+2
-2
@@ -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<Body>,
|
||||
pub xml: Option<BcXml>,
|
||||
pub binary: Option<Vec<u8>>,
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -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<W: Write>(enc_offset: u32, xml: &Body) -> impl SerializeFn<W>
|
||||
fn bc_xml<W: Write>(enc_offset: u32, xml: &BcXml) -> impl SerializeFn<W>
|
||||
{
|
||||
let xml_bytes = xml.serialize(vec!()).unwrap();
|
||||
let enc_bytes = xml_crypto::crypt(enc_offset, &xml_bytes);
|
||||
|
||||
+10
-10
@@ -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<Encryption>,
|
||||
#[yaserde(rename="LoginUser")]
|
||||
@@ -25,7 +25,7 @@ pub struct Body {
|
||||
pub device_info: Option<DeviceInfo>,
|
||||
}
|
||||
|
||||
impl Body {
|
||||
impl BcXml {
|
||||
pub fn try_parse(s: impl Read) -> Result<Self, String> {
|
||||
yaserde::de::from_reader(s)
|
||||
}
|
||||
@@ -102,7 +102,7 @@ fn test_encryption_deser() {
|
||||
<nonce>9E6D1FCB9E69846D</nonce>
|
||||
</Encryption>
|
||||
</body>"#);
|
||||
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() {
|
||||
<udpPort>0</udpPort>
|
||||
</LoginNet>
|
||||
</body>"#);
|
||||
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() {
|
||||
</LoginNet>
|
||||
</body>"#);
|
||||
|
||||
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() {
|
||||
</body>"#);
|
||||
|
||||
// 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,
|
||||
|
||||
+3
-3
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user