diff --git a/src/libraries/Microsoft.Extensions.Configuration.Xml/ref/Microsoft.Extensions.Configuration.Xml.cs b/src/libraries/Microsoft.Extensions.Configuration.Xml/ref/Microsoft.Extensions.Configuration.Xml.cs index a9cfb3bb3a5f27..889044c1071661 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Xml/ref/Microsoft.Extensions.Configuration.Xml.cs +++ b/src/libraries/Microsoft.Extensions.Configuration.Xml/ref/Microsoft.Extensions.Configuration.Xml.cs @@ -9,28 +9,36 @@ namespace Microsoft.Extensions.Configuration public static partial class XmlConfigurationExtensions { [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("Microsoft.Extensions.Configuration.Xml can use EncryptedXml which may contain XSLTs in the xml. XSLTs require dynamic code.")] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Microsoft.Extensions.Configuration.Xml can use EncryptedXml. If you use encrypted XML files, your application might not have the algorithm implementations it needs. To avoid this problem, one option you can use is a DynamicDependency attribute to keep the algorithm implementations in your application.")] public static Microsoft.Extensions.Configuration.IConfigurationBuilder AddXmlFile(this Microsoft.Extensions.Configuration.IConfigurationBuilder builder, Microsoft.Extensions.FileProviders.IFileProvider? provider, string path, bool optional, bool reloadOnChange) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("Microsoft.Extensions.Configuration.Xml can use EncryptedXml which may contain XSLTs in the xml. XSLTs require dynamic code.")] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Microsoft.Extensions.Configuration.Xml can use EncryptedXml. If you use encrypted XML files, your application might not have the algorithm implementations it needs. To avoid this problem, one option you can use is a DynamicDependency attribute to keep the algorithm implementations in your application.")] public static Microsoft.Extensions.Configuration.IConfigurationBuilder AddXmlFile(this Microsoft.Extensions.Configuration.IConfigurationBuilder builder, System.Action? configureSource) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("Microsoft.Extensions.Configuration.Xml can use EncryptedXml which may contain XSLTs in the xml. XSLTs require dynamic code.")] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Microsoft.Extensions.Configuration.Xml can use EncryptedXml. If you use encrypted XML files, your application might not have the algorithm implementations it needs. To avoid this problem, one option you can use is a DynamicDependency attribute to keep the algorithm implementations in your application.")] public static Microsoft.Extensions.Configuration.IConfigurationBuilder AddXmlFile(this Microsoft.Extensions.Configuration.IConfigurationBuilder builder, string path) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("Microsoft.Extensions.Configuration.Xml can use EncryptedXml which may contain XSLTs in the xml. XSLTs require dynamic code.")] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Microsoft.Extensions.Configuration.Xml can use EncryptedXml. If you use encrypted XML files, your application might not have the algorithm implementations it needs. To avoid this problem, one option you can use is a DynamicDependency attribute to keep the algorithm implementations in your application.")] public static Microsoft.Extensions.Configuration.IConfigurationBuilder AddXmlFile(this Microsoft.Extensions.Configuration.IConfigurationBuilder builder, string path, bool optional) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("Microsoft.Extensions.Configuration.Xml can use EncryptedXml which may contain XSLTs in the xml. XSLTs require dynamic code.")] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Microsoft.Extensions.Configuration.Xml can use EncryptedXml. If you use encrypted XML files, your application might not have the algorithm implementations it needs. To avoid this problem, one option you can use is a DynamicDependency attribute to keep the algorithm implementations in your application.")] public static Microsoft.Extensions.Configuration.IConfigurationBuilder AddXmlFile(this Microsoft.Extensions.Configuration.IConfigurationBuilder builder, string path, bool optional, bool reloadOnChange) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("Microsoft.Extensions.Configuration.Xml can use EncryptedXml which may contain XSLTs in the xml. XSLTs require dynamic code.")] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Microsoft.Extensions.Configuration.Xml can use EncryptedXml. If you use encrypted XML files, your application might not have the algorithm implementations it needs. To avoid this problem, one option you can use is a DynamicDependency attribute to keep the algorithm implementations in your application.")] public static Microsoft.Extensions.Configuration.IConfigurationBuilder AddXmlStream(this Microsoft.Extensions.Configuration.IConfigurationBuilder builder, System.IO.Stream stream) { throw null; } } } namespace Microsoft.Extensions.Configuration.Xml { [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("Microsoft.Extensions.Configuration.Xml can use EncryptedXml which may contain XSLTs in the xml. XSLTs require dynamic code.")] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Microsoft.Extensions.Configuration.Xml can use EncryptedXml. If you use encrypted XML files, your application might not have the algorithm implementations it needs. To avoid this problem, one option you can use is a DynamicDependency attribute to keep the algorithm implementations in your application.")] public partial class XmlConfigurationProvider : Microsoft.Extensions.Configuration.FileConfigurationProvider { public XmlConfigurationProvider(Microsoft.Extensions.Configuration.Xml.XmlConfigurationSource source) : base (default(Microsoft.Extensions.Configuration.FileConfigurationSource)) { } public override void Load(System.IO.Stream stream) { } } [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("Microsoft.Extensions.Configuration.Xml can use EncryptedXml which may contain XSLTs in the xml. XSLTs require dynamic code.")] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Microsoft.Extensions.Configuration.Xml can use EncryptedXml. If you use encrypted XML files, your application might not have the algorithm implementations it needs. To avoid this problem, one option you can use is a DynamicDependency attribute to keep the algorithm implementations in your application.")] public partial class XmlConfigurationSource : Microsoft.Extensions.Configuration.FileConfigurationSource { public XmlConfigurationSource() { } @@ -41,12 +49,15 @@ public partial class XmlDocumentDecryptor public static readonly Microsoft.Extensions.Configuration.Xml.XmlDocumentDecryptor Instance; protected XmlDocumentDecryptor() { } [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("Microsoft.Extensions.Configuration.Xml can use EncryptedXml which may contain XSLTs in the xml. XSLTs require dynamic code.")] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Microsoft.Extensions.Configuration.Xml can use EncryptedXml. If you use encrypted XML files, your application might not have the algorithm implementations it needs. To avoid this problem, one option you can use is a DynamicDependency attribute to keep the algorithm implementations in your application.")] public System.Xml.XmlReader CreateDecryptingXmlReader(System.IO.Stream input, System.Xml.XmlReaderSettings? settings) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("Microsoft.Extensions.Configuration.Xml can use EncryptedXml which may contain XSLTs in the xml. XSLTs require dynamic code.")] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Microsoft.Extensions.Configuration.Xml can use EncryptedXml. If you use encrypted XML files, your application might not have the algorithm implementations it needs. To avoid this problem, one option you can use is a DynamicDependency attribute to keep the algorithm implementations in your application.")] [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] protected virtual System.Xml.XmlReader DecryptDocumentAndCreateXmlReader(System.Xml.XmlDocument document) { throw null; } } [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("Microsoft.Extensions.Configuration.Xml can use EncryptedXml which may contain XSLTs in the xml. XSLTs require dynamic code.")] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Microsoft.Extensions.Configuration.Xml can use EncryptedXml. If you use encrypted XML files, your application might not have the algorithm implementations it needs. To avoid this problem, one option you can use is a DynamicDependency attribute to keep the algorithm implementations in your application.")] public partial class XmlStreamConfigurationProvider : Microsoft.Extensions.Configuration.StreamConfigurationProvider { public XmlStreamConfigurationProvider(Microsoft.Extensions.Configuration.Xml.XmlStreamConfigurationSource source) : base (default(Microsoft.Extensions.Configuration.StreamConfigurationSource)) { } @@ -54,6 +65,7 @@ public override void Load(System.IO.Stream stream) { } public static System.Collections.Generic.IDictionary Read(System.IO.Stream stream, Microsoft.Extensions.Configuration.Xml.XmlDocumentDecryptor decryptor) { throw null; } } [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("Microsoft.Extensions.Configuration.Xml can use EncryptedXml which may contain XSLTs in the xml. XSLTs require dynamic code.")] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Microsoft.Extensions.Configuration.Xml can use EncryptedXml. If you use encrypted XML files, your application might not have the algorithm implementations it needs. To avoid this problem, one option you can use is a DynamicDependency attribute to keep the algorithm implementations in your application.")] public partial class XmlStreamConfigurationSource : Microsoft.Extensions.Configuration.StreamConfigurationSource { public XmlStreamConfigurationSource() { } diff --git a/src/libraries/Microsoft.Extensions.Configuration.Xml/ref/Microsoft.Extensions.Configuration.Xml.csproj b/src/libraries/Microsoft.Extensions.Configuration.Xml/ref/Microsoft.Extensions.Configuration.Xml.csproj index 7050e3b94bcf5d..e9f36a80ea65bb 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Xml/ref/Microsoft.Extensions.Configuration.Xml.csproj +++ b/src/libraries/Microsoft.Extensions.Configuration.Xml/ref/Microsoft.Extensions.Configuration.Xml.csproj @@ -7,6 +7,10 @@ + + + + diff --git a/src/libraries/Microsoft.Extensions.Configuration.Xml/src/Microsoft.Extensions.Configuration.Xml.csproj b/src/libraries/Microsoft.Extensions.Configuration.Xml/src/Microsoft.Extensions.Configuration.Xml.csproj index b20d79127ec2c0..7cf288a00eb842 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Xml/src/Microsoft.Extensions.Configuration.Xml.csproj +++ b/src/libraries/Microsoft.Extensions.Configuration.Xml/src/Microsoft.Extensions.Configuration.Xml.csproj @@ -17,6 +17,10 @@ Link="Common\System\ThrowHelper.cs" /> + + + + diff --git a/src/libraries/Microsoft.Extensions.Configuration.Xml/src/XmlConfigurationExtensions.cs b/src/libraries/Microsoft.Extensions.Configuration.Xml/src/XmlConfigurationExtensions.cs index 8b126367451414..716dc553848ac6 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Xml/src/XmlConfigurationExtensions.cs +++ b/src/libraries/Microsoft.Extensions.Configuration.Xml/src/XmlConfigurationExtensions.cs @@ -22,6 +22,7 @@ public static class XmlConfigurationExtensions /// of . /// The . [RequiresDynamicCode(XmlDocumentDecryptor.RequiresDynamicCodeMessage)] + [RequiresUnreferencedCode(XmlDocumentDecryptor.RequiresUnreferencedCodeMessage)] public static IConfigurationBuilder AddXmlFile(this IConfigurationBuilder builder, string path) { return AddXmlFile(builder, provider: null, path: path, optional: false, reloadOnChange: false); @@ -36,6 +37,7 @@ public static IConfigurationBuilder AddXmlFile(this IConfigurationBuilder builde /// Whether the file is optional. /// The . [RequiresDynamicCode(XmlDocumentDecryptor.RequiresDynamicCodeMessage)] + [RequiresUnreferencedCode(XmlDocumentDecryptor.RequiresUnreferencedCodeMessage)] public static IConfigurationBuilder AddXmlFile(this IConfigurationBuilder builder, string path, bool optional) { return AddXmlFile(builder, provider: null, path: path, optional: optional, reloadOnChange: false); @@ -51,6 +53,7 @@ public static IConfigurationBuilder AddXmlFile(this IConfigurationBuilder builde /// Whether the configuration should be reloaded if the file changes. /// The . [RequiresDynamicCode(XmlDocumentDecryptor.RequiresDynamicCodeMessage)] + [RequiresUnreferencedCode(XmlDocumentDecryptor.RequiresUnreferencedCodeMessage)] public static IConfigurationBuilder AddXmlFile(this IConfigurationBuilder builder, string path, bool optional, bool reloadOnChange) { return AddXmlFile(builder, provider: null, path: path, optional: optional, reloadOnChange: reloadOnChange); @@ -67,6 +70,7 @@ public static IConfigurationBuilder AddXmlFile(this IConfigurationBuilder builde /// Whether the configuration should be reloaded if the file changes. /// The . [RequiresDynamicCode(XmlDocumentDecryptor.RequiresDynamicCodeMessage)] + [RequiresUnreferencedCode(XmlDocumentDecryptor.RequiresUnreferencedCodeMessage)] public static IConfigurationBuilder AddXmlFile(this IConfigurationBuilder builder, IFileProvider? provider, string path, bool optional, bool reloadOnChange) { ThrowHelper.ThrowIfNull(builder); @@ -93,6 +97,7 @@ public static IConfigurationBuilder AddXmlFile(this IConfigurationBuilder builde /// Configures the source. /// The . [RequiresDynamicCode(XmlDocumentDecryptor.RequiresDynamicCodeMessage)] + [RequiresUnreferencedCode(XmlDocumentDecryptor.RequiresUnreferencedCodeMessage)] public static IConfigurationBuilder AddXmlFile(this IConfigurationBuilder builder, Action? configureSource) => builder.Add(configureSource); @@ -103,6 +108,7 @@ public static IConfigurationBuilder AddXmlFile(this IConfigurationBuilder builde /// The to read the XML configuration data from. /// The . [RequiresDynamicCode(XmlDocumentDecryptor.RequiresDynamicCodeMessage)] + [RequiresUnreferencedCode(XmlDocumentDecryptor.RequiresUnreferencedCodeMessage)] public static IConfigurationBuilder AddXmlStream(this IConfigurationBuilder builder, Stream stream) { ThrowHelper.ThrowIfNull(builder); diff --git a/src/libraries/Microsoft.Extensions.Configuration.Xml/src/XmlConfigurationProvider.cs b/src/libraries/Microsoft.Extensions.Configuration.Xml/src/XmlConfigurationProvider.cs index bfa1ac45f06fd6..029a24c2a46d2b 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Xml/src/XmlConfigurationProvider.cs +++ b/src/libraries/Microsoft.Extensions.Configuration.Xml/src/XmlConfigurationProvider.cs @@ -10,6 +10,7 @@ namespace Microsoft.Extensions.Configuration.Xml /// Represents an XML file as an . /// [RequiresDynamicCode(XmlDocumentDecryptor.RequiresDynamicCodeMessage)] + [RequiresUnreferencedCode(XmlDocumentDecryptor.RequiresUnreferencedCodeMessage)] public class XmlConfigurationProvider : FileConfigurationProvider { /// diff --git a/src/libraries/Microsoft.Extensions.Configuration.Xml/src/XmlConfigurationSource.cs b/src/libraries/Microsoft.Extensions.Configuration.Xml/src/XmlConfigurationSource.cs index cbeb47c6689e23..e6279095d1178b 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Xml/src/XmlConfigurationSource.cs +++ b/src/libraries/Microsoft.Extensions.Configuration.Xml/src/XmlConfigurationSource.cs @@ -9,6 +9,7 @@ namespace Microsoft.Extensions.Configuration.Xml /// An XML file based . /// [RequiresDynamicCode(XmlDocumentDecryptor.RequiresDynamicCodeMessage)] + [RequiresUnreferencedCode(XmlDocumentDecryptor.RequiresUnreferencedCodeMessage)] public class XmlConfigurationSource : FileConfigurationSource { /// diff --git a/src/libraries/Microsoft.Extensions.Configuration.Xml/src/XmlDocumentDecryptor.cs b/src/libraries/Microsoft.Extensions.Configuration.Xml/src/XmlDocumentDecryptor.cs index 07a09cb82c467d..51bfb352228a83 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Xml/src/XmlDocumentDecryptor.cs +++ b/src/libraries/Microsoft.Extensions.Configuration.Xml/src/XmlDocumentDecryptor.cs @@ -16,6 +16,7 @@ namespace Microsoft.Extensions.Configuration.Xml public class XmlDocumentDecryptor { internal const string RequiresDynamicCodeMessage = "Microsoft.Extensions.Configuration.Xml can use EncryptedXml which may contain XSLTs in the xml. XSLTs require dynamic code."; + internal const string RequiresUnreferencedCodeMessage = "Microsoft.Extensions.Configuration.Xml can use EncryptedXml. If you use encrypted XML files, your application might not have the algorithm implementations it needs. To avoid this problem, one option you can use is a DynamicDependency attribute to keep the algorithm implementations in your application."; /// /// Accesses the singleton decryptor instance. @@ -57,6 +58,7 @@ private static bool ContainsEncryptedData(XmlDocument document) /// The settings for the new instance. /// An that decrypts data transparently. [RequiresDynamicCode(RequiresDynamicCodeMessage)] + [RequiresUnreferencedCode(RequiresUnreferencedCodeMessage)] public XmlReader CreateDecryptingXmlReader(Stream input, XmlReaderSettings? settings) { // XML-based configurations aren't really all that big, so we can buffer @@ -97,6 +99,7 @@ public XmlReader CreateDecryptingXmlReader(Stream input, XmlReaderSettings? sett /// An XmlReader which can read the document. [UnsupportedOSPlatform("browser")] [RequiresDynamicCode(RequiresDynamicCodeMessage)] + [RequiresUnreferencedCode(RequiresUnreferencedCodeMessage)] protected virtual XmlReader DecryptDocumentAndCreateXmlReader(XmlDocument document) { // Perform the actual decryption step, updating the XmlDocument in-place. diff --git a/src/libraries/Microsoft.Extensions.Configuration.Xml/src/XmlStreamConfigurationProvider.cs b/src/libraries/Microsoft.Extensions.Configuration.Xml/src/XmlStreamConfigurationProvider.cs index adf2a0773cc4d8..b2db3ebc0e3286 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Xml/src/XmlStreamConfigurationProvider.cs +++ b/src/libraries/Microsoft.Extensions.Configuration.Xml/src/XmlStreamConfigurationProvider.cs @@ -15,9 +15,14 @@ namespace Microsoft.Extensions.Configuration.Xml /// An XML file based . /// [RequiresDynamicCode(XmlDocumentDecryptor.RequiresDynamicCodeMessage)] + [RequiresUnreferencedCode(XmlDocumentDecryptor.RequiresUnreferencedCodeMessage)] public class XmlStreamConfigurationProvider : StreamConfigurationProvider { - private const string NameAttributeKey = "Name"; + // work around https://github.com/dotnet/runtime/issues/81864 by splitting this into a separate class. + internal static class Consts + { + internal const string NameAttributeKey = "Name"; + } /// /// Constructor. @@ -229,7 +234,7 @@ private static void ReadAttributes(XmlReader reader, XmlConfigurationElement ele while (reader.MoveToNextAttribute()) { - if (string.Equals(reader.LocalName, NameAttributeKey, StringComparison.OrdinalIgnoreCase)) + if (string.Equals(reader.LocalName, Consts.NameAttributeKey, StringComparison.OrdinalIgnoreCase)) { // If there is a namespace attached to current attribute if (!string.IsNullOrEmpty(reader.NamespaceURI)) diff --git a/src/libraries/Microsoft.Extensions.Configuration.Xml/src/XmlStreamConfigurationSource.cs b/src/libraries/Microsoft.Extensions.Configuration.Xml/src/XmlStreamConfigurationSource.cs index 70a39a35c4c158..8bcaee5554573e 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Xml/src/XmlStreamConfigurationSource.cs +++ b/src/libraries/Microsoft.Extensions.Configuration.Xml/src/XmlStreamConfigurationSource.cs @@ -9,6 +9,7 @@ namespace Microsoft.Extensions.Configuration.Xml /// Represents a XML file as an . /// [RequiresDynamicCode(XmlDocumentDecryptor.RequiresDynamicCodeMessage)] + [RequiresUnreferencedCode(XmlDocumentDecryptor.RequiresUnreferencedCodeMessage)] public class XmlStreamConfigurationSource : StreamConfigurationSource { /// diff --git a/src/libraries/System.Security.Cryptography.Xml/ref/System.Security.Cryptography.Xml.cs b/src/libraries/System.Security.Cryptography.Xml/ref/System.Security.Cryptography.Xml.cs index b7412aaded369a..51c9221900827f 100644 --- a/src/libraries/System.Security.Cryptography.Xml/ref/System.Security.Cryptography.Xml.cs +++ b/src/libraries/System.Security.Cryptography.Xml/ref/System.Security.Cryptography.Xml.cs @@ -17,6 +17,7 @@ public CipherData(System.Security.Cryptography.Xml.CipherReference cipherReferen public byte[]? CipherValue { get { throw null; } set { } } public System.Xml.XmlElement GetXml() { throw null; } [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("XmlDsigXsltTransform uses XslCompiledTransform which requires dynamic code.")] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The algorithm implementations referenced in the XML payload might be removed. Ensure the required algorithm implementations are preserved in your application.")] public void LoadXml(System.Xml.XmlElement value) { } } public sealed partial class CipherReference : System.Security.Cryptography.Xml.EncryptedReference @@ -26,6 +27,7 @@ public CipherReference(string uri) { } public CipherReference(string uri, System.Security.Cryptography.Xml.TransformChain transformChain) { } public override System.Xml.XmlElement GetXml() { throw null; } [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("XmlDsigXsltTransform uses XslCompiledTransform which requires dynamic code.")] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The algorithm implementations referenced in the XML payload might be removed. Ensure the required algorithm implementations are preserved in your application.")] public override void LoadXml(System.Xml.XmlElement value) { } } public partial class DataObject @@ -60,6 +62,7 @@ public sealed partial class EncryptedData : System.Security.Cryptography.Xml.Enc public EncryptedData() { } public override System.Xml.XmlElement GetXml() { throw null; } [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("XmlDsigXsltTransform uses XslCompiledTransform which requires dynamic code.")] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The algorithm implementations referenced in the XML payload might be removed. Ensure the required algorithm implementations are preserved in your application.")] public override void LoadXml(System.Xml.XmlElement value) { } } public sealed partial class EncryptedKey : System.Security.Cryptography.Xml.EncryptedType @@ -73,6 +76,7 @@ public void AddReference(System.Security.Cryptography.Xml.DataReference dataRefe public void AddReference(System.Security.Cryptography.Xml.KeyReference keyReference) { } public override System.Xml.XmlElement GetXml() { throw null; } [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("XmlDsigXsltTransform uses XslCompiledTransform which requires dynamic code.")] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The algorithm implementations referenced in the XML payload might be removed. Ensure the required algorithm implementations are preserved in your application.")] public override void LoadXml(System.Xml.XmlElement value) { } } public abstract partial class EncryptedReference @@ -87,6 +91,7 @@ protected EncryptedReference(string uri, System.Security.Cryptography.Xml.Transf public void AddTransform(System.Security.Cryptography.Xml.Transform transform) { } public virtual System.Xml.XmlElement GetXml() { throw null; } [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("XmlDsigXsltTransform uses XslCompiledTransform which requires dynamic code.")] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The algorithm implementations referenced in the XML payload might be removed. Ensure the required algorithm implementations are preserved in your application.")] public virtual void LoadXml(System.Xml.XmlElement value) { } } public abstract partial class EncryptedType @@ -104,6 +109,7 @@ protected EncryptedType() { } public void AddProperty(System.Security.Cryptography.Xml.EncryptionProperty ep) { } public abstract System.Xml.XmlElement GetXml(); [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("XmlDsigXsltTransform uses XslCompiledTransform which requires dynamic code.")] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The algorithm implementations referenced in the XML payload might be removed. Ensure the required algorithm implementations are preserved in your application.")] public abstract void LoadXml(System.Xml.XmlElement value); } public partial class EncryptedXml @@ -126,10 +132,13 @@ public partial class EncryptedXml public const string XmlEncTripleDESKeyWrapUrl = "http://www.w3.org/2001/04/xmlenc#kw-tripledes"; public const string XmlEncTripleDESUrl = "http://www.w3.org/2001/04/xmlenc#tripledes-cbc"; [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("XmlDsigXsltTransform uses XslCompiledTransform which requires dynamic code.")] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The algorithm implementations referenced in the XML payload might be removed. Ensure the required algorithm implementations are preserved in your application.")] public EncryptedXml() { } [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("XmlDsigXsltTransform uses XslCompiledTransform which requires dynamic code.")] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The algorithm implementations referenced in the XML payload might be removed. Ensure the required algorithm implementations are preserved in your application.")] public EncryptedXml(System.Xml.XmlDocument document) { } [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("XmlDsigXsltTransform uses XslCompiledTransform which requires dynamic code.")] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The algorithm implementations referenced in the XML payload might be removed. Ensure the required algorithm implementations are preserved in your application.")] public EncryptedXml(System.Xml.XmlDocument document, System.Security.Policy.Evidence? evidence) { } public System.Security.Policy.Evidence? DocumentEvidence { get { throw null; } set { } } public System.Text.Encoding Encoding { get { throw null; } set { } } @@ -219,6 +228,7 @@ public void AddClause(System.Security.Cryptography.Xml.KeyInfoClause clause) { } public System.Collections.IEnumerator GetEnumerator() { throw null; } public System.Collections.IEnumerator GetEnumerator(System.Type requestedObjectType) { throw null; } public System.Xml.XmlElement GetXml() { throw null; } + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The algorithm implementations referenced in the XML payload might be removed. Ensure the required algorithm implementations are preserved in your application.")] public void LoadXml(System.Xml.XmlElement value) { } } public abstract partial class KeyInfoClause @@ -228,6 +238,7 @@ protected KeyInfoClause() { } public abstract void LoadXml(System.Xml.XmlElement element); } [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("XmlDsigXsltTransform uses XslCompiledTransform which requires dynamic code.")] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The algorithm implementations referenced in the XML payload might be removed. Ensure the required algorithm implementations are preserved in your application.")] public partial class KeyInfoEncryptedKey : System.Security.Cryptography.Xml.KeyInfoClause { public KeyInfoEncryptedKey() { } @@ -301,6 +312,7 @@ public Reference(string? uri) { } public void AddTransform(System.Security.Cryptography.Xml.Transform transform) { } public System.Xml.XmlElement GetXml() { throw null; } [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("XmlDsigXsltTransform uses XslCompiledTransform which requires dynamic code.")] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The algorithm implementations referenced in the XML payload might be removed. Ensure the required algorithm implementations are preserved in your application.")] public void LoadXml(System.Xml.XmlElement value) { } } public sealed partial class ReferenceList : System.Collections.ICollection, System.Collections.IEnumerable, System.Collections.IList @@ -344,9 +356,11 @@ public Signature() { } public void AddObject(System.Security.Cryptography.Xml.DataObject dataObject) { } public System.Xml.XmlElement GetXml() { throw null; } [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("XmlDsigXsltTransform uses XslCompiledTransform which requires dynamic code.")] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The algorithm implementations referenced in the XML payload might be removed. Ensure the required algorithm implementations are preserved in your application.")] public void LoadXml(System.Xml.XmlElement value) { } } [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("XmlDsigXsltTransform uses XslCompiledTransform which requires dynamic code.")] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The algorithm implementations referenced in the XML payload might be removed. Ensure the required algorithm implementations are preserved in your application.")] public partial class SignedInfo : System.Collections.ICollection, System.Collections.IEnumerable { public SignedInfo() { } @@ -396,10 +410,13 @@ public partial class SignedXml public const string XmlDsigXsltTransformUrl = "http://www.w3.org/TR/1999/REC-xslt-19991116"; public const string XmlLicenseTransformUrl = "urn:mpeg:mpeg21:2003:01-REL-R-NS:licenseTransform"; [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("XmlDsigXsltTransform uses XslCompiledTransform which requires dynamic code.")] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The algorithm implementations referenced in the XML payload might be removed. Ensure the required algorithm implementations are preserved in your application.")] public SignedXml() { } [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("XmlDsigXsltTransform uses XslCompiledTransform which requires dynamic code.")] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The algorithm implementations referenced in the XML payload might be removed. Ensure the required algorithm implementations are preserved in your application.")] public SignedXml(System.Xml.XmlDocument document) { } [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("XmlDsigXsltTransform uses XslCompiledTransform which requires dynamic code.")] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The algorithm implementations referenced in the XML payload might be removed. Ensure the required algorithm implementations are preserved in your application.")] public SignedXml(System.Xml.XmlElement elem) { } [System.Diagnostics.CodeAnalysis.AllowNullAttribute] public System.Security.Cryptography.Xml.EncryptedXml EncryptedXml { get { throw null; } set { } } @@ -454,6 +471,7 @@ public void Add(System.Security.Cryptography.Xml.Transform transform) { } public System.Collections.IEnumerator GetEnumerator() { throw null; } } [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("XmlDsigXsltTransform uses XslCompiledTransform which requires dynamic code.")] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The algorithm implementations referenced in the XML payload might be removed. Ensure the required algorithm implementations are preserved in your application.")] public partial class XmlDecryptionTransform : System.Security.Cryptography.Xml.Transform { public XmlDecryptionTransform() { } @@ -554,6 +572,7 @@ public override void LoadInnerXml(System.Xml.XmlNodeList nodeList) { } public override void LoadInput(object obj) { } } [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("XmlDsigXsltTransform uses XslCompiledTransform which requires dynamic code.")] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The algorithm implementations referenced in the XML payload might be removed. Ensure the required algorithm implementations are preserved in your application.")] public partial class XmlLicenseTransform : System.Security.Cryptography.Xml.Transform { public XmlLicenseTransform() { } diff --git a/src/libraries/System.Security.Cryptography.Xml/ref/System.Security.Cryptography.Xml.csproj b/src/libraries/System.Security.Cryptography.Xml/ref/System.Security.Cryptography.Xml.csproj index 899bc64c16e318..3974bdf58e004d 100644 --- a/src/libraries/System.Security.Cryptography.Xml/ref/System.Security.Cryptography.Xml.csproj +++ b/src/libraries/System.Security.Cryptography.Xml/ref/System.Security.Cryptography.Xml.csproj @@ -9,6 +9,10 @@ + + + + diff --git a/src/libraries/System.Security.Cryptography.Xml/src/ILLink/ILLink.Suppressions.xml b/src/libraries/System.Security.Cryptography.Xml/src/ILLink/ILLink.Suppressions.xml deleted file mode 100644 index d1b8e66a585313..00000000000000 --- a/src/libraries/System.Security.Cryptography.Xml/src/ILLink/ILLink.Suppressions.xml +++ /dev/null @@ -1,89 +0,0 @@ - - - - - ILLink - IL2026 - member - M:System.Security.Cryptography.Xml.CryptoHelpers.CreateFromName``1(System.String) - - - ILLink - IL2026 - member - M:System.Security.Cryptography.Xml.DSASignatureDescription.CreateDeformatter(System.Security.Cryptography.AsymmetricAlgorithm) - - - ILLink - IL2026 - member - M:System.Security.Cryptography.Xml.DSASignatureDescription.CreateFormatter(System.Security.Cryptography.AsymmetricAlgorithm) - - - ILLink - IL2026 - member - M:System.Security.Cryptography.Xml.RSAPKCS1SignatureDescription.CreateDeformatter(System.Security.Cryptography.AsymmetricAlgorithm) - - - ILLink - IL2026 - member - M:System.Security.Cryptography.Xml.RSAPKCS1SignatureDescription.CreateFormatter(System.Security.Cryptography.AsymmetricAlgorithm) - - - ILLink - IL2026 - member - M:System.Security.Cryptography.Xml.SignedXml.CheckSignedInfo(System.Security.Cryptography.AsymmetricAlgorithm) - - - ILLink - IL2026 - member - M:System.Security.Cryptography.Xml.SignedXml.ComputeSignature - - - ILLink - IL2046 - member - M:System.Security.Cryptography.Xml.DSASignatureDescription.CreateDeformatter(System.Security.Cryptography.AsymmetricAlgorithm) - - - ILLink - IL2046 - member - M:System.Security.Cryptography.Xml.DSASignatureDescription.CreateDigest - - - ILLink - IL2046 - member - M:System.Security.Cryptography.Xml.DSASignatureDescription.CreateFormatter(System.Security.Cryptography.AsymmetricAlgorithm) - - - ILLink - IL2046 - member - M:System.Security.Cryptography.Xml.RSAPKCS1SignatureDescription.CreateDeformatter(System.Security.Cryptography.AsymmetricAlgorithm) - - - ILLink - IL2046 - member - M:System.Security.Cryptography.Xml.RSAPKCS1SignatureDescription.CreateDigest - - - ILLink - IL2046 - member - M:System.Security.Cryptography.Xml.RSAPKCS1SignatureDescription.CreateFormatter(System.Security.Cryptography.AsymmetricAlgorithm) - - - ILLink - IL2057 - member - M:System.Security.Cryptography.Xml.SignedXml.CheckSignedInfo(System.Security.Cryptography.AsymmetricAlgorithm) - - - \ No newline at end of file diff --git a/src/libraries/System.Security.Cryptography.Xml/src/Resources/Strings.resx b/src/libraries/System.Security.Cryptography.Xml/src/Resources/Strings.resx index 2bd8ecd0fe14bb..924132bd04547e 100644 --- a/src/libraries/System.Security.Cryptography.Xml/src/Resources/Strings.resx +++ b/src/libraries/System.Security.Cryptography.Xml/src/Resources/Strings.resx @@ -136,7 +136,7 @@ A Cipher Data element should have either a CipherValue or a CipherReference element. - Could not create hash algorithm object. + Could not create hash algorithm object. If the application has been trimmed, ensure the required algorithm implementations are preserved. Could not create the XML transformation identified by the URI {0}. @@ -184,7 +184,7 @@ Signing key is not loaded. - Symmetric algorithm is not specified. + Symmetric algorithm is not specified. If the application has been trimmed, ensure the required algorithm implementations are preserved. Cipher data is not specified. diff --git a/src/libraries/System.Security.Cryptography.Xml/src/System.Security.Cryptography.Xml.csproj b/src/libraries/System.Security.Cryptography.Xml/src/System.Security.Cryptography.Xml.csproj index 7d3013c1c01bda..5aea1a156c97a4 100644 --- a/src/libraries/System.Security.Cryptography.Xml/src/System.Security.Cryptography.Xml.csproj +++ b/src/libraries/System.Security.Cryptography.Xml/src/System.Security.Cryptography.Xml.csproj @@ -1,4 +1,4 @@ - + $(NetCoreAppCurrent);$(NetCoreAppPrevious);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum) true @@ -138,6 +138,7 @@ System.Security.Cryptography.Xml.XmlLicenseTransform + diff --git a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/CipherData.cs b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/CipherData.cs index 4e84778c2e7bdc..ebc7b1980d2b2a 100644 --- a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/CipherData.cs +++ b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/CipherData.cs @@ -95,6 +95,7 @@ internal XmlElement GetXml(XmlDocument document) } [RequiresDynamicCode(CryptoHelpers.XsltRequiresDynamicCodeMessage)] + [RequiresUnreferencedCode(CryptoHelpers.CreateFromNameUnreferencedCodeMessage)] public void LoadXml(XmlElement value) { if (value is null) diff --git a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/CipherReference.cs b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/CipherReference.cs index de5033266679e6..14741e3c069892 100644 --- a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/CipherReference.cs +++ b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/CipherReference.cs @@ -67,6 +67,7 @@ public override XmlElement GetXml() } [RequiresDynamicCode(CryptoHelpers.XsltRequiresDynamicCodeMessage)] + [RequiresUnreferencedCode(CryptoHelpers.CreateFromNameUnreferencedCodeMessage)] public override void LoadXml(XmlElement value) { if (value is null) diff --git a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/CryptoHelpers.cs b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/CryptoHelpers.cs index 40cdea30bd3504..6ea4154ca27790 100644 --- a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/CryptoHelpers.cs +++ b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/CryptoHelpers.cs @@ -9,11 +9,13 @@ namespace System.Security.Cryptography.Xml { internal static class CryptoHelpers { + internal const string CreateFromNameUnreferencedCodeMessage = "The algorithm implementations referenced in the XML payload might be removed. Ensure the required algorithm implementations are preserved in your application."; internal const string XsltRequiresDynamicCodeMessage = "XmlDsigXsltTransform uses XslCompiledTransform which requires dynamic code."; private static readonly char[] _invalidChars = new char[] { ',', '`', '[', '*', '&' }; [RequiresDynamicCode(XsltRequiresDynamicCodeMessage)] + [RequiresUnreferencedCode(CreateFromNameUnreferencedCodeMessage)] private static object? CreateFromKnownName(string name) => name switch { @@ -60,6 +62,7 @@ private static XmlDsigXsltTransform CreateXmlDsigXsltTransform() } [RequiresDynamicCode(XsltRequiresDynamicCodeMessage)] + [RequiresUnreferencedCode(CreateFromNameUnreferencedCodeMessage)] public static T? CreateFromName(string? name) where T : class { if (name == null || name.IndexOfAny(_invalidChars) >= 0) @@ -76,6 +79,7 @@ private static XmlDsigXsltTransform CreateXmlDsigXsltTransform() } } + [RequiresUnreferencedCode(CreateFromNameUnreferencedCodeMessage)] [UnconditionalSuppressMessage("AOT", "IL3050:RequiresDynamicCodeAttribute", Justification = "Only XmlDsigXsltTransform requires dynamic code. This method asserts that T is not a Transform.")] public static T? CreateNonTransformFromName(string? name) where T : class diff --git a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/DSASignatureDescription.cs b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/DSASignatureDescription.cs index 2b423e681e0fbc..22b1c4c355a79b 100644 --- a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/DSASignatureDescription.cs +++ b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/DSASignatureDescription.cs @@ -17,6 +17,9 @@ public DSASignatureDescription() DigestAlgorithm = "SHA1"; } +#if NETCOREAPP + [RequiresUnreferencedCode("CreateDeformatter is not trim compatible because the algorithm implementation referenced by DeformatterAlgorithm might be removed.")] +#endif public sealed override AsymmetricSignatureDeformatter CreateDeformatter(AsymmetricAlgorithm key) { var item = (AsymmetricSignatureDeformatter)CryptoConfig.CreateFromName(DeformatterAlgorithm!)!; @@ -25,6 +28,9 @@ public sealed override AsymmetricSignatureDeformatter CreateDeformatter(Asymmetr return item; } +#if NETCOREAPP + [RequiresUnreferencedCode("CreateFormatter is not trim compatible because the algorithm implementation referenced by FormatterAlgorithm might be removed.")] +#endif public sealed override AsymmetricSignatureFormatter CreateFormatter(AsymmetricAlgorithm key) { var item = (AsymmetricSignatureFormatter)CryptoConfig.CreateFromName(FormatterAlgorithm!)!; @@ -34,6 +40,8 @@ public sealed override AsymmetricSignatureFormatter CreateFormatter(AsymmetricAl } [SuppressMessage("Microsoft.Security", "CA5350", Justification = "SHA1 needed for compat.")] + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2046:AnnotationsMustMatchBase", + Justification = "This derived implementation doesn't require unreferenced code, like the base does.")] public sealed override HashAlgorithm CreateDigest() { return SHA1.Create(); diff --git a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/EncryptedData.cs b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/EncryptedData.cs index df2c077483b4ae..3de83fe10ebc08 100644 --- a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/EncryptedData.cs +++ b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/EncryptedData.cs @@ -9,6 +9,7 @@ namespace System.Security.Cryptography.Xml public sealed class EncryptedData : EncryptedType { [RequiresDynamicCode(CryptoHelpers.XsltRequiresDynamicCodeMessage)] + [RequiresUnreferencedCode(CryptoHelpers.CreateFromNameUnreferencedCodeMessage)] public override void LoadXml(XmlElement value) { if (value is null) diff --git a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/EncryptedKey.cs b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/EncryptedKey.cs index 3a46f0e5bf07cd..3cd2a7bc0a35ee 100644 --- a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/EncryptedKey.cs +++ b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/EncryptedKey.cs @@ -48,6 +48,7 @@ public void AddReference(KeyReference keyReference) } [RequiresDynamicCode(CryptoHelpers.XsltRequiresDynamicCodeMessage)] + [RequiresUnreferencedCode(CryptoHelpers.CreateFromNameUnreferencedCodeMessage)] public override void LoadXml(XmlElement value) { if (value is null) diff --git a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/EncryptedReference.cs b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/EncryptedReference.cs index 81ccbce3b702e0..159bc6ac0b5ea9 100644 --- a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/EncryptedReference.cs +++ b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/EncryptedReference.cs @@ -103,6 +103,7 @@ internal XmlElement GetXml(XmlDocument document) } [RequiresDynamicCode(CryptoHelpers.XsltRequiresDynamicCodeMessage)] + [RequiresUnreferencedCode(CryptoHelpers.CreateFromNameUnreferencedCodeMessage)] public virtual void LoadXml(XmlElement value) { if (value is null) diff --git a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/EncryptedType.cs b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/EncryptedType.cs index 85b82dd8d0d112..29aa30afacfec7 100644 --- a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/EncryptedType.cs +++ b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/EncryptedType.cs @@ -105,6 +105,7 @@ public virtual CipherData CipherData } [RequiresDynamicCode(CryptoHelpers.XsltRequiresDynamicCodeMessage)] + [RequiresUnreferencedCode(CryptoHelpers.CreateFromNameUnreferencedCodeMessage)] public abstract void LoadXml(XmlElement value); public abstract XmlElement GetXml(); } diff --git a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/EncryptedXml.cs b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/EncryptedXml.cs index 9c9d3337196d9f..1e42b3a73ac9ee 100644 --- a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/EncryptedXml.cs +++ b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/EncryptedXml.cs @@ -77,12 +77,15 @@ public class EncryptedXml // public constructors // [RequiresDynamicCode(CryptoHelpers.XsltRequiresDynamicCodeMessage)] + [RequiresUnreferencedCode(CryptoHelpers.CreateFromNameUnreferencedCodeMessage)] public EncryptedXml() : this(new XmlDocument()) { } [RequiresDynamicCode(CryptoHelpers.XsltRequiresDynamicCodeMessage)] + [RequiresUnreferencedCode(CryptoHelpers.CreateFromNameUnreferencedCodeMessage)] public EncryptedXml(XmlDocument document) : this(document, null) { } [RequiresDynamicCode(CryptoHelpers.XsltRequiresDynamicCodeMessage)] + [RequiresUnreferencedCode(CryptoHelpers.CreateFromNameUnreferencedCodeMessage)] public EncryptedXml(XmlDocument document, Evidence? evidence) { _document = document; @@ -303,6 +306,7 @@ public virtual byte[] GetDecryptionIV(EncryptedData encryptedData, string? symme // default behaviour is to look for keys defined by an EncryptedKey clause // either directly or through a KeyInfoRetrievalMethod, and key names in the key mapping [UnconditionalSuppressMessage("AOT", "IL3050:RequiresDynamicCode", Justification = "ctors are marked as RDC")] + [UnconditionalSuppressMessage("ILLink", "IL2026:RequiresUnreferencedCode", Justification = "ctors are marked as RUC")] public virtual SymmetricAlgorithm? GetDecryptionKey(EncryptedData encryptedData, string? symmetricAlgorithmUri) { if (encryptedData is null) @@ -391,6 +395,7 @@ public virtual byte[] GetDecryptionIV(EncryptedData encryptedData, string? symme // Try to decrypt the EncryptedKey given the key mapping [UnconditionalSuppressMessage("AOT", "IL3050:RequiresDynamicCode", Justification = "ctors are marked as RDC")] + [UnconditionalSuppressMessage("ILLink", "IL2026:RequiresUnreferencedCode", Justification = "ctors are marked as RUC")] public virtual byte[]? DecryptEncryptedKey(EncryptedKey encryptedKey) { if (encryptedKey is null) @@ -537,6 +542,7 @@ public void ClearKeyNameMappings() // Encrypts the given element with the certificate specified. The certificate is added as // an X509Data KeyInfo to an EncryptedKey (AES session key) generated randomly. [UnconditionalSuppressMessage("AOT", "IL3050:RequiresDynamicCode", Justification = "ctors are marked as RDC")] + [UnconditionalSuppressMessage("ILLink", "IL2026:RequiresUnreferencedCode", Justification = "ctors are marked as RUC")] public EncryptedData Encrypt(XmlElement inputElement, X509Certificate2 certificate) { if (inputElement is null) @@ -582,6 +588,7 @@ public EncryptedData Encrypt(XmlElement inputElement, X509Certificate2 certifica // has to be defined before calling this method. The key name is added as // a KeyNameInfo KeyInfo to an EncryptedKey (AES session key) generated randomly. [UnconditionalSuppressMessage("AOT", "IL3050:RequiresDynamicCode", Justification = "ctors are marked as RDC")] + [UnconditionalSuppressMessage("ILLink", "IL2026:RequiresUnreferencedCode", Justification = "ctors are marked as RUC")] public EncryptedData Encrypt(XmlElement inputElement, string keyName) { if (inputElement is null) @@ -665,6 +672,7 @@ public EncryptedData Encrypt(XmlElement inputElement, string keyName) // The behaviour of this method can be extended because GetDecryptionKey is virtual // the document is decrypted in place [UnconditionalSuppressMessage("AOT", "IL3050:RequiresDynamicCode", Justification = "ctors are marked as RDC")] + [UnconditionalSuppressMessage("ILLink", "IL2026:RequiresUnreferencedCode", Justification = "ctors are marked as RUC")] public void DecryptDocument() { // Look for all EncryptedData elements and decrypt them diff --git a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/KeyInfo.cs b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/KeyInfo.cs index d439382ea13ee7..2beaa3eb31dbbb 100644 --- a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/KeyInfo.cs +++ b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/KeyInfo.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Collections; +using System.Diagnostics.CodeAnalysis; using System.Xml; namespace System.Security.Cryptography.Xml @@ -58,6 +59,7 @@ internal XmlElement GetXml(XmlDocument xmlDocument) return keyInfoElement; } + [RequiresUnreferencedCode(CryptoHelpers.CreateFromNameUnreferencedCodeMessage)] public void LoadXml(XmlElement value) { if (value is null) diff --git a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/KeyInfoEncryptedKey.cs b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/KeyInfoEncryptedKey.cs index 0826866fd9874b..45329ded66a947 100644 --- a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/KeyInfoEncryptedKey.cs +++ b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/KeyInfoEncryptedKey.cs @@ -7,6 +7,7 @@ namespace System.Security.Cryptography.Xml { [RequiresDynamicCode(CryptoHelpers.XsltRequiresDynamicCodeMessage)] + [RequiresUnreferencedCode(CryptoHelpers.CreateFromNameUnreferencedCodeMessage)] public class KeyInfoEncryptedKey : KeyInfoClause { private EncryptedKey? _encryptedKey; diff --git a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/RSAPKCS1SHA1SignatureDescription.cs b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/RSAPKCS1SHA1SignatureDescription.cs index 82de982f9cd3af..e181cde89608a7 100644 --- a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/RSAPKCS1SHA1SignatureDescription.cs +++ b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/RSAPKCS1SHA1SignatureDescription.cs @@ -12,6 +12,8 @@ public RSAPKCS1SHA1SignatureDescription() : base("SHA1") } [SuppressMessage("Microsoft.Security", "CA5350", Justification = "SHA1 needed for compat.")] + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2046:AnnotationsMustMatchBase", + Justification = "This derived implementation doesn't require unreferenced code, like the base does.")] public sealed override HashAlgorithm CreateDigest() { return SHA1.Create(); diff --git a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/RSAPKCS1SHA256SignatureDescription.cs b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/RSAPKCS1SHA256SignatureDescription.cs index 21c8967f563b13..08f9620e200c01 100644 --- a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/RSAPKCS1SHA256SignatureDescription.cs +++ b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/RSAPKCS1SHA256SignatureDescription.cs @@ -1,6 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Diagnostics.CodeAnalysis; + namespace System.Security.Cryptography.Xml { internal sealed class RSAPKCS1SHA256SignatureDescription : RSAPKCS1SignatureDescription @@ -9,6 +11,8 @@ public RSAPKCS1SHA256SignatureDescription() : base("SHA256") { } + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2046:AnnotationsMustMatchBase", + Justification = "This derived implementation doesn't require unreferenced code, like the base does.")] public sealed override HashAlgorithm CreateDigest() { return SHA256.Create(); diff --git a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/RSAPKCS1SHA384SignatureDescription.cs b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/RSAPKCS1SHA384SignatureDescription.cs index 9d472c896646ff..92c7a24d6d8d80 100644 --- a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/RSAPKCS1SHA384SignatureDescription.cs +++ b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/RSAPKCS1SHA384SignatureDescription.cs @@ -1,6 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Diagnostics.CodeAnalysis; + namespace System.Security.Cryptography.Xml { internal sealed class RSAPKCS1SHA384SignatureDescription : RSAPKCS1SignatureDescription @@ -9,6 +11,8 @@ public RSAPKCS1SHA384SignatureDescription() : base("SHA384") { } + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2046:AnnotationsMustMatchBase", + Justification = "This derived implementation doesn't require unreferenced code, like the base does.")] public sealed override HashAlgorithm CreateDigest() { return SHA384.Create(); diff --git a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/RSAPKCS1SHA512SignatureDescription.cs b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/RSAPKCS1SHA512SignatureDescription.cs index 0bc99fcc6c1b6e..3be4740315353a 100644 --- a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/RSAPKCS1SHA512SignatureDescription.cs +++ b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/RSAPKCS1SHA512SignatureDescription.cs @@ -1,6 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Diagnostics.CodeAnalysis; + namespace System.Security.Cryptography.Xml { internal sealed class RSAPKCS1SHA512SignatureDescription : RSAPKCS1SignatureDescription @@ -9,6 +11,8 @@ public RSAPKCS1SHA512SignatureDescription() : base("SHA512") { } + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2046:AnnotationsMustMatchBase", + Justification = "This derived implementation doesn't require unreferenced code, like the base does.")] public sealed override HashAlgorithm CreateDigest() { return SHA512.Create(); diff --git a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/RSAPKCS1SignatureDescription.cs b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/RSAPKCS1SignatureDescription.cs index 9c48c3172d45fe..6d5a8fd733e03a 100644 --- a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/RSAPKCS1SignatureDescription.cs +++ b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/RSAPKCS1SignatureDescription.cs @@ -1,6 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Diagnostics.CodeAnalysis; + namespace System.Security.Cryptography.Xml { internal abstract class RSAPKCS1SignatureDescription : SignatureDescription @@ -13,6 +15,9 @@ public RSAPKCS1SignatureDescription(string hashAlgorithmName) DigestAlgorithm = hashAlgorithmName; } +#if NETCOREAPP + [RequiresUnreferencedCode("CreateDeformatter is not trim compatible because the algorithm implementation referenced by DeformatterAlgorithm might be removed.")] +#endif public sealed override AsymmetricSignatureDeformatter CreateDeformatter(AsymmetricAlgorithm key) { var item = (AsymmetricSignatureDeformatter)CryptoConfig.CreateFromName(DeformatterAlgorithm!)!; @@ -21,6 +26,9 @@ public sealed override AsymmetricSignatureDeformatter CreateDeformatter(Asymmetr return item; } +#if NETCOREAPP + [RequiresUnreferencedCode("CreateFormatter is not trim compatible because the algorithm implementation referenced by FormatterAlgorithm might be removed.")] +#endif public sealed override AsymmetricSignatureFormatter CreateFormatter(AsymmetricAlgorithm key) { var item = (AsymmetricSignatureFormatter)CryptoConfig.CreateFromName(FormatterAlgorithm!)!; @@ -29,6 +37,9 @@ public sealed override AsymmetricSignatureFormatter CreateFormatter(AsymmetricAl return item; } +#if NETCOREAPP + [RequiresUnreferencedCode("CreateDigest is not trim compatible because the algorithm implementation referenced by DigestAlgorithm might be removed.")] +#endif public abstract override HashAlgorithm CreateDigest(); } } diff --git a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/Reference.cs b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/Reference.cs index 1cf008b3f468ee..a0dc3399730e19 100644 --- a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/Reference.cs +++ b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/Reference.cs @@ -203,6 +203,7 @@ internal XmlElement GetXml(XmlDocument document) } [RequiresDynamicCode(CryptoHelpers.XsltRequiresDynamicCodeMessage)] + [RequiresUnreferencedCode(CryptoHelpers.CreateFromNameUnreferencedCodeMessage)] public void LoadXml(XmlElement value) { if (value is null) @@ -333,6 +334,7 @@ public void AddTransform(Transform transform) TransformChain.Add(transform); } + [RequiresUnreferencedCode(CryptoHelpers.CreateFromNameUnreferencedCodeMessage)] internal void UpdateHashValue(XmlDocument document, CanonicalXmlNodeList refList) { DigestValue = CalculateHashValue(document, refList); @@ -340,6 +342,7 @@ internal void UpdateHashValue(XmlDocument document, CanonicalXmlNodeList refList // What we want to do is pump the input through the TransformChain and then // hash the output of the chain document is the document context for resolving relative references + [RequiresUnreferencedCode(CryptoHelpers.CreateFromNameUnreferencedCodeMessage)] internal byte[]? CalculateHashValue(XmlDocument document, CanonicalXmlNodeList refList) { // refList is a list of elements that might be targets of references diff --git a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/Signature.cs b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/Signature.cs index 50d7e67c659d69..89485f83f534b8 100644 --- a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/Signature.cs +++ b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/Signature.cs @@ -130,6 +130,7 @@ internal XmlElement GetXml(XmlDocument document) } [RequiresDynamicCode(CryptoHelpers.XsltRequiresDynamicCodeMessage)] + [RequiresUnreferencedCode(CryptoHelpers.CreateFromNameUnreferencedCodeMessage)] public void LoadXml(XmlElement value) { if (value is null) diff --git a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/SignedInfo.cs b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/SignedInfo.cs index 654e4787ed1ecb..20b55828d594e0 100644 --- a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/SignedInfo.cs +++ b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/SignedInfo.cs @@ -8,6 +8,7 @@ namespace System.Security.Cryptography.Xml { [RequiresDynamicCode(CryptoHelpers.XsltRequiresDynamicCodeMessage)] + [RequiresUnreferencedCode(CryptoHelpers.CreateFromNameUnreferencedCodeMessage)] public class SignedInfo : ICollection { private string? _id; diff --git a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/SignedXml.cs b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/SignedXml.cs index d5048385e07ee6..50e13fde40d102 100644 --- a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/SignedXml.cs +++ b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/SignedXml.cs @@ -88,12 +88,14 @@ public class SignedXml // [RequiresDynamicCode(CryptoHelpers.XsltRequiresDynamicCodeMessage)] + [RequiresUnreferencedCode(CryptoHelpers.CreateFromNameUnreferencedCodeMessage)] public SignedXml() { Initialize(null); } [RequiresDynamicCode(CryptoHelpers.XsltRequiresDynamicCodeMessage)] + [RequiresUnreferencedCode(CryptoHelpers.CreateFromNameUnreferencedCodeMessage)] public SignedXml(XmlDocument document) { if (document is null) @@ -105,6 +107,7 @@ public SignedXml(XmlDocument document) } [RequiresDynamicCode(CryptoHelpers.XsltRequiresDynamicCodeMessage)] + [RequiresUnreferencedCode(CryptoHelpers.CreateFromNameUnreferencedCodeMessage)] public SignedXml(XmlElement elem) { if (elem is null) @@ -118,6 +121,7 @@ public SignedXml(XmlElement elem) [MemberNotNull(nameof(m_signature))] [MemberNotNull(nameof(_safeCanonicalizationMethods))] [RequiresDynamicCode(CryptoHelpers.XsltRequiresDynamicCodeMessage)] + [RequiresUnreferencedCode(CryptoHelpers.CreateFromNameUnreferencedCodeMessage)] private void Initialize(XmlElement? element) { _containingDocument = element?.OwnerDocument; @@ -178,6 +182,7 @@ public AsymmetricAlgorithm? SigningKey public EncryptedXml EncryptedXml { [UnconditionalSuppressMessage("AOT", "IL3050:RequiresDynamicCode", Justification = "ctors are marked as RDC")] + [UnconditionalSuppressMessage("ILLink", "IL2026:RequiresUnreferencedCode", Justification = "ctors are marked as RUC")] get => _exml ??= new EncryptedXml(_containingDocument!); // default processing rules set => _exml = value; } @@ -223,6 +228,7 @@ public XmlElement GetXml() } [UnconditionalSuppressMessage("AOT", "IL3050:RequiresDynamicCode", Justification = "ctors are marked as RDC")] + [UnconditionalSuppressMessage("ILLink", "IL2026:RequiresUnreferencedCode", Justification = "ctors are marked as RUC")] public void LoadXml(XmlElement value) { if (value is null) @@ -380,6 +386,7 @@ public bool CheckSignature(X509Certificate2 certificate, bool verifySignatureOnl return true; } + [UnconditionalSuppressMessage("ILLink", "IL2026:RequiresUnreferencedCode", Justification = "ctors are marked as RDC")] public void ComputeSignature() { SignedXmlDebugLog.LogBeginSignatureComputation(this, _context!); @@ -636,6 +643,7 @@ private static bool DefaultSignatureFormatValidator(SignedXml signedXml) // Validation function to see if the current signature is signed with a truncated HMAC - one which // has a signature length of fewer bits than the whole HMAC output. + [UnconditionalSuppressMessage("ILLink", "IL2026:RequiresUnreferencedCode", Justification = "ctors are marked as RDC")] private bool DoesSignatureUseTruncatedHmac() { // If we're not using the SignatureLength property, then we're not truncating the signature length @@ -780,6 +788,7 @@ private static IList DefaultSafeTransformMethods } } + [UnconditionalSuppressMessage("ILLink", "IL2026:RequiresUnreferencedCode", Justification = "ctors are marked as RDC")] private byte[] GetC14NDigest(HashAlgorithm hash) { bool isKeyedHashAlgorithm = hash is KeyedHashAlgorithm; @@ -879,6 +888,7 @@ public int Compare(object? a, object? b) } } + [UnconditionalSuppressMessage("ILLink", "IL2026:RequiresUnreferencedCode", Justification = "ctors are marked as RDC")] private void BuildDigestedReferences() { // Default the DigestMethod and Canonicalization @@ -916,6 +926,7 @@ private void BuildDigestedReferences() } } + [UnconditionalSuppressMessage("ILLink", "IL2026:RequiresUnreferencedCode", Justification = "ctors are marked as RDC")] private bool CheckDigestedReferences() { ArrayList references = m_signature.SignedInfo!.References; @@ -1004,6 +1015,8 @@ private bool CheckSignatureFormat() return formatValid; } + [UnconditionalSuppressMessage("ILLink", "IL2026:RequiresUnreferencedCode", Justification = "ctors are marked as RDC")] + [UnconditionalSuppressMessage("ILLink", "IL2057:UnrecognizedReflectionPattern", Justification = "ctors are marked as RDC")] private bool CheckSignedInfo(AsymmetricAlgorithm key) { if (key is null) diff --git a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/SignedXmlDebugLog.cs b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/SignedXmlDebugLog.cs index 334491e4c3147d..ae73934b343584 100644 --- a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/SignedXmlDebugLog.cs +++ b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/SignedXmlDebugLog.cs @@ -677,6 +677,7 @@ internal static void LogSigning(SignedXml signedXml, KeyedHashAlgorithm key) /// /// SignedXml object driving the signature /// Reference being hashed + [RequiresUnreferencedCode(CryptoHelpers.CreateFromNameUnreferencedCodeMessage)] internal static void LogSigningReference(SignedXml signedXml, Reference reference) { Debug.Assert(signedXml != null, "signedXml != null"); @@ -807,6 +808,7 @@ internal static void LogVerifyReference(SignedXml signedXml, Reference reference /// reference being verified /// actual hash value of the reference /// hash value the signature expected the reference to have + [RequiresUnreferencedCode(CryptoHelpers.CreateFromNameUnreferencedCodeMessage)] internal static void LogVerifyReferenceHash(SignedXml signedXml, Reference reference, byte[]? actualHash, @@ -1025,6 +1027,7 @@ internal static void LogVerifyX509Chain(SignedXml signedXml, X509Chain chain, X5 /// /// SignedXml object verifying the signature /// reference being verified + [RequiresUnreferencedCode(CryptoHelpers.CreateFromNameUnreferencedCodeMessage)] internal static void LogSignedXmlRecursionLimit(SignedXml signedXml, Reference reference) { diff --git a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/TransformChain.cs b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/TransformChain.cs index 00998dde429856..8022ba73c8f879 100644 --- a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/TransformChain.cs +++ b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/TransformChain.cs @@ -168,6 +168,7 @@ internal XmlElement GetXml(XmlDocument document, string ns) } [RequiresDynamicCode(CryptoHelpers.XsltRequiresDynamicCodeMessage)] + [RequiresUnreferencedCode(CryptoHelpers.CreateFromNameUnreferencedCodeMessage)] internal void LoadXml(XmlElement value) { if (value is null) diff --git a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/XmlDecryptionTransform.cs b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/XmlDecryptionTransform.cs index a844a0937b18ae..ff57f6e7170303 100644 --- a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/XmlDecryptionTransform.cs +++ b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/XmlDecryptionTransform.cs @@ -12,6 +12,7 @@ namespace System.Security.Cryptography.Xml // and XML Encryption when performed on the same document. [RequiresDynamicCode(CryptoHelpers.XsltRequiresDynamicCodeMessage)] + [RequiresUnreferencedCode(CryptoHelpers.CreateFromNameUnreferencedCodeMessage)] public class XmlDecryptionTransform : Transform { private readonly Type[] _inputTypes = { typeof(Stream), typeof(XmlDocument) }; @@ -21,7 +22,12 @@ public class XmlDecryptionTransform : Transform private EncryptedXml? _exml; // defines the XML encryption processing rules private XmlDocument? _containingDocument; private XmlNamespaceManager? _nsm; - private const string XmlDecryptionTransformNamespaceUrl = "http://www.w3.org/2002/07/decrypt#"; + + // work around https://github.com/dotnet/runtime/issues/81864 by splitting this into a separate class. + internal static class Consts + { + internal const string XmlDecryptionTransformNamespaceUrl = "http://www.w3.org/2002/07/decrypt#"; + } public XmlDecryptionTransform() { @@ -90,10 +96,10 @@ public override void LoadInnerXml(XmlNodeList nodeList) XmlElement? elem = node as XmlElement; if (elem != null) { - if (elem.LocalName == "Except" && elem.NamespaceURI == XmlDecryptionTransformNamespaceUrl) + if (elem.LocalName == "Except" && elem.NamespaceURI == Consts.XmlDecryptionTransformNamespaceUrl) { // the Uri is required - string? uri = Utils.GetAttribute(elem, "URI", XmlDecryptionTransformNamespaceUrl); + string? uri = Utils.GetAttribute(elem, "URI", Consts.XmlDecryptionTransformNamespaceUrl); if (uri == null || uri.Length == 0 || uri[0] != '#') throw new CryptographicException(SR.Cryptography_Xml_UriRequired); if (!Utils.VerifyAttributes(elem, "URI")) @@ -121,7 +127,7 @@ public override void LoadInnerXml(XmlNodeList nodeList) element.SetAttribute("Algorithm", Algorithm); foreach (string uri in ExceptUris) { - XmlElement exceptUriElement = document.CreateElement("Except", XmlDecryptionTransformNamespaceUrl); + XmlElement exceptUriElement = document.CreateElement("Except", Consts.XmlDecryptionTransformNamespaceUrl); exceptUriElement.SetAttribute("URI", uri); element.AppendChild(exceptUriElement); } diff --git a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/XmlLicenseTransform.cs b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/XmlLicenseTransform.cs index 536dc9f2e6b22a..e58d6c4df95f96 100644 --- a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/XmlLicenseTransform.cs +++ b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/XmlLicenseTransform.cs @@ -8,6 +8,7 @@ namespace System.Security.Cryptography.Xml { [RequiresDynamicCode(CryptoHelpers.XsltRequiresDynamicCodeMessage)] + [RequiresUnreferencedCode(CryptoHelpers.CreateFromNameUnreferencedCodeMessage)] public class XmlLicenseTransform : Transform { private readonly Type[] _inputTypes = { typeof(XmlDocument) }; @@ -15,8 +16,13 @@ public class XmlLicenseTransform : Transform private XmlNamespaceManager? _namespaceManager; private XmlDocument? _license; private IRelDecryptor? _relDecryptor; - private const string ElementIssuer = "issuer"; - private const string NamespaceUriCore = "urn:mpeg:mpeg21:2003:01-REL-R-NS"; + + // work around https://github.com/dotnet/runtime/issues/81864 by splitting these into a separate class. + internal static class Consts + { + internal const string ElementIssuer = "issuer"; + internal const string NamespaceUriCore = "urn:mpeg:mpeg21:2003:01-REL-R-NS"; + } public XmlLicenseTransform() { @@ -131,7 +137,7 @@ public override void LoadInput(object obj) _namespaceManager = new XmlNamespaceManager(_license.NameTable); _namespaceManager.AddNamespace("dsig", SignedXml.XmlDsigNamespaceUrl); _namespaceManager.AddNamespace("enc", EncryptedXml.XmlEncNamespaceUrl); - _namespaceManager.AddNamespace("r", NamespaceUriCore); + _namespaceManager.AddNamespace("r", Consts.NamespaceUriCore); XmlElement? currentIssuerContext; XmlElement? currentLicenseContext; @@ -158,8 +164,8 @@ public override void LoadInput(object obj) if (issuerList[i]! == currentIssuerContext) continue; - if ((issuerList[i]!.LocalName == ElementIssuer) && - (issuerList[i]!.NamespaceURI == NamespaceUriCore)) + if ((issuerList[i]!.LocalName == Consts.ElementIssuer) && + (issuerList[i]!.NamespaceURI == Consts.NamespaceUriCore)) issuerList[i]!.ParentNode!.RemoveChild(issuerList[i]!); }