objc2_foundation/generated/
NSURLCredentialStorage.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6
7use crate::*;
8
9extern_class!(
10    /// NSURLCredentialStorage implements a singleton object (shared instance) which manages the shared credentials cache. Note: Whereas in Mac OS X any application can access any credential with a persistence of NSURLCredentialPersistencePermanent provided the user gives permission, in iPhone OS an application can access only its own credentials.
11    ///
12    /// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nsurlcredentialstorage?language=objc)
13    #[unsafe(super(NSObject))]
14    #[derive(Debug, PartialEq, Eq, Hash)]
15    pub struct NSURLCredentialStorage;
16);
17
18unsafe impl Send for NSURLCredentialStorage {}
19
20unsafe impl Sync for NSURLCredentialStorage {}
21
22unsafe impl NSObjectProtocol for NSURLCredentialStorage {}
23
24impl NSURLCredentialStorage {
25    extern_methods!(
26        /// Get the shared singleton authentication storage
27        ///
28        /// Returns: the shared authentication storage
29        #[unsafe(method(sharedCredentialStorage))]
30        #[unsafe(method_family = none)]
31        pub unsafe fn sharedCredentialStorage() -> Retained<NSURLCredentialStorage>;
32
33        #[cfg(all(
34            feature = "NSDictionary",
35            feature = "NSString",
36            feature = "NSURLCredential",
37            feature = "NSURLProtectionSpace"
38        ))]
39        /// Get a dictionary mapping usernames to credentials for the specified protection space.
40        ///
41        /// Parameter `space`: An NSURLProtectionSpace indicating the protection space for which to get credentials
42        ///
43        /// Returns: A dictionary where the keys are usernames and the values are the corresponding NSURLCredentials.
44        #[unsafe(method(credentialsForProtectionSpace:))]
45        #[unsafe(method_family = none)]
46        pub unsafe fn credentialsForProtectionSpace(
47            &self,
48            space: &NSURLProtectionSpace,
49        ) -> Option<Retained<NSDictionary<NSString, NSURLCredential>>>;
50
51        #[cfg(all(
52            feature = "NSDictionary",
53            feature = "NSString",
54            feature = "NSURLCredential",
55            feature = "NSURLProtectionSpace"
56        ))]
57        /// Get a dictionary mapping NSURLProtectionSpaces to dictionaries which map usernames to NSURLCredentials
58        ///
59        /// Returns: an NSDictionary where the keys are NSURLProtectionSpaces
60        /// and the values are dictionaries, in which the keys are usernames
61        /// and the values are NSURLCredentials
62        #[unsafe(method(allCredentials))]
63        #[unsafe(method_family = none)]
64        pub unsafe fn allCredentials(
65            &self,
66        ) -> Retained<NSDictionary<NSURLProtectionSpace, NSDictionary<NSString, NSURLCredential>>>;
67
68        #[cfg(all(feature = "NSURLCredential", feature = "NSURLProtectionSpace"))]
69        /// Add a new credential to the set for the specified protection space or replace an existing one.
70        ///
71        /// Parameter `credential`: The credential to set.
72        ///
73        /// Parameter `space`: The protection space for which to add it.
74        ///
75        /// Multiple credentials may be set for a given protection space, but each must have
76        /// a distinct user. If a credential with the same user is already set for the protection space,
77        /// the new one will replace it.
78        #[unsafe(method(setCredential:forProtectionSpace:))]
79        #[unsafe(method_family = none)]
80        pub unsafe fn setCredential_forProtectionSpace(
81            &self,
82            credential: &NSURLCredential,
83            space: &NSURLProtectionSpace,
84        );
85
86        #[cfg(all(feature = "NSURLCredential", feature = "NSURLProtectionSpace"))]
87        /// Remove the credential from the set for the specified protection space.
88        ///
89        /// Parameter `credential`: The credential to remove.
90        ///
91        /// Parameter `space`: The protection space for which a credential should be removed
92        ///
93        /// The credential is removed from both persistent and temporary storage. A credential that
94        /// has a persistence policy of NSURLCredentialPersistenceSynchronizable will fail.
95        /// See removeCredential:forProtectionSpace:options.
96        #[unsafe(method(removeCredential:forProtectionSpace:))]
97        #[unsafe(method_family = none)]
98        pub unsafe fn removeCredential_forProtectionSpace(
99            &self,
100            credential: &NSURLCredential,
101            space: &NSURLProtectionSpace,
102        );
103
104        #[cfg(all(
105            feature = "NSDictionary",
106            feature = "NSString",
107            feature = "NSURLCredential",
108            feature = "NSURLProtectionSpace"
109        ))]
110        /// Remove the credential from the set for the specified protection space based on options.
111        ///
112        /// Parameter `credential`: The credential to remove.
113        ///
114        /// Parameter `space`: The protection space for which a credential should be removed
115        ///
116        /// Parameter `options`: A dictionary containing options to consider when removing the credential.  This should
117        /// be used when trying to delete a credential that has the NSURLCredentialPersistenceSynchronizable policy.
118        /// Please note that when NSURLCredential objects that have a NSURLCredentialPersistenceSynchronizable policy
119        /// are removed, the credential will be removed on all devices that contain this credential.
120        ///
121        /// The credential is removed from both persistent and temporary storage.
122        #[unsafe(method(removeCredential:forProtectionSpace:options:))]
123        #[unsafe(method_family = none)]
124        pub unsafe fn removeCredential_forProtectionSpace_options(
125            &self,
126            credential: &NSURLCredential,
127            space: &NSURLProtectionSpace,
128            options: Option<&NSDictionary<NSString, AnyObject>>,
129        );
130
131        #[cfg(all(feature = "NSURLCredential", feature = "NSURLProtectionSpace"))]
132        /// Get the default credential for the specified protection space.
133        ///
134        /// Parameter `space`: The protection space for which to get the default credential.
135        #[unsafe(method(defaultCredentialForProtectionSpace:))]
136        #[unsafe(method_family = none)]
137        pub unsafe fn defaultCredentialForProtectionSpace(
138            &self,
139            space: &NSURLProtectionSpace,
140        ) -> Option<Retained<NSURLCredential>>;
141
142        #[cfg(all(feature = "NSURLCredential", feature = "NSURLProtectionSpace"))]
143        /// Set the default credential for the specified protection space.
144        ///
145        /// Parameter `credential`: The credential to set as default.
146        ///
147        /// Parameter `space`: The protection space for which the credential should be set as default.
148        ///
149        /// If the credential is not yet in the set for the protection space, it will be added to it.
150        #[unsafe(method(setDefaultCredential:forProtectionSpace:))]
151        #[unsafe(method_family = none)]
152        pub unsafe fn setDefaultCredential_forProtectionSpace(
153            &self,
154            credential: &NSURLCredential,
155            space: &NSURLProtectionSpace,
156        );
157    );
158}
159
160/// Methods declared on superclass `NSObject`.
161impl NSURLCredentialStorage {
162    extern_methods!(
163        #[unsafe(method(init))]
164        #[unsafe(method_family = init)]
165        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
166
167        #[unsafe(method(new))]
168        #[unsafe(method_family = new)]
169        pub unsafe fn new() -> Retained<Self>;
170    );
171}
172
173/// NSURLSessionTaskAdditions.
174impl NSURLCredentialStorage {
175    extern_methods!(
176        #[cfg(all(
177            feature = "NSDictionary",
178            feature = "NSString",
179            feature = "NSURLCredential",
180            feature = "NSURLProtectionSpace",
181            feature = "NSURLSession",
182            feature = "block2"
183        ))]
184        #[unsafe(method(getCredentialsForProtectionSpace:task:completionHandler:))]
185        #[unsafe(method_family = none)]
186        pub unsafe fn getCredentialsForProtectionSpace_task_completionHandler(
187            &self,
188            protection_space: &NSURLProtectionSpace,
189            task: &NSURLSessionTask,
190            completion_handler: &block2::Block<
191                dyn Fn(*mut NSDictionary<NSString, NSURLCredential>),
192            >,
193        );
194
195        #[cfg(all(
196            feature = "NSURLCredential",
197            feature = "NSURLProtectionSpace",
198            feature = "NSURLSession"
199        ))]
200        #[unsafe(method(setCredential:forProtectionSpace:task:))]
201        #[unsafe(method_family = none)]
202        pub unsafe fn setCredential_forProtectionSpace_task(
203            &self,
204            credential: &NSURLCredential,
205            protection_space: &NSURLProtectionSpace,
206            task: &NSURLSessionTask,
207        );
208
209        #[cfg(all(
210            feature = "NSDictionary",
211            feature = "NSString",
212            feature = "NSURLCredential",
213            feature = "NSURLProtectionSpace",
214            feature = "NSURLSession"
215        ))]
216        #[unsafe(method(removeCredential:forProtectionSpace:options:task:))]
217        #[unsafe(method_family = none)]
218        pub unsafe fn removeCredential_forProtectionSpace_options_task(
219            &self,
220            credential: &NSURLCredential,
221            protection_space: &NSURLProtectionSpace,
222            options: Option<&NSDictionary<NSString, AnyObject>>,
223            task: &NSURLSessionTask,
224        );
225
226        #[cfg(all(
227            feature = "NSURLCredential",
228            feature = "NSURLProtectionSpace",
229            feature = "NSURLSession",
230            feature = "block2"
231        ))]
232        #[unsafe(method(getDefaultCredentialForProtectionSpace:task:completionHandler:))]
233        #[unsafe(method_family = none)]
234        pub unsafe fn getDefaultCredentialForProtectionSpace_task_completionHandler(
235            &self,
236            space: &NSURLProtectionSpace,
237            task: &NSURLSessionTask,
238            completion_handler: &block2::Block<dyn Fn(*mut NSURLCredential)>,
239        );
240
241        #[cfg(all(
242            feature = "NSURLCredential",
243            feature = "NSURLProtectionSpace",
244            feature = "NSURLSession"
245        ))]
246        #[unsafe(method(setDefaultCredential:forProtectionSpace:task:))]
247        #[unsafe(method_family = none)]
248        pub unsafe fn setDefaultCredential_forProtectionSpace_task(
249            &self,
250            credential: &NSURLCredential,
251            protection_space: &NSURLProtectionSpace,
252            task: &NSURLSessionTask,
253        );
254    );
255}
256
257extern "C" {
258    /// This notification is sent on the main thread whenever
259    /// the set of stored credentials changes.
260    ///
261    /// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nsurlcredentialstoragechangednotification?language=objc)
262    #[cfg(all(feature = "NSNotification", feature = "NSString"))]
263    pub static NSURLCredentialStorageChangedNotification: &'static NSNotificationName;
264}
265
266extern "C" {
267    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsurlcredentialstorageremovesynchronizablecredentials?language=objc)
268    #[cfg(feature = "NSString")]
269    pub static NSURLCredentialStorageRemoveSynchronizableCredentials: &'static NSString;
270}