objc2_foundation/generated/NSURLCredential.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ptr::NonNull;
4use objc2::__framework_prelude::*;
5
6use crate::*;
7
8/// Constants defining how long a credential will be kept around
9///
10///
11///
12///
13/// Note: Whereas in Mac OS X any application can access any credential provided the user gives permission, on iOS an application can
14/// access only its own credentials.
15///
16/// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nsurlcredentialpersistence?language=objc)
17// NS_ENUM
18#[repr(transparent)]
19#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
20pub struct NSURLCredentialPersistence(pub NSUInteger);
21impl NSURLCredentialPersistence {
22 #[doc(alias = "NSURLCredentialPersistenceNone")]
23 pub const None: Self = Self(0);
24 #[doc(alias = "NSURLCredentialPersistenceForSession")]
25 pub const ForSession: Self = Self(1);
26 #[doc(alias = "NSURLCredentialPersistencePermanent")]
27 pub const Permanent: Self = Self(2);
28 #[doc(alias = "NSURLCredentialPersistenceSynchronizable")]
29 pub const Synchronizable: Self = Self(3);
30}
31
32unsafe impl Encode for NSURLCredentialPersistence {
33 const ENCODING: Encoding = NSUInteger::ENCODING;
34}
35
36unsafe impl RefEncode for NSURLCredentialPersistence {
37 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
38}
39
40extern_class!(
41 /// 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.
42 ///
43 /// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nsurlcredential?language=objc)
44 #[unsafe(super(NSObject))]
45 #[derive(Debug, PartialEq, Eq, Hash)]
46 pub struct NSURLCredential;
47);
48
49unsafe impl Send for NSURLCredential {}
50
51unsafe impl Sync for NSURLCredential {}
52
53#[cfg(feature = "NSObject")]
54extern_conformance!(
55 unsafe impl NSCoding for NSURLCredential {}
56);
57
58#[cfg(feature = "NSObject")]
59extern_conformance!(
60 unsafe impl NSCopying for NSURLCredential {}
61);
62
63#[cfg(feature = "NSObject")]
64unsafe impl CopyingHelper for NSURLCredential {
65 type Result = Self;
66}
67
68extern_conformance!(
69 unsafe impl NSObjectProtocol for NSURLCredential {}
70);
71
72#[cfg(feature = "NSObject")]
73extern_conformance!(
74 unsafe impl NSSecureCoding for NSURLCredential {}
75);
76
77impl NSURLCredential {
78 extern_methods!(
79 /// Determine whether this credential is or should be stored persistently
80 ///
81 /// Returns: A value indicating whether this credential is stored permanently, per session or not at all.
82 #[unsafe(method(persistence))]
83 #[unsafe(method_family = none)]
84 pub fn persistence(&self) -> NSURLCredentialPersistence;
85 );
86}
87
88/// Methods declared on superclass `NSObject`.
89impl NSURLCredential {
90 extern_methods!(
91 #[unsafe(method(init))]
92 #[unsafe(method_family = init)]
93 pub fn init(this: Allocated<Self>) -> Retained<Self>;
94
95 #[unsafe(method(new))]
96 #[unsafe(method_family = new)]
97 pub fn new() -> Retained<Self>;
98 );
99}
100
101impl DefaultRetained for NSURLCredential {
102 #[inline]
103 fn default_retained() -> Retained<Self> {
104 Self::new()
105 }
106}
107
108/// NSInternetPassword.
109///
110/// This category defines the methods available to an NSURLCredential created to represent an internet password credential. These are most commonly used for resources that require a username and password combination.
111impl NSURLCredential {
112 extern_methods!(
113 #[cfg(feature = "NSString")]
114 /// Initialize a NSURLCredential with a user and password
115 ///
116 /// Parameter `user`: the username
117 ///
118 /// Parameter `password`: the password
119 ///
120 /// Parameter `persistence`: enum that says to store per session, permanently or not at all
121 ///
122 /// Returns: The initialized NSURLCredential
123 #[unsafe(method(initWithUser:password:persistence:))]
124 #[unsafe(method_family = init)]
125 pub fn initWithUser_password_persistence(
126 this: Allocated<Self>,
127 user: &NSString,
128 password: &NSString,
129 persistence: NSURLCredentialPersistence,
130 ) -> Retained<Self>;
131
132 #[cfg(feature = "NSString")]
133 /// Create a new NSURLCredential with a user and password
134 ///
135 /// Parameter `user`: the username
136 ///
137 /// Parameter `password`: the password
138 ///
139 /// Parameter `persistence`: enum that says to store per session, permanently or not at all
140 ///
141 /// Returns: The new autoreleased NSURLCredential
142 #[unsafe(method(credentialWithUser:password:persistence:))]
143 #[unsafe(method_family = none)]
144 pub fn credentialWithUser_password_persistence(
145 user: &NSString,
146 password: &NSString,
147 persistence: NSURLCredentialPersistence,
148 ) -> Retained<NSURLCredential>;
149
150 #[cfg(feature = "NSString")]
151 /// Get the username
152 ///
153 /// Returns: The user string
154 #[unsafe(method(user))]
155 #[unsafe(method_family = none)]
156 pub fn user(&self) -> Option<Retained<NSString>>;
157
158 #[cfg(feature = "NSString")]
159 /// Get the password
160 ///
161 /// Returns: The password string
162 ///
163 /// This method might actually attempt to retrieve the
164 /// password from an external store, possible resulting in prompting,
165 /// so do not call it unless needed.
166 #[unsafe(method(password))]
167 #[unsafe(method_family = none)]
168 pub fn password(&self) -> Option<Retained<NSString>>;
169
170 /// Find out if this credential has a password, without trying to get it
171 ///
172 /// Returns: YES if this credential has a password, otherwise NO
173 ///
174 /// If this credential's password is actually kept in an
175 /// external store, the password method may return nil even if this
176 /// method returns YES, since getting the password may fail, or the
177 /// user may refuse access.
178 #[unsafe(method(hasPassword))]
179 #[unsafe(method_family = none)]
180 pub fn hasPassword(&self) -> bool;
181 );
182}
183
184/// NSClientCertificate.
185///
186/// This category defines the methods available to an NSURLCredential created to represent a client certificate credential. Client certificates are commonly stored on the users computer in the keychain and must be presented to the server during a handshake.
187impl NSURLCredential {
188 extern_methods!(
189 #[cfg(feature = "NSArray")]
190 /// Returns an NSArray of SecCertificateRef objects representing the client certificate for this credential, if this credential was created with an identity and certificate.
191 ///
192 /// Returns: an NSArray of SecCertificateRef or NULL if this is a username/password credential
193 #[unsafe(method(certificates))]
194 #[unsafe(method_family = none)]
195 pub fn certificates(&self) -> Retained<NSArray>;
196 );
197}
198
199/// NSServerTrust.
200impl NSURLCredential {
201 extern_methods!();
202}