mirror of https://github.com/oxen-io/session-ios
Start integrating LokiDeviceLinkingSession
parent
d5d6d65b5c
commit
da2d18f0fc
@ -1,75 +1,75 @@
|
||||
|
||||
@objc(LKDeviceLink)
|
||||
public final class LokiDeviceLink : NSObject, NSCoding {
|
||||
public let master: Device
|
||||
public let slave: Device
|
||||
@objc public let master: Device
|
||||
@objc public let slave: Device
|
||||
|
||||
public var isAuthorized: Bool { return master.signature != nil }
|
||||
@objc public var isAuthorized: Bool { return master.signature != nil }
|
||||
|
||||
// MARK: Types
|
||||
@objc(LKDevice)
|
||||
public final class Device : NSObject, NSCoding {
|
||||
public let hexEncodedPublicKey: String
|
||||
public let signature: Data?
|
||||
@objc public let hexEncodedPublicKey: String
|
||||
@objc public let signature: Data?
|
||||
|
||||
public init(hexEncodedPublicKey: String, signature: Data? = nil) {
|
||||
@objc public init(hexEncodedPublicKey: String, signature: Data? = nil) {
|
||||
self.hexEncodedPublicKey = hexEncodedPublicKey
|
||||
self.signature = signature
|
||||
}
|
||||
|
||||
public init?(coder: NSCoder) {
|
||||
@objc public init?(coder: NSCoder) {
|
||||
hexEncodedPublicKey = coder.decodeObject(forKey: "hexEncodedPublicKey") as! String
|
||||
signature = coder.decodeObject(forKey: "signature") as! Data?
|
||||
}
|
||||
|
||||
public func encode(with coder: NSCoder) {
|
||||
@objc public func encode(with coder: NSCoder) {
|
||||
coder.encode(hexEncodedPublicKey, forKey: "hexEncodedPublicKey")
|
||||
if let signature = signature { coder.encode(signature, forKey: "signature") }
|
||||
}
|
||||
|
||||
public override func isEqual(_ other: Any?) -> Bool {
|
||||
@objc public override func isEqual(_ other: Any?) -> Bool {
|
||||
guard let other = other as? Device else { return false }
|
||||
return hexEncodedPublicKey == other.hexEncodedPublicKey && signature == other.signature
|
||||
}
|
||||
|
||||
override public var hash: Int { // Override NSObject.hash and not Hashable.hashValue or Hashable.hash(into:)
|
||||
@objc override public var hash: Int { // Override NSObject.hash and not Hashable.hashValue or Hashable.hash(into:)
|
||||
var result = hexEncodedPublicKey.hashValue
|
||||
if let signature = signature { result = result ^ signature.hashValue }
|
||||
return result
|
||||
}
|
||||
|
||||
override public var description: String { return hexEncodedPublicKey }
|
||||
@objc override public var description: String { return hexEncodedPublicKey }
|
||||
}
|
||||
|
||||
// MARK: Lifecycle
|
||||
public init(between master: Device, and slave: Device) {
|
||||
@objc public init(between master: Device, and slave: Device) {
|
||||
self.master = master
|
||||
self.slave = slave
|
||||
}
|
||||
|
||||
// MARK: Coding
|
||||
public init?(coder: NSCoder) {
|
||||
@objc public init?(coder: NSCoder) {
|
||||
master = coder.decodeObject(forKey: "master") as! Device
|
||||
slave = coder.decodeObject(forKey: "slave") as! Device
|
||||
super.init()
|
||||
}
|
||||
|
||||
public func encode(with coder: NSCoder) {
|
||||
@objc public func encode(with coder: NSCoder) {
|
||||
coder.encode(master, forKey: "master")
|
||||
coder.encode(slave, forKey: "slave")
|
||||
}
|
||||
|
||||
// MARK: Equality
|
||||
override public func isEqual(_ other: Any?) -> Bool {
|
||||
@objc override public func isEqual(_ other: Any?) -> Bool {
|
||||
guard let other = other as? LokiDeviceLink else { return false }
|
||||
return master == other.master && slave == other.slave
|
||||
}
|
||||
|
||||
// MARK: Hashing
|
||||
override public var hash: Int { // Override NSObject.hash and not Hashable.hashValue or Hashable.hash(into:)
|
||||
@objc override public var hash: Int { // Override NSObject.hash and not Hashable.hashValue or Hashable.hash(into:)
|
||||
return master.hash ^ slave.hash
|
||||
}
|
||||
|
||||
// MARK: Description
|
||||
override public var description: String { return "\(master) - \(slave)" }
|
||||
@objc override public var description: String { return "\(master) - \(slave)" }
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
|
||||
@objc(LKDeviceLinkingSessionDelegate)
|
||||
public protocol LokiDeviceLinkingSessionDelegate {
|
||||
|
||||
func requestUserAuthorization(for deviceLink: LokiDeviceLink)
|
||||
func handleDeviceLinkingSessionTimeout()
|
||||
@objc func requestUserAuthorization(for deviceLink: LokiDeviceLink)
|
||||
@objc func handleDeviceLinkingSessionTimeout()
|
||||
}
|
||||
|
Loading…
Reference in New Issue