You've already forked linux-packaging-mono
Imported Upstream version 5.12.0.220
Former-commit-id: c477e03582759447177c6d4bf412cd2355aad476
This commit is contained in:
parent
8bd104cef2
commit
8fc30896db
@ -30,7 +30,7 @@
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#if FULL_AOT_RUNTIME
|
||||
#if !FEATURE_CRYPTO_CONFIGURABLE
|
||||
|
||||
// This is a special version of CryptoConfig that is not configurable and
|
||||
// every "choice" is statiscally compiled. As long as CreateFromName is not
|
||||
@ -38,17 +38,13 @@
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Permissions;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace System.Security.Cryptography {
|
||||
|
||||
[ComVisible (true)]
|
||||
public partial class CryptoConfig {
|
||||
|
||||
public static void AddAlgorithm (Type algorithm, params string[] names)
|
||||
{
|
||||
throw new PlatformNotSupportedException ();
|
||||
}
|
||||
|
||||
public static void AddOID (string oid, params string[] names)
|
||||
{
|
||||
throw new PlatformNotSupportedException ();
|
||||
@ -61,12 +57,12 @@ namespace System.Security.Cryptography {
|
||||
return CreateFromName (name, null);
|
||||
}
|
||||
|
||||
[PermissionSet (SecurityAction.LinkDemand, Unrestricted = true)]
|
||||
public static object CreateFromName (string name, params object[] args)
|
||||
{
|
||||
if (name == null)
|
||||
throw new ArgumentNullException ("name");
|
||||
|
||||
// TODO: These ignore args
|
||||
switch (name.ToLowerInvariant ()) {
|
||||
case "system.security.cryptography.dsacryptoserviceprovider":
|
||||
case "system.security.cryptography.dsa":
|
||||
@ -94,6 +90,7 @@ namespace System.Security.Cryptography {
|
||||
case "system.security.cryptography.hmac":
|
||||
case "system.security.cryptography.hmacsha1":
|
||||
case "hmacsha1":
|
||||
case "http://www.w3.org/2000/09/xmldsig#hmac-sha1":
|
||||
return new HMACSHA1 ();
|
||||
case "system.security.cryptography.hmacsha256":
|
||||
case "hmacsha256":
|
||||
@ -155,8 +152,8 @@ namespace System.Security.Cryptography {
|
||||
case "system.security.cryptography.hashalgorithm":
|
||||
case "system.security.cryptography.sha1":
|
||||
case "system.security.cryptography.sha1cryptoserviceprovider":
|
||||
case "system.security.cryptography.sha1cng":
|
||||
case "sha1":
|
||||
case "system.security.cryptography.sha1cng":
|
||||
case "sha":
|
||||
case "http://www.w3.org/2000/09/xmldsig#sha1":
|
||||
return new SHA1CryptoServiceProvider ();
|
||||
@ -192,23 +189,47 @@ namespace System.Security.Cryptography {
|
||||
case "tripledes":
|
||||
case "3des":
|
||||
return new TripleDESCryptoServiceProvider ();
|
||||
|
||||
// These are not yet linker friendly
|
||||
case "x509chain":
|
||||
name = "System.Security.Cryptography.X509Certificates.X509Chain, System";
|
||||
break;
|
||||
case "2.5.29.15":
|
||||
name = "System.Security.Cryptography.X509Certificates.X509KeyUsageExtension, System";
|
||||
break;
|
||||
case "2.5.29.19":
|
||||
name = "System.Security.Cryptography.X509Certificates.X509BasicConstraintsExtension, System";
|
||||
break;
|
||||
case "2.5.29.14":
|
||||
name = "System.Security.Cryptography.X509Certificates.X509SubjectKeyIdentifierExtension, System";
|
||||
break;
|
||||
case "2.5.29.37":
|
||||
name = "System.Security.Cryptography.X509Certificates.X509EnhancedKeyUsageExtension, System";
|
||||
break;
|
||||
case "aes":
|
||||
#if FULL_AOT_DESKTOP // TODO: why is this special cased? we could use AesManaged like other full AOT profiles
|
||||
name = "System.Security.Cryptography.AesCryptoServiceProvider, System.Core";
|
||||
#else
|
||||
#if MONOTOUCH || XAMMAC
|
||||
name = "System.Security.Cryptography.AesManaged, System.Core";
|
||||
#else
|
||||
name = "System.Security.Cryptography.AesCryptoServiceProvider, System.Core";
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
lock (lockObject) {
|
||||
Type algoClass = null;
|
||||
if (algorithms?.TryGetValue (name, out algoClass) == true) {
|
||||
try {
|
||||
return Activator.CreateInstance (algoClass, args);
|
||||
} catch {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// last resort, the request type might be available (if care is taken for the type not to be linked
|
||||
// away) and that can allow some 3rd party code to work (e.g. extra algorithms) and make a few more
|
||||
// unit tests happy
|
||||
return Activator.CreateInstance (Type.GetType (name));
|
||||
return Activator.CreateInstance (Type.GetType (name), args);
|
||||
}
|
||||
catch {
|
||||
// method doesn't throw any exception
|
||||
@ -271,6 +292,11 @@ namespace System.Security.Cryptography {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static void Initialize ()
|
||||
{
|
||||
algorithms = new Dictionary<string, Type> (StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,9 +29,43 @@
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace System.Security.Cryptography {
|
||||
|
||||
public partial class CryptoConfig {
|
||||
public partial class CryptoConfig
|
||||
{
|
||||
static readonly object lockObject = new object ();
|
||||
static Dictionary<string,Type> algorithms;
|
||||
|
||||
public static void AddAlgorithm (Type algorithm, params string[] names)
|
||||
{
|
||||
if (algorithm == null)
|
||||
throw new ArgumentNullException (nameof (algorithm));
|
||||
if (!algorithm.IsVisible)
|
||||
throw new ArgumentException ("Algorithms added to CryptoConfig must be accessable from outside their assembly.", nameof (algorithm));
|
||||
if (names == null)
|
||||
throw new ArgumentNullException (nameof (names));
|
||||
|
||||
var algorithmNames = new string [names.Length];
|
||||
Array.Copy (names, algorithmNames, algorithmNames.Length);
|
||||
|
||||
foreach (string name in algorithmNames) {
|
||||
if (string.IsNullOrEmpty (name)) {
|
||||
throw new ArgumentException ("CryptoConfig cannot add a mapping for a null or empty name.");
|
||||
}
|
||||
}
|
||||
|
||||
lock (lockObject) {
|
||||
if (algorithms == null) {
|
||||
Initialize ();
|
||||
}
|
||||
|
||||
foreach (string name in algorithmNames) {
|
||||
algorithms [name] = algorithm;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] EncodeOID (string str)
|
||||
{
|
||||
|
@ -30,7 +30,7 @@
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#if !FULL_AOT_RUNTIME
|
||||
#if FEATURE_CRYPTO_CONFIGURABLE
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
@ -50,8 +50,6 @@ namespace System.Security.Cryptography {
|
||||
[ComVisible (true)]
|
||||
public partial class CryptoConfig {
|
||||
|
||||
static private object lockObject;
|
||||
static private Dictionary<string,Type> algorithms;
|
||||
static private Dictionary<string,string> unresolved_algorithms;
|
||||
static private Dictionary<string,string> oids;
|
||||
|
||||
@ -204,6 +202,7 @@ public partial class CryptoConfig {
|
||||
private const string urlSHA256 = "http://www.w3.org/2001/04/xmlenc#sha256";
|
||||
private const string urlSHA384 = "http://www.w3.org/2001/04/xmldsig-more#sha384";
|
||||
private const string urlSHA512 = "http://www.w3.org/2001/04/xmlenc#sha512";
|
||||
private const string urlHMACSHA1 = "http://www.w3.org/2000/09/xmldsig#hmac-sha1";
|
||||
private const string urlHMACSHA256 = "http://www.w3.org/2001/04/xmldsig-more#hmac-sha256";
|
||||
private const string urlHMACSHA384 = "http://www.w3.org/2001/04/xmldsig-more#hmac-sha384";
|
||||
private const string urlHMACSHA512 = "http://www.w3.org/2001/04/xmldsig-more#hmac-sha512";
|
||||
@ -280,12 +279,6 @@ public partial class CryptoConfig {
|
||||
// SHA512 provider
|
||||
const string nameSHA512Provider = "System.Security.Cryptography.SHA512CryptoServiceProvider";
|
||||
const string defaultSHA512Provider = "System.Security.Cryptography.SHA512CryptoServiceProvider" + system_core_assembly;
|
||||
static CryptoConfig ()
|
||||
{
|
||||
// lock(this) is bad
|
||||
// http://msdn.microsoft.com/library/en-us/dnaskdr/html/askgui06032003.asp?frame=true
|
||||
lockObject = new object ();
|
||||
}
|
||||
|
||||
private static void Initialize ()
|
||||
{
|
||||
@ -384,6 +377,7 @@ public partial class CryptoConfig {
|
||||
algorithms.Add (urlSHA256, defaultSHA256);
|
||||
algorithms.Add (urlSHA384, defaultSHA384);
|
||||
algorithms.Add (urlSHA512, defaultSHA512);
|
||||
algorithms.Add (urlHMACSHA1, defaultHMAC);
|
||||
algorithms.Add (urlHMACSHA256, defaultHMACSHA256);
|
||||
algorithms.Add (urlHMACSHA384, defaultHMACSHA384);
|
||||
algorithms.Add (urlHMACSHA512, defaultHMACSHA512);
|
||||
@ -560,20 +554,6 @@ public partial class CryptoConfig {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void AddAlgorithm (Type algorithm, params string[] names)
|
||||
{
|
||||
if (algorithm == null)
|
||||
throw new ArgumentNullException ("algorithm");
|
||||
if (names == null)
|
||||
throw new ArgumentNullException ("names");
|
||||
|
||||
foreach (string name in names) {
|
||||
if (String.IsNullOrWhiteSpace (name))
|
||||
throw new ArithmeticException ("names");
|
||||
algorithms [name] = algorithm;
|
||||
}
|
||||
}
|
||||
|
||||
public static void AddOID (string oid, params string[] names)
|
||||
{
|
||||
if (oid == null)
|
||||
|
Reference in New Issue
Block a user