Merge pull request #3008 from lateralusX/jlorenss/win-x64-shutdown-crash
[mono.git] / mcs / class / corlib / System.Security.Cryptography.X509Certificates / X509Helper.Apple.cs
1 using System;
2 using System.Runtime.InteropServices;
3 using MX = Mono.Security.X509;
4 using XamMac.CoreFoundation;
5
6 namespace System.Security.Cryptography.X509Certificates
7 {
8         static partial class X509Helper
9         {
10                 public static X509CertificateImpl InitFromHandle (IntPtr handle)
11                 {
12                         return new X509CertificateImplApple (handle, false);
13                 }
14
15                 static X509CertificateImpl Import (byte[] rawData)
16                 {
17                         var handle = CFHelpers.CreateCertificateFromData (rawData);
18                         if (handle != IntPtr.Zero)
19                                 return new X509CertificateImplApple (handle, true);
20
21                         MX.X509Certificate x509;
22                         try {
23                                 x509 = new MX.X509Certificate (rawData);
24                         } catch (Exception e) {
25                                 try {
26                                         x509 = ImportPkcs12 (rawData, null);
27                                 } catch {
28                                         string msg = Locale.GetText ("Unable to decode certificate.");
29                                         // inner exception is the original (not second) exception
30                                         throw new CryptographicException (msg, e);
31                                 }
32                         }
33
34                         return new X509CertificateImplMono (x509);
35                 }
36         }
37 }