6c15bbb54f4788fb034f61d73be312b678227b80
[mono.git] / mcs / class / corlib / System.Security.Cryptography.X509Certificates / X509Helper.Apple.cs
1 #if MONO_FEATURE_APPLETLS
2 using System;
3 using System.Runtime.InteropServices;
4 using MX = Mono.Security.X509;
5 using XamMac.CoreFoundation;
6
7 namespace System.Security.Cryptography.X509Certificates
8 {
9         static partial class X509Helper
10         {
11                 public static X509CertificateImpl InitFromHandleApple (IntPtr handle)
12                 {
13                         return new X509CertificateImplApple (handle, false);
14                 }
15
16                 static X509CertificateImpl ImportApple (byte[] rawData)
17                 {
18                         var handle = CFHelpers.CreateCertificateFromData (rawData);
19                         if (handle != IntPtr.Zero)
20                                 return new X509CertificateImplApple (handle, true);
21
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);
32                                 }
33                         }
34
35                         return new X509CertificateImplMono (x509);
36                 }
37         }
38 }
39 #endif