@@ -40,8 +40,12 @@ extension URLCredential {
4040 @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.
4141*/
4242open 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 ?
4549 private var _persistence : Persistence
4650
4751 /*!
@@ -55,6 +59,25 @@ open class URLCredential : NSObject, NSSecureCoding, NSCopying {
5559 public init ( user: String , password: String , persistence: Persistence ) {
5660 _user = user
5761 _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
5881 _persistence = persistence
5982 super. init ( )
6083 }
@@ -91,9 +114,14 @@ open class URLCredential : NSObject, NSSecureCoding, NSCopying {
91114 guard aCoder. allowsKeyedCoding else {
92115 preconditionFailure ( " Unkeyed coding is unsupported. " )
93116 }
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+
97125 aCoder. encode ( self . _persistence. rawValue. _bridgeToObjectiveC ( ) , forKey: " NS._persistence " )
98126 }
99127
@@ -141,6 +169,20 @@ open class URLCredential : NSObject, NSSecureCoding, NSCopying {
141169 */
142170 open var password : String ? { return _password }
143171
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+
144186 /*!
145187 @method hasPassword
146188 @abstract Find out if this credential has a password, without trying to get it
@@ -152,6 +194,6 @@ open class URLCredential : NSObject, NSSecureCoding, NSCopying {
152194 */
153195 open var hasPassword : Bool {
154196 // Currently no support for SecTrust/SecIdentity, always return true
155- return true
197+ return _password != nil
156198 }
157199}
0 commit comments