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 unsafe 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 unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
94
95        #[unsafe(method(new))]
96        #[unsafe(method_family = new)]
97        pub unsafe fn new() -> Retained<Self>;
98    );
99}
100
101/// NSInternetPassword.
102/// 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.
103impl NSURLCredential {
104    extern_methods!(
105        #[cfg(feature = "NSString")]
106        /// Initialize a NSURLCredential with a user and password
107        ///
108        /// Parameter `user`: the username
109        ///
110        /// Parameter `password`: the password
111        ///
112        /// Parameter `persistence`: enum that says to store per session, permanently or not at all
113        ///
114        /// Returns: The initialized NSURLCredential
115        #[unsafe(method(initWithUser:password:persistence:))]
116        #[unsafe(method_family = init)]
117        pub unsafe fn initWithUser_password_persistence(
118            this: Allocated<Self>,
119            user: &NSString,
120            password: &NSString,
121            persistence: NSURLCredentialPersistence,
122        ) -> Retained<Self>;
123
124        #[cfg(feature = "NSString")]
125        /// Create a new NSURLCredential with a user and password
126        ///
127        /// Parameter `user`: the username
128        ///
129        /// Parameter `password`: the password
130        ///
131        /// Parameter `persistence`: enum that says to store per session, permanently or not at all
132        ///
133        /// Returns: The new autoreleased NSURLCredential
134        #[unsafe(method(credentialWithUser:password:persistence:))]
135        #[unsafe(method_family = none)]
136        pub unsafe fn credentialWithUser_password_persistence(
137            user: &NSString,
138            password: &NSString,
139            persistence: NSURLCredentialPersistence,
140        ) -> Retained<NSURLCredential>;
141
142        #[cfg(feature = "NSString")]
143        /// Get the username
144        ///
145        /// Returns: The user string
146        #[unsafe(method(user))]
147        #[unsafe(method_family = none)]
148        pub unsafe fn user(&self) -> Option<Retained<NSString>>;
149
150        #[cfg(feature = "NSString")]
151        /// Get the password
152        ///
153        /// Returns: The password string
154        ///
155        /// This method might actually attempt to retrieve the
156        /// password from an external store, possible resulting in prompting,
157        /// so do not call it unless needed.
158        #[unsafe(method(password))]
159        #[unsafe(method_family = none)]
160        pub unsafe fn password(&self) -> Option<Retained<NSString>>;
161
162        /// Find out if this credential has a password, without trying to get it
163        ///
164        /// Returns: YES if this credential has a password, otherwise NO
165        ///
166        /// If this credential's password is actually kept in an
167        /// external store, the password method may return nil even if this
168        /// method returns YES, since getting the password may fail, or the
169        /// user may refuse access.
170        #[unsafe(method(hasPassword))]
171        #[unsafe(method_family = none)]
172        pub unsafe fn hasPassword(&self) -> bool;
173    );
174}
175
176/// NSClientCertificate.
177/// 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.
178impl NSURLCredential {
179    extern_methods!(
180        #[cfg(feature = "NSArray")]
181        /// Returns an NSArray of SecCertificateRef objects representing the client certificate for this credential, if this credential was created with an identity and certificate.
182        ///
183        /// Returns: an NSArray of SecCertificateRef or NULL if this is a username/password credential
184        #[unsafe(method(certificates))]
185        #[unsafe(method_family = none)]
186        pub unsafe fn certificates(&self) -> Retained<NSArray>;
187    );
188}
189
190/// NSServerTrust.
191impl NSURLCredential {
192    extern_methods!();
193}