[corlib] Add back X509 support for watchOS.
[mono.git] / mcs / class / corlib / System.Security.Cryptography.X509Certificates / X509Helper.Apple.cs
index 7068882bc9ac15ee093c9649f6e19cf44ff84e59..410f94674443d0cc9118ba8c47d4101f55595c5e 100644 (file)
@@ -1,3 +1,4 @@
+#if MONO_FEATURE_APPLETLS || MONO_FEATURE_APPLE_X509
 using System;
 using System.Runtime.InteropServices;
 using MX = Mono.Security.X509;
@@ -7,40 +8,27 @@ namespace System.Security.Cryptography.X509Certificates
 {
        static partial class X509Helper
        {
-               public static X509CertificateImpl InitFromHandle (IntPtr handle)
+               public static X509CertificateImpl InitFromHandleApple (IntPtr handle)
                {
                        return new X509CertificateImplApple (handle, false);
                }
 
-               public static X509CertificateImpl Import (byte[] rawData, string password, X509KeyStorageFlags keyStorageFlags)
+               static X509CertificateImpl ImportApple (byte[] rawData)
                {
-                       MX.X509Certificate x509;
-                       IntPtr handle;
-                       if (password == null) {
-                               handle = CFHelpers.CreateCertificateFromData (rawData);
-                               if (handle != IntPtr.Zero)
-                                       return new X509CertificateImplApple (handle, true);
+                       var handle = CFHelpers.CreateCertificateFromData (rawData);
+                       if (handle != IntPtr.Zero)
+                               return new X509CertificateImplApple (handle, true);
 
+                       MX.X509Certificate x509;
+                       try {
+                               x509 = new MX.X509Certificate (rawData);
+                       } catch (Exception e) {
                                try {
-                                       x509 = new MX.X509Certificate (rawData);
-                               } catch (Exception e) {
-                                       try {
-                                               x509 = X509Helper.ImportPkcs12 (rawData, null);
-                                       } catch {
-                                               string msg = Locale.GetText ("Unable to decode certificate.");
-                                               // inner exception is the original (not second) exception
-                                               throw new CryptographicException (msg, e);
-                                       }
-                               }
-                       } else {
-                               // try PKCS#12
-                               try {
-                                       x509 = X509Helper.ImportPkcs12 (rawData, password);
-                               }
-                               catch {
-                                       // it's possible to supply a (unrequired/unusued) password
-                                       // fix bug #79028
-                                       x509 = new MX.X509Certificate (rawData);
+                                       x509 = ImportPkcs12 (rawData, null);
+                               } catch {
+                                       string msg = Locale.GetText ("Unable to decode certificate.");
+                                       // inner exception is the original (not second) exception
+                                       throw new CryptographicException (msg, e);
                                }
                        }
 
@@ -48,3 +36,4 @@ namespace System.Security.Cryptography.X509Certificates
                }
        }
 }
+#endif