-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSFTPFingerprint.swift
96 lines (80 loc) · 2.75 KB
/
SFTPFingerprint.swift
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
// Copyright (c) 2014-2016 SafeDrive. All rights reserved.
//
import Foundation
import SDDK
public class SDKSFTPFingerprint: Equatable, NSSecureCoding {
public func encode(with aCoder: NSCoder) {
aCoder.encode(self.host, forKey: "host")
aCoder.encode(self.fingerprint, forKey: "fingerprint")
aCoder.encode(self.port, forKey: "port")
}
fileprivate let modificationQueue = DispatchQueue(label: "io.safedrive.SafeDriveSDK.SDKSFTPFingerprint.modificationQueue")
public static var supportsSecureCoding = true
var _host: String
var _fingerprint: String
var _port: UInt16
public var port: UInt16 {
get {
var r: UInt16 = 0
modificationQueue.sync {
r = self._port
}
return r
}
set (newValue) {
modificationQueue.sync(flags: .barrier, execute: {
self._port = newValue
})
}
}
public var host: String {
get {
var r: String = ""
modificationQueue.sync {
r = self._host
}
return r
}
set (newValue) {
modificationQueue.sync(flags: .barrier, execute: {
self._host = newValue
})
}
}
public var fingerprint: String {
get {
var r: String = ""
modificationQueue.sync {
r = self._fingerprint
}
return r
}
set (newValue) {
modificationQueue.sync(flags: .barrier, execute: {
self._fingerprint = newValue
})
}
}
public static func == (left: SDKSFTPFingerprint, right: SDKSFTPFingerprint) -> Bool {
return (left.fingerprint == right.fingerprint) && (left.host == right.host)
}
public init(fingerprint: SDDKSFTPFingerprint) {
_host = String(cString: fingerprint.host)
_fingerprint = String(cString: fingerprint.fingerprint)
_port = fingerprint.port
}
public required init?(coder aDecoder: NSCoder) {
guard let host = aDecoder.decodeObject(of: NSString.self, forKey: "host") as String? else {
fatalError("Could not deserialise host!")
}
guard let fingerprint = aDecoder.decodeObject(of: NSString.self, forKey: "fingerprint") as String? else {
fatalError("Could not deserialise fingerprint!")
}
guard let port = aDecoder.decodeObject(of: NSNumber.self, forKey: "port") as NSNumber? else {
fatalError("Could not deserialise port!")
}
_host = host
_fingerprint = fingerprint
_port = UInt16(truncating: port)
}
}