Merge pull request #3686 from lambdageek/dev-format-printf
[mono.git] / mcs / class / Mono.Btls.Interface / Mono.Btls.Interface / BtlsProvider.cs
1 //
2 // BtlsProvider.cs
3 //
4 // Author:
5 //       Martin Baulig <martin.baulig@xamarin.com>
6 //
7 // Copyright (c) 2016 Xamarin Inc. (http://www.xamarin.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining a copy
10 // of this software and associated documentation files (the "Software"), to deal
11 // in the Software without restriction, including without limitation the rights
12 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 // copies of the Software, and to permit persons to whom the Software is
14 // furnished to do so, subject to the following conditions:
15 //
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
18 //
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 // THE SOFTWARE.
26 using System;
27 using Mono.Security.Interface;
28 using System.Security.Cryptography.X509Certificates;
29
30 namespace Mono.Btls.Interface
31 {
32         public static class BtlsProvider
33         {
34                 public static bool IsSupported ()
35                 {
36                         return MonoBtlsProvider.IsSupported ();
37                 }
38
39                 public static MonoTlsProvider GetProvider ()
40                 {
41                         return new MonoBtlsProvider ();
42                 }
43
44                 public static BtlsX509 CreateNative (byte[] data, BtlsX509Format format)
45                 {
46                         var x509 = MonoBtlsX509.LoadFromData (data, (MonoBtlsX509Format)format);
47                         return new BtlsX509 (x509);
48                 }
49
50                 public static X509Certificate CreateCertificate (byte[] data, BtlsX509Format format, bool disallowFallback = false)
51                 {
52                         return MonoBtlsProvider.CreateCertificate (data, (MonoBtlsX509Format)format, disallowFallback);
53                 }
54
55                 public static X509Certificate2 CreateCertificate2 (byte[] data, BtlsX509Format format, bool disallowFallback = false)
56                 {
57                         return MonoBtlsProvider.CreateCertificate2 (data, (MonoBtlsX509Format)format, disallowFallback);
58                 }
59
60                 public static X509Certificate2 CreateCertificate2 (byte[] data, string password, bool disallowFallback = false)
61                 {
62                         return MonoBtlsProvider.CreateCertificate2 (data, password, disallowFallback);
63                 }
64
65                 public static BtlsX509Chain CreateNativeChain ()
66                 {
67                         return new BtlsX509Chain (new MonoBtlsX509Chain ());
68                 }
69
70                 public static BtlsX509Store CreateNativeStore ()
71                 {
72                         return new BtlsX509Store (new MonoBtlsX509Store ());
73                 }
74
75                 public static BtlsX509StoreCtx CreateNativeStoreCtx ()
76                 {
77                         return new BtlsX509StoreCtx (new MonoBtlsX509StoreCtx ());
78                 }
79
80                 public static X509Chain CreateChain ()
81                 {
82                         return MonoBtlsProvider.CreateChain ();
83                 }
84
85                 public static string GetSystemStoreLocation ()
86                 {
87                         return MonoBtlsProvider.GetSystemStoreLocation ();
88                 }
89
90                 public static BtlsX509VerifyParam GetVerifyParam_SslClient ()
91                 {
92                         return new BtlsX509VerifyParam (MonoBtlsX509VerifyParam.GetSslClient ());
93                 }
94
95                 public static BtlsX509VerifyParam GetVerifyParam_SslServer ()
96                 {
97                         return new BtlsX509VerifyParam (MonoBtlsX509VerifyParam.GetSslServer ());
98                 }
99
100                 public static X509Chain GetManagedChain (BtlsX509Chain chain)
101                 {
102                         return MonoBtlsProvider.GetManagedChain (chain.Instance);
103                 }
104         }
105 }
106