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