Skip to content

Commit ef466ab

Browse files
authored
[Foundation] Fix nullability in NSUrlCredential.
This is file 15 of 47 files with nullability disabled in Foundation. Changes: - Enabled nullable reference types - Made SecIdentity property return SecIdentity? (nullable) since it can return null when Identity handle is IntPtr.Zero - Replaced "To be added." XML documentation with proper documentation for all members - Added see cref attributes for better cross-referencing - Removed unnecessary whitespace in XML comments - Replaced manual null checks with ArgumentNullException.ThrowIfNull for cleaner code - Added returns documentation for all methods that were missing it Contributes towards #17285.
1 parent f1b038e commit ef466ab

File tree

1 file changed

+20
-32
lines changed

1 file changed

+20
-32
lines changed

src/Foundation/NSUrlCredential.cs

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,35 @@
55

66
using Security;
77

8-
// Disable until we get around to enable + fix any issues.
9-
#nullable disable
8+
#nullable enable
109

1110
namespace Foundation {
1211

1312
public partial class NSUrlCredential {
14-
/// <param name="identity">Identity to use for the credential.</param>
15-
/// <param name="certificates">Certificates.</param>
16-
/// <param name="persistence">Specifies how long the credential should be kept.</param>
17-
/// <summary>Creates an NSUrlCredential from an identity (digital certificate + private key) and a list of certificates. </summary>
18-
/// <remarks>
19-
/// </remarks>
13+
/// <summary>Creates a new <see cref="NSUrlCredential" /> from an identity (digital certificate + private key) and a list of certificates.</summary>
14+
/// <param name="identity">The identity to use for the credential.</param>
15+
/// <param name="certificates">The certificates to use for the credential.</param>
16+
/// <param name="persistence">Specifies how long the credential should be kept.</param>
2017
public NSUrlCredential (SecIdentity identity, SecCertificate [] certificates, NSUrlCredentialPersistence persistence)
2118
: base (NSObjectFlag.Empty)
2219
{
23-
if (identity is null)
24-
throw new ArgumentNullException ("identity");
20+
ArgumentNullException.ThrowIfNull (identity);
2521

2622
using (var certs = NSArray.FromNativeObjects (certificates)) {
2723
InitializeHandle (_InitWithIdentity (identity.Handle, certs.Handle, persistence));
2824
GC.KeepAlive (identity);
2925
}
3026
}
3127

32-
/// <param name="identity">Identity to use for the credential.</param>
33-
/// <param name="certificates">Certificates for the credential.</param>
34-
/// <param name="persistence">Specifies how long the credential should be kept.</param>
35-
/// <summary>Creates an NSUrlCredential from an identity (digital certificate + private key) and a list of certificates. </summary>
36-
/// <returns>
37-
/// </returns>
38-
/// <remarks>
39-
/// </remarks>
28+
/// <summary>Creates a new <see cref="NSUrlCredential" /> from an identity (digital certificate + private key) and a list of certificates.</summary>
29+
/// <param name="identity">The identity to use for the credential.</param>
30+
/// <param name="certificates">The certificates to use for the credential.</param>
31+
/// <param name="persistence">Specifies how long the credential should be kept.</param>
32+
/// <returns>A new <see cref="NSUrlCredential" /> instance.</returns>
4033
public static NSUrlCredential FromIdentityCertificatesPersistance (SecIdentity identity, SecCertificate [] certificates, NSUrlCredentialPersistence persistence)
4134
{
42-
if (identity is null)
43-
throw new ArgumentNullException ("identity");
44-
if (certificates is null)
45-
throw new ArgumentNullException ("certificates");
35+
ArgumentNullException.ThrowIfNull (identity);
36+
ArgumentNullException.ThrowIfNull (certificates);
4637

4738
using (var certs = NSArray.FromNativeObjects (certificates)) {
4839
NSUrlCredential result = FromIdentityCertificatesPersistanceInternal (identity.Handle, certs.Handle, persistence);
@@ -51,24 +42,21 @@ public static NSUrlCredential FromIdentityCertificatesPersistance (SecIdentity i
5142
}
5243
}
5344

54-
/// <summary>To be added.</summary>
55-
/// <value>To be added.</value>
56-
/// <remarks>To be added.</remarks>
57-
public SecIdentity SecIdentity {
45+
/// <summary>Gets the identity (digital certificate + private key) associated with this credential.</summary>
46+
/// <value>A <see cref="SecIdentity" /> object representing the identity, or <see langword="null" /> if no identity is available.</value>
47+
public SecIdentity? SecIdentity {
5848
get {
5949
IntPtr handle = Identity;
6050
return (handle == IntPtr.Zero) ? null : new SecIdentity (handle, false);
6151
}
6252
}
6353

64-
/// <param name="trust">To be added.</param>
65-
/// <summary>To be added.</summary>
66-
/// <returns>To be added.</returns>
67-
/// <remarks>To be added.</remarks>
54+
/// <summary>Creates a new <see cref="NSUrlCredential" /> from a server trust.</summary>
55+
/// <param name="trust">The server trust to use for the credential.</param>
56+
/// <returns>A new <see cref="NSUrlCredential" /> instance.</returns>
6857
public static NSUrlCredential FromTrust (SecTrust trust)
6958
{
70-
if (trust is null)
71-
throw new ArgumentNullException ("trust");
59+
ArgumentNullException.ThrowIfNull (trust);
7260

7361
NSUrlCredential result = FromTrust (trust.Handle);
7462
GC.KeepAlive (trust);

0 commit comments

Comments
 (0)