Merge pull request #2274 from esdrubal/udpclientreceive
[mono.git] / mcs / class / System / System.Security.Cryptography.X509Certificates / PublicKey.cs
index a1f65e773a4de15f2ccc8de7d537d952c84504e8..15641f264213831c7846be0b0492b33f3948297c 100644 (file)
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-#if SECURITY_DEP || MOONLIGHT
+#if SECURITY_DEP
 
+#if MONO_SECURITY_ALIAS
+extern alias MonoSecurity;
+using MonoSecurity::Mono.Security;
+using MonoSecurity::Mono.Security.Cryptography;
+using MSX = MonoSecurity::Mono.Security.X509;
+#else
 using Mono.Security;
 using Mono.Security.Cryptography;
 using MSX = Mono.Security.X509;
+#endif
 
 namespace System.Security.Cryptography.X509Certificates {
 
@@ -47,6 +54,8 @@ namespace System.Security.Cryptography.X509Certificates {
                private AsnEncodedData _params;
                private Oid _oid;
 
+               static byte[] Empty = new byte [0];
+
                public PublicKey (Oid oid, AsnEncodedData parameters, AsnEncodedData keyValue)
                {
                        if (oid == null)
@@ -67,14 +76,12 @@ namespace System.Security.Cryptography.X509Certificates {
                        bool export_required = true;
 
                        if (certificate.KeyAlgorithm == rsaOid) {
-#if !MOONLIGHT
                                // shortcut export/import in the case the private key isn't available
                                RSACryptoServiceProvider rcsp = (certificate.RSA as RSACryptoServiceProvider);
                                if ((rcsp != null) && rcsp.PublicOnly) {
                                        _key = certificate.RSA;
                                        export_required = false;
                                } else 
-#endif
                                {
                                        RSAManaged rsam = (certificate.RSA as RSAManaged);
                                        if ((rsam != null) && rsam.PublicOnly) {
@@ -89,7 +96,6 @@ namespace System.Security.Cryptography.X509Certificates {
                                        (_key as RSA).ImportParameters (rsap);
                                }
                        } else {
-#if !MOONLIGHT
                                // shortcut export/import in the case the private key isn't available
                                DSACryptoServiceProvider dcsp = (certificate.DSA as DSACryptoServiceProvider);
                                if ((dcsp != null) && dcsp.PublicOnly) {
@@ -103,12 +109,11 @@ namespace System.Security.Cryptography.X509Certificates {
                                        _key = DSA.Create ();
                                        (_key as DSA).ImportParameters (rsap);
                                }
-#endif
                        }
 
                        _oid = new Oid (certificate.KeyAlgorithm);
                        _keyValue = new AsnEncodedData (_oid, certificate.PublicKey);
-                       _params = new AsnEncodedData (_oid, certificate.KeyAlgorithmParameters);
+                       _params = new AsnEncodedData (_oid, certificate.KeyAlgorithmParameters ?? Empty);
                }
 
                // properties
@@ -184,11 +189,7 @@ namespace System.Security.Cryptography.X509Certificates {
                                throw new CryptographicException (msg, e);
                        }
 
-#if MOONLIGHT
-                       DSA dsa = (DSA) new DSAManaged (dsaParams.Y.Length << 3);
-#else
                        DSA dsa = (DSA) new DSACryptoServiceProvider (dsaParams.Y.Length << 3);
-#endif
                        dsa.ImportParameters (dsaParams);
                        return dsa;
                }
@@ -218,11 +219,7 @@ namespace System.Security.Cryptography.X509Certificates {
                        }
 
                        int keySize = (rsaParams.Modulus.Length << 3);
-#if MOONLIGHT
-                       RSA rsa = (RSA) new RSAManaged (keySize);
-#else
                        RSA rsa = (RSA) new RSACryptoServiceProvider (keySize);
-#endif
                        rsa.ImportParameters (rsaParams);
                        return rsa;
                }