Modern Apps git

xtool.git

Public
git clone https://git.maproj.org/xtool.git
main ▾

xtool.git / Sources / XKit / GrandSlam / Anisette / AnisetteData.swift

AnisetteData.swift74 lines · 2.3 KiBRaw
1//
2// AnisetteData.swift
3// XKit
4//
5// Created by Kabir Oberai on 19/11/19.
6// Copyright © 2019 Kabir Oberai. All rights reserved.
7//
8
9import Foundation
10
11public struct AnisetteData {
12
13 private static let dateFormatter: DateFormatter = {
14 let dateFormatter = DateFormatter()
15 dateFormatter.locale = Locale(identifier: "en_US_POSIX")
16 dateFormatter.calendar = Calendar(identifier: .gregorian)
17 dateFormatter.timeZone = TimeZone(abbreviation: "UTC")
18 dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'"
19 return dateFormatter
20 }()
21
22 /// `X-Apple-I-Locale`
23 static let iLocaleKey = "X-Apple-I-Locale"
24 /// `X-Apple-Locale`
25 static let localeKey = "X-Apple-Locale"
26 public let locale: Locale = .current
27
28 /// `X-Apple-I-TimeZone`
29 static let timeZoneKey = "X-Apple-I-TimeZone"
30 public let timeZone: TimeZone = .current
31
32 /// `X-Apple-I-Client-Time`
33 static let clientTimeKey = "X-Apple-I-Client-Time"
34 public let clientTime: Date
35
36 /// `X-Apple-I-MD-RINFO`
37 static let routingInfoKey = "X-Apple-I-MD-RINFO"
38 public let routingInfo: UInt64
39
40 /// `X-Apple-I-MD-M`
41 static let machineIDKey = "X-Apple-I-MD-M"
42 public let machineID: String
43
44 /// `X-Apple-I-MD-LU`
45 static let localUserIDKey = "X-Apple-I-MD-LU"
46 public let localUserID: String
47
48 /// `X-Apple-I-MD`
49 static let oneTimePasswordKey = "X-Apple-I-MD"
50 public let oneTimePassword: String
51
52 public let deviceInfo: DeviceInfo
53
54 public var dictionary: [String: String] {
55 // GSA doesn't like "en_US@rg=..."; it has to be just "en_US".
56 let localeIdentifier = if let language = locale.language.languageCode?.identifier,
57 let region = locale.region?.identifier {
58 "\(language)_\(region)"
59 } else {
60 "en_US"
61 }
62 return [
63 Self.localeKey: localeIdentifier,
64 Self.timeZoneKey: timeZone.abbreviation() ?? "UTC",
65 Self.clientTimeKey: Self.dateFormatter.string(from: clientTime),
66 Self.routingInfoKey: "\(routingInfo)",
67 Self.machineIDKey: machineID,
68 Self.localUserIDKey: localUserID,
69 Self.oneTimePasswordKey: oneTimePassword,
70 ]
71 .merging(deviceInfo.dictionary) { _, b in b }
72 }
73
74}