Merge pull request #963 from kebby/master
[mono.git] / mcs / class / corlib / System.Security.Cryptography / AsymmetricAlgorithm.cs
index 9447908dd9233a69934207617aa120309fa49ba1..47ce386ebd8ff0ab3653ad6a5f97adf12c4af9f9 100644 (file)
@@ -6,7 +6,7 @@
 //     Sebastien Pouliot (sebastien@ximian.com)
 //
 // Portions (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
-// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004-2005, 2008 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -33,10 +33,8 @@ using System.Runtime.InteropServices;
 
 namespace System.Security.Cryptography {
 
-#if NET_2_0
        [ComVisible (true)]
-#endif
-       public abstract class AsymmetricAlgorithm : IDisposable {
+       public abstract class AsymmetricAlgorithm : IDisposable {
 
                protected int KeySizeValue;
                protected KeySizes[] LegalKeySizesValue; 
@@ -67,7 +65,11 @@ namespace System.Security.Cryptography {
                        get;
                }
 
+#if NET_4_0
+               public void Dispose ()
+#else
                void IDisposable.Dispose () 
+#endif
                {
                        Dispose (true);
                        GC.SuppressFinalize (this);  // Finalization is now unnecessary
@@ -78,20 +80,48 @@ namespace System.Security.Cryptography {
                        Dispose (false);
                }
 
+#if NET_4_0
+               protected virtual void Dispose (bool disposing)
+               {
+               }
+#else
                protected abstract void Dispose (bool disposing);
-
+#endif
                public abstract void FromXmlString (string xmlString);
                
                public abstract string ToXmlString (bool includePrivateParameters);             
                
                public static AsymmetricAlgorithm Create () 
                {
+#if FULL_AOT_RUNTIME
+                       return new RSACryptoServiceProvider ();
+#else
                        return Create ("System.Security.Cryptography.AsymmetricAlgorithm");
+#endif
                }
        
                public static AsymmetricAlgorithm Create (string algName) 
                {
                        return (AsymmetricAlgorithm) CryptoConfig.CreateFromName (algName);
                }
+
+               // parsing helper shared between DSA and RSA
+               internal static byte [] GetNamedParam (string xml, string param)
+               {
+                       string start_element = "<" + param + ">";
+                       int start = xml.IndexOf (start_element);
+                       if (start == -1)
+                               return null;
+
+                       string end_element = "</" + param + ">";
+                       int end = xml.IndexOf (end_element);
+                       if ((end == -1) || (end <= start))
+                               return null;
+
+                       start += start_element.Length;
+
+                       string base64 = xml.Substring (start, end - start);
+                       return Convert.FromBase64String (base64);
+               }
        }
 }