mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-19 23:07:33 +09:00
Dactyloidae iOS initial commit
This commit is contained in:
parent
daa6179d22
commit
7154a0497e
2123 changed files with 197052 additions and 0 deletions
55
mobile/ios/Sync/KeysPayload.swift
Normal file
55
mobile/ios/Sync/KeysPayload.swift
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import Foundation
|
||||
import Shared
|
||||
import SwiftyJSON
|
||||
|
||||
open class KeysPayload: CleartextPayloadJSON {
|
||||
override open func isValid() -> Bool {
|
||||
return super.isValid() &&
|
||||
self["default"].isArray()
|
||||
}
|
||||
|
||||
fileprivate func keyBundleFromPair(_ input: JSON) -> KeyBundle? {
|
||||
if let pair: [JSON] = input.array {
|
||||
if let encKey = pair[0].string {
|
||||
if let hmacKey = pair[1].string {
|
||||
return KeyBundle(encKeyB64: encKey, hmacKeyB64: hmacKey)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var defaultKeys: KeyBundle? {
|
||||
return self.keyBundleFromPair(self["default"])
|
||||
}
|
||||
|
||||
var collectionKeys: [String: KeyBundle] {
|
||||
if let collections: [String: JSON] = self["collections"].dictionary {
|
||||
return optFilter(mapValues(collections, f: self.keyBundleFromPair))
|
||||
}
|
||||
return [:]
|
||||
}
|
||||
|
||||
override open func equalPayloads(_ obj: CleartextPayloadJSON) -> Bool {
|
||||
if !(obj is KeysPayload) {
|
||||
return false
|
||||
}
|
||||
|
||||
if !super.equalPayloads(obj) {
|
||||
return false
|
||||
}
|
||||
|
||||
let p = obj as! KeysPayload
|
||||
if p.defaultKeys != self.defaultKeys {
|
||||
return false
|
||||
}
|
||||
|
||||
// TODO: check collections.
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue