[corlib] Add back X509 support for watchOS.
[mono-project.git] / mcs / class / corlib / System.Security.Cryptography.X509Certificates / X509Helper.Apple.cs
blob410f94674443d0cc9118ba8c47d4101f55595c5e
1 #if MONO_FEATURE_APPLETLS || MONO_FEATURE_APPLE_X509
2 using System;
3 using System.Runtime.InteropServices;
4 using MX = Mono.Security.X509;
5 using XamMac.CoreFoundation;
7 namespace System.Security.Cryptography.X509Certificates
9 static partial class X509Helper
11 public static X509CertificateImpl InitFromHandleApple (IntPtr handle)
13 return new X509CertificateImplApple (handle, false);
16 static X509CertificateImpl ImportApple (byte[] rawData)
18 var handle = CFHelpers.CreateCertificateFromData (rawData);
19 if (handle != IntPtr.Zero)
20 return new X509CertificateImplApple (handle, true);
22 MX.X509Certificate x509;
23 try {
24 x509 = new MX.X509Certificate (rawData);
25 } catch (Exception e) {
26 try {
27 x509 = ImportPkcs12 (rawData, null);
28 } catch {
29 string msg = Locale.GetText ("Unable to decode certificate.");
30 // inner exception is the original (not second) exception
31 throw new CryptographicException (msg, e);
35 return new X509CertificateImplMono (x509);
39 #endif