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 unsafe 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 unsafe 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 unsafe 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 unsafe 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 unsafe 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        #[unsafe(method(removeCredential:forProtectionSpace:options:))]
125        #[unsafe(method_family = none)]
126        pub unsafe fn removeCredential_forProtectionSpace_options(
127            &self,
128            credential: &NSURLCredential,
129            space: &NSURLProtectionSpace,
130            options: Option<&NSDictionary<NSString, AnyObject>>,
131        );
132
133        #[cfg(all(feature = "NSURLCredential", feature = "NSURLProtectionSpace"))]
134        /// Get the default credential for the specified protection space.
135        ///
136        /// Parameter `space`: The protection space for which to get the default credential.
137        #[unsafe(method(defaultCredentialForProtectionSpace:))]
138        #[unsafe(method_family = none)]
139        pub unsafe fn defaultCredentialForProtectionSpace(
140            &self,
141            space: &NSURLProtectionSpace,
142        ) -> Option<Retained<NSURLCredential>>;
143
144        #[cfg(all(feature = "NSURLCredential", feature = "NSURLProtectionSpace"))]
145        /// Set the default credential for the specified protection space.
146        ///
147        /// Parameter `credential`: The credential to set as default.
148        ///
149        /// Parameter `space`: The protection space for which the credential should be set as default.
150        ///
151        /// If the credential is not yet in the set for the protection space, it will be added to it.
152        #[unsafe(method(setDefaultCredential:forProtectionSpace:))]
153        #[unsafe(method_family = none)]
154        pub unsafe fn setDefaultCredential_forProtectionSpace(
155            &self,
156            credential: &NSURLCredential,
157            space: &NSURLProtectionSpace,
158        );
159    );
160}
161
162/// Methods declared on superclass `NSObject`.
163impl NSURLCredentialStorage {
164    extern_methods!(
165        #[unsafe(method(init))]
166        #[unsafe(method_family = init)]
167        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
168
169        #[unsafe(method(new))]
170        #[unsafe(method_family = new)]
171        pub unsafe fn new() -> Retained<Self>;
172    );
173}
174
175/// NSURLSessionTaskAdditions.
176impl NSURLCredentialStorage {
177    extern_methods!(
178        #[cfg(all(
179            feature = "NSDictionary",
180            feature = "NSString",
181            feature = "NSURLCredential",
182            feature = "NSURLProtectionSpace",
183            feature = "NSURLSession",
184            feature = "block2"
185        ))]
186        #[unsafe(method(getCredentialsForProtectionSpace:task:completionHandler:))]
187        #[unsafe(method_family = none)]
188        pub unsafe fn getCredentialsForProtectionSpace_task_completionHandler(
189            &self,
190            protection_space: &NSURLProtectionSpace,
191            task: &NSURLSessionTask,
192            completion_handler: &block2::DynBlock<
193                dyn Fn(*mut NSDictionary<NSString, NSURLCredential>),
194            >,
195        );
196
197        #[cfg(all(
198            feature = "NSURLCredential",
199            feature = "NSURLProtectionSpace",
200            feature = "NSURLSession"
201        ))]
202        #[unsafe(method(setCredential:forProtectionSpace:task:))]
203        #[unsafe(method_family = none)]
204        pub unsafe fn setCredential_forProtectionSpace_task(
205            &self,
206            credential: &NSURLCredential,
207            protection_space: &NSURLProtectionSpace,
208            task: &NSURLSessionTask,
209        );
210
211        #[cfg(all(
212            feature = "NSDictionary",
213            feature = "NSString",
214            feature = "NSURLCredential",
215            feature = "NSURLProtectionSpace",
216            feature = "NSURLSession"
217        ))]
218        #[unsafe(method(removeCredential:forProtectionSpace:options:task:))]
219        #[unsafe(method_family = none)]
220        pub unsafe fn removeCredential_forProtectionSpace_options_task(
221            &self,
222            credential: &NSURLCredential,
223            protection_space: &NSURLProtectionSpace,
224            options: Option<&NSDictionary<NSString, AnyObject>>,
225            task: &NSURLSessionTask,
226        );
227
228        #[cfg(all(
229            feature = "NSURLCredential",
230            feature = "NSURLProtectionSpace",
231            feature = "NSURLSession",
232            feature = "block2"
233        ))]
234        #[unsafe(method(getDefaultCredentialForProtectionSpace:task:completionHandler:))]
235        #[unsafe(method_family = none)]
236        pub unsafe fn getDefaultCredentialForProtectionSpace_task_completionHandler(
237            &self,
238            space: &NSURLProtectionSpace,
239            task: &NSURLSessionTask,
240            completion_handler: &block2::DynBlock<dyn Fn(*mut NSURLCredential)>,
241        );
242
243        #[cfg(all(
244            feature = "NSURLCredential",
245            feature = "NSURLProtectionSpace",
246            feature = "NSURLSession"
247        ))]
248        #[unsafe(method(setDefaultCredential:forProtectionSpace:task:))]
249        #[unsafe(method_family = none)]
250        pub unsafe fn setDefaultCredential_forProtectionSpace_task(
251            &self,
252            credential: &NSURLCredential,
253            protection_space: &NSURLProtectionSpace,
254            task: &NSURLSessionTask,
255        );
256    );
257}
258
259extern "C" {
260    /// This notification is sent on the main thread whenever
261    /// the set of stored credentials changes.
262    ///
263    /// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nsurlcredentialstoragechangednotification?language=objc)
264    #[cfg(all(feature = "NSNotification", feature = "NSString"))]
265    pub static NSURLCredentialStorageChangedNotification: &'static NSNotificationName;
266}
267
268extern "C" {
269    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsurlcredentialstorageremovesynchronizablecredentials?language=objc)
270    #[cfg(feature = "NSString")]
271    pub static NSURLCredentialStorageRemoveSynchronizableCredentials: &'static NSString;
272}