diff --git a/src/DataProtection/DataProtection/src/EphemeralDataProtectionProvider.cs b/src/DataProtection/DataProtection/src/EphemeralDataProtectionProvider.cs index 348a41b92521..a2f67609656f 100644 --- a/src/DataProtection/DataProtection/src/EphemeralDataProtectionProvider.cs +++ b/src/DataProtection/DataProtection/src/EphemeralDataProtectionProvider.cs @@ -4,7 +4,6 @@ using System; using System.Diagnostics; using System.Runtime.InteropServices; -using System.Runtime.Versioning; using Microsoft.AspNetCore.Cryptography.Cng; using Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption; using Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel; @@ -85,9 +84,6 @@ public EphemeralKeyRing(ILoggerFactory loggerFactory) DefaultAuthenticatedEncryptor = GetDefaultEncryptor(loggerFactory); } - // Currently hardcoded to a 512-bit KDK. - private const int NUM_BYTES_IN_KDK = 512 / 8; - public IAuthenticatedEncryptor? DefaultAuthenticatedEncryptor { get; } public Guid DefaultKeyId { get; } = default(Guid); diff --git a/src/DataProtection/DataProtection/src/Managed/ManagedAuthenticatedEncryptor.cs b/src/DataProtection/DataProtection/src/Managed/ManagedAuthenticatedEncryptor.cs index d9c806fa362c..c00ff06fcaf6 100644 --- a/src/DataProtection/DataProtection/src/Managed/ManagedAuthenticatedEncryptor.cs +++ b/src/DataProtection/DataProtection/src/Managed/ManagedAuthenticatedEncryptor.cs @@ -69,7 +69,7 @@ public ManagedAuthenticatedEncryptor(Secret keyDerivationKey, Func(); var EMPTY_ARRAY_SEGMENT = new ArraySegment(EMPTY_ARRAY); var retVal = new byte[checked( diff --git a/src/DataProtection/DataProtection/src/SimpleActivator.cs b/src/DataProtection/DataProtection/src/SimpleActivator.cs index cbcba6bf7632..78a421e3d515 100644 --- a/src/DataProtection/DataProtection/src/SimpleActivator.cs +++ b/src/DataProtection/DataProtection/src/SimpleActivator.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Reflection; using Microsoft.AspNetCore.DataProtection.Internal; namespace Microsoft.AspNetCore.DataProtection @@ -13,6 +12,8 @@ namespace Microsoft.AspNetCore.DataProtection /// internal class SimpleActivator : IActivator { + private static readonly Type[] _serviceProviderTypeArray = { typeof(IServiceProvider) }; + /// /// A default whose wrapped is null. /// @@ -42,7 +43,7 @@ public virtual object CreateInstance(Type expectedBaseType, string implementatio } // If an IServiceProvider was specified or if .ctor() doesn't exist, prefer .ctor(IServiceProvider) [if it exists] - var ctorWhichTakesServiceProvider = implementationType.GetConstructor(new Type[] { typeof(IServiceProvider) }); + var ctorWhichTakesServiceProvider = implementationType.GetConstructor(_serviceProviderTypeArray); if (ctorWhichTakesServiceProvider != null) { return ctorWhichTakesServiceProvider.Invoke(new[] { _services }); diff --git a/src/DataProtection/DataProtection/src/XmlEncryption/EncryptedXmlDecryptor.cs b/src/DataProtection/DataProtection/src/XmlEncryption/EncryptedXmlDecryptor.cs index b913dd465353..2144e2ece62e 100644 --- a/src/DataProtection/DataProtection/src/XmlEncryption/EncryptedXmlDecryptor.cs +++ b/src/DataProtection/DataProtection/src/XmlEncryption/EncryptedXmlDecryptor.cs @@ -59,7 +59,6 @@ public XElement Decrypt(XElement encryptedElement) // doesn't handle encrypting the root element all that well. var xmlDocument = new XmlDocument(); xmlDocument.Load(new XElement("root", encryptedElement).CreateReader()); - var elementToDecrypt = (XmlElement)xmlDocument.DocumentElement!.FirstChild!; // Perform the decryption and update the document in-place. var encryptedXml = new EncryptedXmlWithCertificateKeys(_options, xmlDocument); @@ -68,7 +67,7 @@ public XElement Decrypt(XElement encryptedElement) encryptedXml.DecryptDocument(); // Strip the element back off and convert the XmlDocument to an XElement. - return XElement.Load(xmlDocument.DocumentElement.FirstChild!.CreateNavigator()!.ReadSubtree()); + return XElement.Load(xmlDocument.DocumentElement!.FirstChild!.CreateNavigator()!.ReadSubtree()); } void IInternalEncryptedXmlDecryptor.PerformPreDecryptionSetup(EncryptedXml encryptedXml) diff --git a/src/Shared/WebEncoders/WebEncoders.cs b/src/Shared/WebEncoders/WebEncoders.cs index 244453e0b58c..ccad3bfc9379 100644 --- a/src/Shared/WebEncoders/WebEncoders.cs +++ b/src/Shared/WebEncoders/WebEncoders.cs @@ -404,22 +404,6 @@ private static int Base64UrlEncode(ReadOnlySpan input, Span output) } #endif - private static int GetNumBase64PaddingCharsInString(string str) - { - // Assumption: input contains a well-formed base64 string with no whitespace. - - // base64 guaranteed have 0 - 2 padding characters. - if (str[str.Length - 1] == '=') - { - if (str[str.Length - 2] == '=') - { - return 2; - } - return 1; - } - return 0; - } - private static int GetNumBase64PaddingCharsToAddForDecode(int inputLength) { switch (inputLength % 4)