@@ -40,8 +40,12 @@ extension URLCredential {
40
40
@discussion This class is an immutable object representing an authentication credential. The actual type of the credential is determined by the constructor called in the categories declared below.
41
41
*/
42
42
open class URLCredential : NSObject , NSSecureCoding , NSCopying {
43
- private var _user : String
44
- private var _password : String
43
+ private var _user : String ?
44
+ private var _password : String ?
45
+ // _privateClientKey contains the private client key in DER format
46
+ private var _privateClientKey : Data ?
47
+ // _privateClientCertificate contains the private client certificate in DER format
48
+ private var _privateClientCertificate : Data ?
45
49
private var _persistence : Persistence
46
50
47
51
/*!
@@ -55,6 +59,25 @@ open class URLCredential : NSObject, NSSecureCoding, NSCopying {
55
59
public init ( user: String , password: String , persistence: Persistence ) {
56
60
_user = user
57
61
_password = password
62
+ _privateClientKey = nil
63
+ _privateClientCertificate = nil
64
+ _persistence = persistence
65
+ super. init ( )
66
+ }
67
+
68
+ /*!
69
+ @method initWithUser:password:persistence:
70
+ @abstract Initialize a URLCredential with a user and password
71
+ @param user the username
72
+ @param password the password
73
+ @param persistence enum that says to store per session, permanently or not at all
74
+ @result The initialized URLCredential
75
+ */
76
+ public init ( clientKey: Data , clientCertificate: Data , persistence: Persistence ) {
77
+ _user = nil
78
+ _password = nil
79
+ _privateClientKey = clientKey
80
+ _privateClientCertificate = clientCertificate
58
81
_persistence = persistence
59
82
super. init ( )
60
83
}
@@ -91,9 +114,14 @@ open class URLCredential : NSObject, NSSecureCoding, NSCopying {
91
114
guard aCoder. allowsKeyedCoding else {
92
115
preconditionFailure ( " Unkeyed coding is unsupported. " )
93
116
}
94
-
95
- aCoder. encode ( self . _user. _bridgeToObjectiveC ( ) , forKey: " NS._user " )
96
- aCoder. encode ( self . _password. _bridgeToObjectiveC ( ) , forKey: " NS._password " )
117
+
118
+ if let user = self . _user {
119
+ aCoder. encode ( user. _bridgeToObjectiveC ( ) , forKey: " NS._user " )
120
+ }
121
+ if let password = self . _password {
122
+ aCoder. encode ( password. _bridgeToObjectiveC ( ) , forKey: " NS._password " )
123
+ }
124
+
97
125
aCoder. encode ( self . _persistence. rawValue. _bridgeToObjectiveC ( ) , forKey: " NS._persistence " )
98
126
}
99
127
@@ -141,6 +169,20 @@ open class URLCredential : NSObject, NSSecureCoding, NSCopying {
141
169
*/
142
170
open var password : String ? { return _password }
143
171
172
+ /*!
173
+ @method privateClientKey
174
+ @abstract Get the private client key
175
+ @result The private key binary blob
176
+ */
177
+ open var privateClientKey : Data ? { return _privateClientKey }
178
+
179
+ /*!
180
+ @method privateClientCertificate
181
+ @abstract Get the private client key
182
+ @result The private key binary blob
183
+ */
184
+ open var privateClientCertificate : Data ? { return _privateClientCertificate }
185
+
144
186
/*!
145
187
@method hasPassword
146
188
@abstract Find out if this credential has a password, without trying to get it
@@ -152,6 +194,6 @@ open class URLCredential : NSObject, NSSecureCoding, NSCopying {
152
194
*/
153
195
open var hasPassword : Bool {
154
196
// Currently no support for SecTrust/SecIdentity, always return true
155
- return true
197
+ return _password != nil
156
198
}
157
199
}
0 commit comments