Git · dadoum.zone
Repositories
Help
Report an Issue
apple-crates
Code
Commits
Branches
Tags
Search
Tree:
a74924e
Branches
Tags
main
apple-crates
sharing
src
person.rs
Refactor and unify a lot of things for another project and implement airdrop support
Dadoum
commited
a74924e
at 2026-10-25 22:15:58
person.rs
Blame
History
Raw
//! `lookupPersonHandles` and `findPerson`: resolving Apple ID handles (email //! addresses, phone numbers) to account identifiers. //! //! `lookupPersonHandles` is pinned down by a capture of macOS sharingd: the body //! lists `emails` and `phones` (phones as digits with the country code, no `+`), //! and the reply has one `lookupResults` entry per handle, with the handle's //! `altDsId` or `null` when it is not an Apple Account. `findPerson` has not been //! captured yet, so its reply stays raw JSON. use serde::{Deserialize, Serialize}; use crate::impl_sharing_request; #[derive(Debug, Serialize)] pub struct FindPerson { pub handle: String, } impl_sharing_request!(FindPerson, "findPerson", serde_json::Value); #[derive(Debug, Default, Serialize)] pub struct LookupPersonHandles { pub emails: Vec<String>, pub phones: Vec<String>, } #[derive(Debug, Deserialize)] pub struct LookupPersonHandlesResponse { #[serde(rename = "lookupResults", default)] pub lookup_results: Vec<LookupResult>, /// Milliseconds before the same lookup should be repeated. #[serde(rename = "nextSuggestedAttemptDelay")] pub next_suggested_attempt_delay: Option<u64>, } #[derive(Debug, Deserialize)] pub struct LookupResult { pub handle: String, #[serde(rename = "altDsId")] pub alt_dsid: Option<String>, } impl_sharing_request!( LookupPersonHandles, "lookupPersonHandles", LookupPersonHandlesResponse ); #[cfg(test)] mod tests { use super::*; #[test] fn request_and_reply_match_the_captured_shape() { let request = LookupPersonHandles { emails: vec!["someone@example.invalid".into()], phones: vec!["15550100".into()], }; assert_eq!( serde_json::to_string(&request).unwrap(), r#"{"emails":["someone@example.invalid"],"phones":["15550100"]}"# ); let reply: LookupPersonHandlesResponse = serde_json::from_str( r#"{"responseCode":0,"responseMessage":null,"nextSuggestedAttemptDelay":15631, "lookupResults":[{"handle":"a@example.invalid","altDsId":"000000-00-x"}, {"handle":"15550100","altDsId":null}]}"#, ) .unwrap(); assert_eq!(reply.lookup_results.len(), 2); assert_eq!( reply.lookup_results[0].alt_dsid.as_deref(), Some("000000-00-x") ); assert_eq!(reply.lookup_results[1].alt_dsid, None); assert_eq!(reply.next_suggested_attempt_delay, Some(15631)); } }