Skip to content

Commit f04992f

Browse files
authored
Add nullable to DataProtection (#22591)
* Add nullable to DataProtection Contributes to #5680
1 parent 9b63151 commit f04992f

21 files changed

+56
-44
lines changed

src/DataProtection/Abstractions/ref/Microsoft.AspNetCore.DataProtection.Abstractions.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<PropertyGroup>
44
<TargetFrameworks>netstandard2.0;$(DefaultNetCoreTargetFramework)</TargetFrameworks>
55
<TargetFrameworks Condition="'$(DotNetBuildFromSource)' == 'true'">$(DefaultNetCoreTargetFramework)</TargetFrameworks>
6+
<Nullable>annotations</Nullable>
67
</PropertyGroup>
78
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
89
<Compile Include="Microsoft.AspNetCore.DataProtection.Abstractions.netstandard2.0.cs" />

src/DataProtection/Abstractions/src/DataProtectionCommonExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public static IDataProtector CreateProtector(this IDataProtectionProvider provid
8888
// because we don't want the code provider.CreateProtector() [parameterless] to inadvertently compile.
8989
// The actual signature for this method forces at least one purpose to be provided at the call site.
9090

91-
IDataProtector protector = provider.CreateProtector(purpose);
91+
IDataProtector? protector = provider.CreateProtector(purpose);
9292
if (subPurposes != null && subPurposes.Length > 0)
9393
{
9494
protector = protector?.CreateProtector((IEnumerable<string>)subPurposes);
@@ -111,7 +111,7 @@ public static IDataProtectionProvider GetDataProtectionProvider(this IServicePro
111111

112112
// We have our own implementation of GetRequiredService<T> since we don't want to
113113
// take a dependency on DependencyInjection.Interfaces.
114-
IDataProtectionProvider provider = (IDataProtectionProvider)services.GetService(typeof(IDataProtectionProvider));
114+
var provider = (IDataProtectionProvider?)services.GetService(typeof(IDataProtectionProvider));
115115
if (provider == null)
116116
{
117117
throw new InvalidOperationException(Resources.FormatDataProtectionExtensions_NoService(typeof(IDataProtectionProvider).FullName));

src/DataProtection/Abstractions/src/Error.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.DataProtection
99
{
1010
internal static class Error
1111
{
12-
public static CryptographicException CryptCommon_GenericError(Exception inner = null)
12+
public static CryptographicException CryptCommon_GenericError(Exception? inner = null)
1313
{
1414
return new CryptographicException(Resources.CryptCommon_GenericError, inner);
1515
}

src/DataProtection/Abstractions/src/Microsoft.AspNetCore.DataProtection.Abstractions.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<Description>ASP.NET Core data protection abstractions.
@@ -9,6 +9,7 @@ Microsoft.AspNetCore.DataProtection.IDataProtector</Description>
99
<IsAspNetCoreApp>true</IsAspNetCoreApp>
1010
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1111
<PackageTags>aspnetcore;dataprotection</PackageTags>
12+
<Nullable>enable</Nullable>
1213
</PropertyGroup>
1314

1415
<ItemGroup>

src/DataProtection/Cryptography.Internal/ref/Microsoft.AspNetCore.Cryptography.Internal.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<PropertyGroup>
44
<TargetFrameworks>netstandard2.0;$(DefaultNetCoreTargetFramework)</TargetFrameworks>
55
<TargetFrameworks Condition="'$(DotNetBuildFromSource)' == 'true'">$(DefaultNetCoreTargetFramework)</TargetFrameworks>
6+
<Nullable>annotations</Nullable>
67
</PropertyGroup>
78
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
89
<Compile Include="Microsoft.AspNetCore.Cryptography.Internal.netstandard2.0.cs" />

src/DataProtection/Cryptography.Internal/src/CryptoUtil.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Diagnostics;
6+
using System.Diagnostics.CodeAnalysis;
67
using System.Runtime.CompilerServices;
78
using System.Runtime.ConstrainedExecution;
89
using System.Runtime.InteropServices;
@@ -16,7 +17,7 @@ internal unsafe static class CryptoUtil
1617
{
1718
// This isn't a typical Debug.Assert; the check is always performed, even in retail builds.
1819
[MethodImpl(MethodImplOptions.AggressiveInlining)]
19-
public static void Assert(bool condition, string message)
20+
public static void Assert([DoesNotReturnIf(false)] bool condition, string message)
2021
{
2122
if (!condition)
2223
{

src/DataProtection/Cryptography.Internal/src/Microsoft.AspNetCore.Cryptography.Internal.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<Description>Infrastructure for ASP.NET Core cryptographic packages. Applications and libraries should not reference this package directly.</Description>
@@ -8,6 +8,7 @@
88
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
99
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1010
<PackageTags>aspnetcore;dataprotection</PackageTags>
11+
<Nullable>annotations</Nullable>
1112
</PropertyGroup>
1213

1314
</Project>

src/DataProtection/Cryptography.KeyDerivation/ref/Microsoft.AspNetCore.Cryptography.KeyDerivation.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<PropertyGroup>
44
<TargetFrameworks>netstandard2.0;$(DefaultNetCoreTargetFramework)</TargetFrameworks>
55
<TargetFrameworks Condition="'$(DotNetBuildFromSource)' == 'true'">$(DefaultNetCoreTargetFramework)</TargetFrameworks>
6+
<Nullable>annotations</Nullable>
67
</PropertyGroup>
78
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
89
<Compile Include="Microsoft.AspNetCore.Cryptography.KeyDerivation.netstandard2.0.cs" />

src/DataProtection/Cryptography.KeyDerivation/src/Microsoft.AspNetCore.Cryptography.KeyDerivation.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<Description>ASP.NET Core utilities for key derivation.</Description>
@@ -7,6 +7,8 @@
77
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
88
<GenerateDocumentationFile>true</GenerateDocumentationFile>
99
<PackageTags>aspnetcore;dataprotection</PackageTags>
10+
<Nullable>enable</Nullable>
11+
<Nullable Condition="'$(TargetFramework)' == 'netstandard2.0'">annotations</Nullable>
1012
</PropertyGroup>
1113

1214
<ItemGroup>

src/DataProtection/DataProtection/ref/Microsoft.AspNetCore.DataProtection.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<PropertyGroup>
44
<TargetFrameworks>netstandard2.0;$(DefaultNetCoreTargetFramework)</TargetFrameworks>
55
<TargetFrameworks Condition="'$(DotNetBuildFromSource)' == 'true'">$(DefaultNetCoreTargetFramework)</TargetFrameworks>
6+
<Nullable>annotations</Nullable>
67
</PropertyGroup>
78
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
89
<Compile Include="Microsoft.AspNetCore.DataProtection.netstandard2.0.cs" />

0 commit comments

Comments
 (0)