Skip to content

Commit 2c2074b

Browse files
authored
Refactor DataProtection trimming (#41650)
1 parent 1230a1a commit 2c2074b

30 files changed

+125
-91
lines changed

src/DataProtection/Abstractions/src/DataProtectionCommonExtensions.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ public static IDataProtector GetDataProtector(this IServiceProvider services, st
183183
/// <param name="protector">The data protector to use for this operation.</param>
184184
/// <param name="plaintext">The plaintext data to protect.</param>
185185
/// <returns>The protected form of the plaintext data.</returns>
186-
[RequiresUnreferencedCode(TrimmerWarning.Message)]
187186
public static string Protect(this IDataProtector protector, string plaintext)
188187
{
189188
if (protector == null)
@@ -218,7 +217,6 @@ public static string Protect(this IDataProtector protector, string plaintext)
218217
/// <exception cref="System.Security.Cryptography.CryptographicException">
219218
/// Thrown if <paramref name="protectedData"/> is invalid or malformed.
220219
/// </exception>
221-
[RequiresUnreferencedCode(TrimmerWarning.Message)]
222220
public static string Unprotect(this IDataProtector protector, string protectedData)
223221
{
224222
if (protector == null)

src/DataProtection/Abstractions/src/IDataProtector.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ public interface IDataProtector : IDataProtectionProvider
1515
/// </summary>
1616
/// <param name="plaintext">The plaintext data to protect.</param>
1717
/// <returns>The protected form of the plaintext data.</returns>
18-
[RequiresUnreferencedCode(TrimmerWarning.Message)]
1918
byte[] Protect(byte[] plaintext);
2019

2120
/// <summary>
@@ -26,6 +25,5 @@ public interface IDataProtector : IDataProtectionProvider
2625
/// <exception cref="System.Security.Cryptography.CryptographicException">
2726
/// Thrown if the protected data is invalid or malformed.
2827
/// </exception>
29-
[RequiresUnreferencedCode(TrimmerWarning.Message)]
3028
byte[] Unprotect(byte[] protectedData);
3129
}

src/DataProtection/DataProtection/src/ActivatorExtensions.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ internal static class ActivatorExtensions
1818
/// Creates an instance of <paramref name="implementationTypeName"/> and ensures
1919
/// that it is assignable to <typeparamref name="T"/>.
2020
/// </summary>
21-
[RequiresUnreferencedCode(TrimmerWarning.Message)]
22-
public static T CreateInstance<T>(this IActivator activator, string implementationTypeName)
21+
public static T CreateInstance<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>(this IActivator activator, string implementationTypeName)
2322
where T : class
2423
{
2524
if (implementationTypeName == null)

src/DataProtection/DataProtection/src/AuthenticatedEncryption/ConfigurationModel/AuthenticatedEncryptorDescriptorDeserializer.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public sealed class AuthenticatedEncryptorDescriptorDeserializer : IAuthenticate
1717
/// <summary>
1818
/// Imports the <see cref="AuthenticatedEncryptorDescriptor"/> from serialized XML.
1919
/// </summary>
20-
[RequiresUnreferencedCode(TrimmerWarning.Message)]
2120
public IAuthenticatedEncryptorDescriptor ImportFromXml(XElement element)
2221
{
2322
if (element == null)

src/DataProtection/DataProtection/src/AuthenticatedEncryption/ConfigurationModel/CngCbcAuthenticatedEncryptorDescriptorDeserializer.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public sealed class CngCbcAuthenticatedEncryptorDescriptorDeserializer : IAuthen
1818
/// <summary>
1919
/// Imports the <see cref="CngCbcAuthenticatedEncryptorDescriptor"/> from serialized XML.
2020
/// </summary>
21-
[RequiresUnreferencedCode(TrimmerWarning.Message)]
2221
public IAuthenticatedEncryptorDescriptor ImportFromXml(XElement element)
2322
{
2423
if (element == null)

src/DataProtection/DataProtection/src/AuthenticatedEncryption/ConfigurationModel/CngGcmAuthenticatedEncryptorDescriptorDeserializer.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public sealed class CngGcmAuthenticatedEncryptorDescriptorDeserializer : IAuthen
1818
/// <summary>
1919
/// Imports the <see cref="CngCbcAuthenticatedEncryptorDescriptor"/> from serialized XML.
2020
/// </summary>
21-
[RequiresUnreferencedCode(TrimmerWarning.Message)]
2221
public IAuthenticatedEncryptorDescriptor ImportFromXml(XElement element)
2322
{
2423
if (element == null)

src/DataProtection/DataProtection/src/AuthenticatedEncryption/ConfigurationModel/IAuthenticatedEncryptorDescriptorDeserializer.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,5 @@ public interface IAuthenticatedEncryptorDescriptorDeserializer
1616
/// </summary>
1717
/// <param name="element">The element to deserialize.</param>
1818
/// <returns>The <see cref="IAuthenticatedEncryptorDescriptor"/> represented by <paramref name="element"/>.</returns>
19-
[RequiresUnreferencedCode(TrimmerWarning.Message)]
2019
IAuthenticatedEncryptorDescriptor ImportFromXml(XElement element);
2120
}

src/DataProtection/DataProtection/src/AuthenticatedEncryption/ConfigurationModel/ManagedAuthenticatedEncryptorDescriptorDeserializer.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public sealed class ManagedAuthenticatedEncryptorDescriptorDeserializer : IAuthe
1717
/// <summary>
1818
/// Imports the <see cref="ManagedAuthenticatedEncryptorDescriptor"/> from serialized XML.
1919
/// </summary>
20-
[RequiresUnreferencedCode(TrimmerWarning.Message)]
2120
public IAuthenticatedEncryptorDescriptor ImportFromXml(XElement element)
2221
{
2322
if (element == null)
@@ -48,7 +47,6 @@ public IAuthenticatedEncryptorDescriptor ImportFromXml(XElement element)
4847

4948
// Any changes to this method should also be be reflected
5049
// in ManagedAuthenticatedEncryptorDescriptor.TypeToFriendlyName.
51-
[RequiresUnreferencedCode(TrimmerWarning.Message)]
5250
private static Type FriendlyNameToType(string typeName)
5351
{
5452
if (typeName == nameof(Aes))
@@ -73,7 +71,7 @@ private static Type FriendlyNameToType(string typeName)
7371
}
7472
else
7573
{
76-
return Type.GetType(typeName, throwOnError: true)!;
74+
return TypeExtensions.GetTypeWithTrimFriendlyErrorMessage(typeName);
7775
}
7876
}
7977
}

src/DataProtection/DataProtection/src/EphemeralDataProtectionProvider.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ public EphemeralKeyRing(ILoggerFactory loggerFactory)
9595
return (keyId == default(Guid)) ? DefaultAuthenticatedEncryptor : null;
9696
}
9797

98-
[RequiresUnreferencedCode(TrimmerWarning.Message)]
9998
public IKeyRing GetCurrentKeyRing()
10099
{
101100
return this;

src/DataProtection/DataProtection/src/IPersistedDataProtector.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,5 @@ public interface IPersistedDataProtector : IDataProtector
3131
/// Implementations should throw CryptographicException if the protected data is
3232
/// invalid or malformed.
3333
/// </remarks>
34-
[RequiresUnreferencedCode(TrimmerWarning.Message)]
3534
byte[] DangerousUnprotect(byte[] protectedData, bool ignoreRevocationErrors, out bool requiresMigration, out bool wasRevoked);
3635
}

0 commit comments

Comments
 (0)