From 2c78f79c38e9fdd4cbd30f8fbeb7c9fb8c3c5e68 Mon Sep 17 00:00:00 2001 From: Jackson Coxson Date: Thu, 9 Jan 2025 18:13:45 -0800 Subject: [PATCH] Add from_bytes method for PairingFile --- src/pairing_file.rs | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/src/pairing_file.rs b/src/pairing_file.rs index 743fecd..27390eb 100644 --- a/src/pairing_file.rs +++ b/src/pairing_file.rs @@ -44,14 +44,19 @@ struct RawPairingFile { impl PairingFile { pub fn read_from_file(path: impl AsRef) -> Result { - let f = std::fs::read_to_string(path)?; - let r = match plist::from_bytes::(f.as_bytes()) { + let f = std::fs::read(path)?; + Self::from_bytes(&f) + } + + pub fn from_bytes(bytes: &[u8]) -> Result { + let r = match ::plist::from_bytes::(bytes) { Ok(r) => r, Err(e) => { - warn!("Unable to read raw pairing file to memory: {e:?}"); + warn!("Unable to convert bytes to raw pairing file: {e:?}"); return Err(crate::IdeviceError::UnexpectedResponse); } }; + match r.try_into() { Ok(r) => Ok(r), Err(e) => { @@ -84,20 +89,3 @@ impl TryFrom for PairingFile { }) } } - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn f1() { - let f = std::fs::read_to_string( - "/Users/jacksoncoxson/Documents/00008140-0016243626F3001C.mobiledevicepairing", - ) - .unwrap(); - let p: plist::Dictionary = plist::from_bytes(f.as_bytes()).unwrap(); - println!("{p:#?}"); - let p: RawPairingFile = plist::from_bytes(f.as_bytes()).unwrap(); - println!("{p:#?}"); - } -}