Skip to content

Commit ba16200

Browse files
committed
Add nullable to DataProtection
1 parent c1a3a2f commit ba16200

24 files changed

+39
-26
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" />

src/DataProtection/DataProtection/ref/Microsoft.AspNetCore.DataProtection.netcoreapp.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ public virtual void StoreElement(System.Xml.Linq.XElement element, string friend
323323
}
324324
public partial interface IXmlRepository
325325
{
326-
System.Collections.Generic.IReadOnlyCollection<System.Xml.Linq.XElement> GetAllElements();
326+
System.Collections.Generic.IReadOnlyCollection<System.Xml.Linq.XElement?> GetAllElements();
327327
void StoreElement(System.Xml.Linq.XElement element, string friendlyName);
328328
}
329329
public partial class RegistryXmlRepository : Microsoft.AspNetCore.DataProtection.Repositories.IXmlRepository

src/DataProtection/DataProtection/ref/Microsoft.AspNetCore.DataProtection.netstandard2.0.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ public virtual void StoreElement(System.Xml.Linq.XElement element, string friend
323323
}
324324
public partial interface IXmlRepository
325325
{
326-
System.Collections.Generic.IReadOnlyCollection<System.Xml.Linq.XElement> GetAllElements();
326+
System.Collections.Generic.IReadOnlyCollection<System.Xml.Linq.XElement?> GetAllElements();
327327
void StoreElement(System.Xml.Linq.XElement element, string friendlyName);
328328
}
329329
public partial class RegistryXmlRepository : Microsoft.AspNetCore.DataProtection.Repositories.IXmlRepository

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1010
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1111
<PackageTags>aspnetcore;dataprotection</PackageTags>
12+
<Nullable>annotations</Nullable>
1213
</PropertyGroup>
1314

1415
<ItemGroup>

src/DataProtection/DataProtection/src/Repositories/IXmlRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public interface IXmlRepository
1818
/// <remarks>
1919
/// All top-level elements in the repository.
2020
/// </remarks>
21-
IReadOnlyCollection<XElement> GetAllElements();
21+
IReadOnlyCollection<XElement?> GetAllElements();
2222

2323
/// <summary>
2424
/// Adds a top-level XML element to the repository.

src/DataProtection/EntityFrameworkCore/src/DataProtectionKey.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
namespace Microsoft.AspNetCore.DataProtection.EntityFrameworkCore
@@ -16,11 +16,11 @@ public class DataProtectionKey
1616
/// <summary>
1717
/// The friendly name of the <see cref="DataProtectionKey"/>.
1818
/// </summary>
19-
public string FriendlyName { get; set; }
19+
public string? FriendlyName { get; set; }
2020

2121
/// <summary>
2222
/// The XML representation of the <see cref="DataProtectionKey"/>.
2323
/// </summary>
24-
public string Xml { get; set; }
24+
public string? Xml { get; set; }
2525
}
2626
}

src/DataProtection/EntityFrameworkCore/src/EntityFrameworkCoreXmlRepository.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ public EntityFrameworkCoreXmlRepository(IServiceProvider services, ILoggerFactor
3838
}
3939

4040
/// <inheritdoc />
41-
public virtual IReadOnlyCollection<XElement> GetAllElements()
41+
public virtual IReadOnlyCollection<XElement?> GetAllElements()
4242
{
4343
using (var scope = _services.CreateScope())
4444
{
4545
var context = scope.ServiceProvider.GetRequiredService<TContext>();
4646

4747
// Put logger in a local such that `this` isn't captured.
4848
var logger = _logger;
49-
return context.DataProtectionKeys.AsNoTracking().Select(key => TryParseKeyXml(key.Xml, logger)).ToList().AsReadOnly();
49+
return context.DataProtectionKeys.AsNoTracking().Select(key => TryParseKeyXml(key.Xml!, logger)).ToList().AsReadOnly();
5050
}
5151
}
5252

@@ -68,7 +68,7 @@ public void StoreElement(XElement element, string friendlyName)
6868
}
6969
}
7070

71-
private static XElement TryParseKeyXml(string xml, ILogger logger)
71+
private static XElement? TryParseKeyXml(string xml, ILogger logger)
7272
{
7373
try
7474
{

src/DataProtection/EntityFrameworkCore/src/LoggingExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
@@ -7,8 +7,8 @@ namespace Microsoft.Extensions.Logging
77
{
88
internal static class LoggingExtensions
99
{
10-
private static readonly Action<ILogger, string, Exception> _anExceptionOccurredWhileParsingKeyXml;
11-
private static readonly Action<ILogger, string, string, Exception> _savingKeyToDbContext;
10+
private static readonly Action<ILogger, string, Exception?> _anExceptionOccurredWhileParsingKeyXml;
11+
private static readonly Action<ILogger, string, string, Exception?> _savingKeyToDbContext;
1212

1313
static LoggingExtensions()
1414
{

src/DataProtection/EntityFrameworkCore/src/Microsoft.AspNetCore.DataProtection.EntityFrameworkCore.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>Support for storing keys using Entity Framework Core.</Description>
@@ -7,6 +7,7 @@
77
<GenerateDocumentationFile>true</GenerateDocumentationFile>
88
<PackageTags>aspnetcore;dataprotection;entityframeworkcore</PackageTags>
99
<IsPackable>true</IsPackable>
10+
<Nullable>enable</Nullable>
1011
</PropertyGroup>
1112

1213
<ItemGroup>

src/DataProtection/Extensions/ref/Microsoft.AspNetCore.DataProtection.Extensions.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.Extensions.netstandard2.0.cs" />

src/DataProtection/Extensions/src/DataProtectionProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ public static IDataProtectionProvider Create(
151151
}
152152

153153
internal static IDataProtectionProvider CreateProvider(
154-
DirectoryInfo keyDirectory,
154+
DirectoryInfo? keyDirectory,
155155
Action<IDataProtectionBuilder> setupAction,
156-
X509Certificate2 certificate)
156+
X509Certificate2? certificate)
157157
{
158158
// build the service collection
159159
var serviceCollection = new ServiceCollection();

src/DataProtection/Extensions/src/Microsoft.AspNetCore.DataProtection.Extensions.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>Additional APIs for ASP.NET Core data protection.</Description>
@@ -7,6 +7,7 @@
77
<IsAspNetCoreApp>true</IsAspNetCoreApp>
88
<GenerateDocumentationFile>true</GenerateDocumentationFile>
99
<PackageTags>aspnetcore;dataprotection</PackageTags>
10+
<Nullable>enable</Nullable>
1011
</PropertyGroup>
1112

1213
<ItemGroup>

src/DataProtection/Extensions/src/TimeLimitedDataProtector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ internal sealed class TimeLimitedDataProtector : ITimeLimitedDataProtector
1717
private const string MyPurposeString = "Microsoft.AspNetCore.DataProtection.TimeLimitedDataProtector.v1";
1818

1919
private readonly IDataProtector _innerProtector;
20-
private IDataProtector _innerProtectorWithTimeLimitedPurpose; // created on-demand
20+
private IDataProtector? _innerProtectorWithTimeLimitedPurpose; // created on-demand
2121

2222
public TimeLimitedDataProtector(IDataProtector innerProtector)
2323
{

src/DataProtection/StackExchangeRedis/src/Microsoft.AspNetCore.DataProtection.StackExchangeRedis.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>Support for storing data protection keys in Redis.</Description>
@@ -7,6 +7,7 @@
77
<GenerateDocumentationFile>true</GenerateDocumentationFile>
88
<PackageTags>aspnetcore;dataprotection;redis</PackageTags>
99
<IsPackable>true</IsPackable>
10+
<Nullable>enable</Nullable>
1011
</PropertyGroup>
1112

1213
<ItemGroup>

src/Shared/WebEncoders/WebEncoders.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
#nullable enable
5-
65
using System;
76
#if NETCOREAPP
87
using System.Buffers;

0 commit comments

Comments
 (0)