Skip to content

Commit

Permalink
Annotate System.Net.Mail for nullable reference types (dotnet#33826)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub authored Mar 21, 2020
1 parent c73774b commit cf63e73
Show file tree
Hide file tree
Showing 55 changed files with 668 additions and 750 deletions.
4 changes: 2 additions & 2 deletions src/libraries/Common/src/System/Net/ContextAwareResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ internal ContextAwareResult(object myObject, object? myState, AsyncCallback? myC
//
// Setting forceCaptureContext enables the ContextCopy property even when a null callback is specified. (The context is
// always captured if a callback is given.)
internal ContextAwareResult(bool captureIdentity, bool forceCaptureContext, object myObject, object? myState, AsyncCallback? myCallBack) :
internal ContextAwareResult(bool captureIdentity, bool forceCaptureContext, object? myObject, object? myState, AsyncCallback? myCallBack) :
this(captureIdentity, forceCaptureContext, false, myObject, myState, myCallBack)
{ }

internal ContextAwareResult(bool captureIdentity, bool forceCaptureContext, bool threadSafeContextCopy, object myObject, object? myState, AsyncCallback? myCallBack) :
internal ContextAwareResult(bool captureIdentity, bool forceCaptureContext, bool threadSafeContextCopy, object? myObject, object? myState, AsyncCallback? myCallBack) :
base(myObject, myState, myCallBack)
{
if (forceCaptureContext)
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/Common/src/System/Net/Mail/MailBnfHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ internal static void ValidateHeaderName(string data)
throw new FormatException(SR.InvalidHeaderName);
}

internal static string? ReadQuotedString(string data, ref int offset, StringBuilder builder)
internal static string? ReadQuotedString(string data, ref int offset, StringBuilder? builder)
{
return ReadQuotedString(data, ref offset, builder, false, false);
}
Expand Down Expand Up @@ -247,7 +247,7 @@ internal static void ValidateHeaderName(string data)
throw new FormatException(SR.MailHeaderFieldMalformedHeader);
}

internal static string? ReadParameterAttribute(string data, ref int offset, StringBuilder builder)
internal static string? ReadParameterAttribute(string data, ref int offset, StringBuilder? builder)
{
if (!SkipCFWS(data, ref offset))
return null; //
Expand Down
11 changes: 6 additions & 5 deletions src/libraries/Common/src/System/Net/NTAuthentication.Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#nullable enable
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Net.Security;
using System.Runtime.InteropServices;
using System.Security.Authentication.ExtendedProtection;
Expand All @@ -16,7 +17,7 @@ internal partial class NTAuthentication

private SafeFreeCredentials? _credentialsHandle;
private SafeDeleteContext? _securityContext;
private string _spn = null!;
private string? _spn;

private int _tokenSize;
private ContextFlagsPal _requestedContextFlags;
Expand Down Expand Up @@ -92,12 +93,12 @@ internal bool IsKerberos
//
// This overload does not attempt to impersonate because the caller either did it already or the original thread context is still preserved.
//
internal NTAuthentication(bool isServer, string package, NetworkCredential credential, string spn, ContextFlagsPal requestedContextFlags, ChannelBinding? channelBinding)
internal NTAuthentication(bool isServer, string package, NetworkCredential credential, string? spn, ContextFlagsPal requestedContextFlags, ChannelBinding? channelBinding)
{
Initialize(isServer, package, credential, spn, requestedContextFlags, channelBinding);
}

private void Initialize(bool isServer, string package, NetworkCredential credential, string spn, ContextFlagsPal requestedContextFlags, ChannelBinding? channelBinding)
private void Initialize(bool isServer, string package, NetworkCredential credential, string? spn, ContextFlagsPal requestedContextFlags, ChannelBinding? channelBinding)
{
if (NetEventSource.IsEnabled) NetEventSource.Enter(this, package, spn, requestedContextFlags);

Expand Down Expand Up @@ -162,7 +163,7 @@ internal int VerifySignature(byte[] buffer, int offset, int count)
return NegotiateStreamPal.VerifySignature(_securityContext!, buffer, offset, count);
}

internal int MakeSignature(byte[] buffer, int offset, int count, ref byte[] output)
internal int MakeSignature(byte[] buffer, int offset, int count, [AllowNull] ref byte[] output)
{
return NegotiateStreamPal.MakeSignature(_securityContext!, buffer, offset, count, ref output);
}
Expand Down Expand Up @@ -202,7 +203,7 @@ internal int MakeSignature(byte[] buffer, int offset, int count, ref byte[] outp
return outgoingBlob;
}

internal byte[]? GetOutgoingBlob(byte[] incomingBlob, bool thrownOnError)
internal byte[]? GetOutgoingBlob(byte[]? incomingBlob, bool thrownOnError)
{
SecurityStatusPal statusCode;
return GetOutgoingBlob(incomingBlob, thrownOnError, out statusCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.IO;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Authentication;
Expand Down Expand Up @@ -280,7 +281,7 @@ private static SecurityStatusPal EstablishSecurityContext(
SafeFreeNegoCredentials credential,
ref SafeDeleteContext? context,
ChannelBinding? channelBinding,
string targetName,
string? targetName,
ContextFlagsPal inFlags,
byte[]? incomingBlob,
ref byte[]? resultBuffer,
Expand All @@ -296,7 +297,7 @@ private static SecurityStatusPal EstablishSecurityContext(
NetEventSource.Info(context, $"requested protocol = {protocol}, target = {targetName}");
}

context = new SafeDeleteNegoContext(credential, targetName);
context = new SafeDeleteNegoContext(credential, targetName!);
}

SafeDeleteNegoContext negoContext = (SafeDeleteNegoContext)context;
Expand Down Expand Up @@ -358,7 +359,7 @@ private static SecurityStatusPal EstablishSecurityContext(
internal static SecurityStatusPal InitializeSecurityContext(
ref SafeFreeCredentials credentialsHandle,
ref SafeDeleteContext? securityContext,
string spn,
string? spn,
ContextFlagsPal requestedContextFlags,
byte[]? incomingBlob,
ChannelBinding? channelBinding,
Expand Down Expand Up @@ -624,7 +625,7 @@ internal static int VerifySignature(SafeDeleteContext securityContext, byte[] bu
return GssUnwrap(((SafeDeleteNegoContext)securityContext).GssContext, buffer!, offset, count);
}

internal static int MakeSignature(SafeDeleteContext securityContext, byte[] buffer, int offset, int count, ref byte[] output)
internal static int MakeSignature(SafeDeleteContext securityContext, byte[] buffer, int offset, int count, [AllowNull] ref byte[] output)
{
SafeDeleteNegoContext gssContext = (SafeDeleteNegoContext)securityContext;
byte[] tempOutput = GssWrap(gssContext.GssContext, false, buffer, offset, count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#nullable enable
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Security.Authentication.ExtendedProtection;
Expand Down Expand Up @@ -74,7 +75,7 @@ internal static unsafe SafeFreeCredentials AcquireCredentialsHandle(string packa
internal static SecurityStatusPal InitializeSecurityContext(
ref SafeFreeCredentials? credentialsHandle,
ref SafeDeleteContext? securityContext,
string spn,
string? spn,
ContextFlagsPal requestedContextFlags,
byte[]? incomingBlob,
ChannelBinding? channelBinding,
Expand Down Expand Up @@ -225,7 +226,7 @@ internal static int VerifySignature(SafeDeleteContext securityContext, byte[] bu
return securityBuffer[1].size;
}

internal static int MakeSignature(SafeDeleteContext securityContext, byte[] buffer, int offset, int count, ref byte[] output)
internal static int MakeSignature(SafeDeleteContext securityContext, byte[] buffer, int offset, int count, [AllowNull] ref byte[] output)
{
SecPkgContext_Sizes sizes = default;
bool success = SSPIWrapper.QueryBlittableContextAttributes(GlobalSSPI.SSPIAuth, securityContext, Interop.SspiCli.ContextAttribute.SECPKG_ATTR_SIZES, ref sizes);
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/Common/src/System/Net/TlsStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ internal class TlsStream : NetworkStream
{
private readonly SslStream _sslStream;
private readonly string _host;
private readonly X509CertificateCollection _clientCertificates;
private readonly X509CertificateCollection? _clientCertificates;

public TlsStream(NetworkStream stream, Socket socket, string host, X509CertificateCollection clientCertificates) : base(socket)
public TlsStream(NetworkStream stream, Socket socket, string host, X509CertificateCollection? clientCertificates) : base(socket)
{
_sslStream = new SslStream(stream, false, ServicePointManager.ServerCertificateValidationCallback);
_host = host;
Expand Down
Loading

0 comments on commit cf63e73

Please sign in to comment.