1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
//! Apple Associated Domains semantics for Rust and WebAssembly.
//!
//! `blazingly-aasa` parses, validates, matches, explains, and compares `apple-app-site-association`
//! files. It is a semantic engine, not a fetcher: it never touches the network, never opens an
//! `.ipa`, and never claims to know what a device will do. Give it bytes and explicit context, and
//! it tells you exactly what the document says.
//!
//! # Three separate questions
//!
//! 1. **Is this parseable?** [`AasaDocument::parse`] fails only on invalid JSON, a non-object root,
//! or an oversized payload.
//! 2. **Is this sane?** [`CompiledAasa::validate`] returns a [`ValidationReport`] of stable,
//! machine-readable [`DiagnosticCode`]s rather than a single yes/no.
//! 3. **Does this URL match?** [`CompiledAasa::match_url`] returns [`MatchDecision::Match`],
//! [`MatchDecision::Exclude`], or [`MatchDecision::NoMatch`] — with a trace explaining why.
//!
//! A URL that does not match is not an error, and neither is one that is excluded. Both are
//! answers.
//!
//! # Matching a URL
//!
//! ```
//! use blazingly_aasa::{CompiledAasa, MatchDecision};
//!
//! let bytes = br#"{
//! "applinks": {
//! "details": [{
//! "appIDs": ["ABCDE12345.com.example.app"],
//! "components": [
//! { "/": "/help/website/*", "exclude": true },
//! { "/": "/help/*", "?": { "articleNumber": "????" } }
//! ]
//! }]
//! }
//! }"#;
//!
//! let aasa = CompiledAasa::parse(bytes)?;
//! let app = "ABCDE12345.com.example.app";
//!
//! let hit = aasa.match_url("example.com", app, "https://example.com/help/1?articleNumber=4815")?;
//! assert_eq!(hit.decision, MatchDecision::Match);
//!
//! let blocked = aasa.match_url("example.com", app, "https://example.com/help/website/faq")?;
//! assert_eq!(blocked.decision, MatchDecision::Exclude);
//!
//! // Three characters, not four: the query predicate rejects it.
//! let miss = aasa.match_url("example.com", app, "https://example.com/help/1?articleNumber=481")?;
//! assert_eq!(miss.decision, MatchDecision::NoMatch);
//! # Ok::<(), blazingly_aasa::Error>(())
//! ```
//!
//! # Explaining a decision
//!
//! Every result formats itself into something you can paste into a bug report:
//!
//! ```
//! # use blazingly_aasa::CompiledAasa;
//! # let bytes = br#"{"applinks":{"details":[{"appIDs":["A.b"],"components":[{"/":"/buy/*"}]}]}}"#;
//! # let aasa = CompiledAasa::parse(bytes)?;
//! let result = aasa.match_url("example.com", "A.b", "https://example.com/sell/42")?;
//! println!("{result}");
//! # Ok::<(), blazingly_aasa::Error>(())
//! ```
//!
//! # Comparing two files
//!
//! [`CompiledAasa::semantic_diff`] compares behaviour rather than text, so moving
//! `caseSensitive` from every component up into `defaults` reports no change, while reordering two
//! rules does:
//!
//! ```
//! use blazingly_aasa::CompiledAasa;
//!
//! let spelled_out = CompiledAasa::parse(br#"{"applinks":{"details":[{
//! "appIDs": ["A.b"],
//! "components": [{ "/": "/buy/*", "caseSensitive": false }]
//! }]}}"#)?;
//!
//! let refactored = CompiledAasa::parse(br#"{"applinks":{"details":[{
//! "appIDs": ["A.b"],
//! "defaults": { "caseSensitive": false },
//! "components": [{ "/": "/buy/*" }]
//! }]}}"#)?;
//!
//! assert!(spelled_out.semantic_diff(&refactored).is_equivalent());
//! assert!(!spelled_out.structural_equal(&refactored));
//! # Ok::<(), blazingly_aasa::Error>(())
//! ```
//!
//! # What this crate will not do
//!
//! It does not fetch `.well-known/apple-app-site-association`, talk to Apple's CDN, read
//! entitlements out of a signed binary, or model device state. Those belong in the tools that use
//! this crate. See `docs/parity.md` for the behaviours that are verified against Apple's
//! documentation and the ones that are still open questions.
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ParseOptions;
pub use ;
pub use ;
/// The Foundation release the `$(region)` and `$(lang)` tables were generated from.
///
/// Apple defines those variables as `Locale.isoRegionCodes` and `Locale.isoLanguageCodes`, which
/// change between OS releases. Knowing which snapshot you are matching against matters.
pub const ISO_TABLE_SOURCE: &str = ISO_TABLE_SOURCE;
/// Splits `ABCDE12345.com.example.app` into its application identifier prefix and bundle
/// identifier.
///
/// Apple documents the form as `<Application Identifier Prefix>.<Bundle Identifier>`, and the
/// prefix never contains a dot, so the split is at the first one. Returns `None` when there is no
/// dot, or when either half would be empty.
///
/// ```
/// assert_eq!(
/// blazingly_aasa::split_app_id("ABCDE12345.com.example.app"),
/// Some(("ABCDE12345", "com.example.app")),
/// );
/// assert_eq!(blazingly_aasa::split_app_id("nodots"), None);
/// ```
/// Parses and validates in one call.
///
/// # Errors
///
/// Returns [`ParseError`] for invalid JSON, a non-object root, or an oversized payload.
/// Parses and matches in one call.
///
/// Prefer [`CompiledAasa::match_url`] when testing more than one URL against the same document:
/// this helper reparses and recompiles every time.
///
/// # Errors
///
/// Returns [`Error::Parse`] for an unusable document and [`Error::Url`] for an unusable URL.
/// Parses both documents and compares them semantically.
///
/// # Errors
///
/// Returns [`ParseError`] when either payload is unusable.