Automatic optimization bug bisector.
[mono.git] / mcs / class / Mono.Security / Mono.Security.Interface / MonoTlsProviderFactory.cs
1 //
2 // MonoTlsProviderFactory.cs
3 //
4 // Author:
5 //       Martin Baulig <martin.baulig@xamarin.com>
6 //
7 // Copyright (c) 2015 Xamarin, Inc.
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 System.Net;
28 using Mono.Net.Security;
29 using System.Security.Cryptography.X509Certificates;
30
31 namespace Mono.Security.Interface
32 {
33         /*
34          * Public API front-end to System.dll's version.
35          *
36          * Keep in sync with System/Mono.Net.Security/MonoTlsProviderFactory.cs.
37          */
38         public static class MonoTlsProviderFactory
39         {
40                 /*
41                  * Returns the currently installed @MonoTlsProvider, falling back to the default one.
42                  *
43                  * This method throws @NotSupportedException if no TLS Provider can be found.
44                  */
45                 public static MonoTlsProvider GetProvider ()
46                 {
47                         return (MonoTlsProvider)NoReflectionHelper.GetProvider ();
48                 }
49
50                 /*
51                  * Returns the default @MonoTlsProvider.
52                  *
53                  * This method throws @NotSupportedException if no TLS Provider can be found.
54                  */
55                 public static MonoTlsProvider GetDefaultProvider ()
56                 {
57                         return (MonoTlsProvider)NoReflectionHelper.GetDefaultProvider ();
58                 }
59
60                 /*
61                  * GetProvider() attempts to load and install the default provider and throws on error.
62                  *
63                  * This property checks whether a provider has previously been installed by a call
64                  * to either GetProvider() or InstallProvider().
65                  *
66                  */
67                 public static bool HasProvider {
68                         get {
69                                 return NoReflectionHelper.HasProvider;
70                         }
71                 }
72
73                 /*
74                  * Installs a custom TLS Provider.
75                  *
76                  * May only be called at application startup and will throw
77                  * @InvalidOperationException if a provider has already been installed.
78                  */
79                 public static void InstallProvider (MonoTlsProvider provider)
80                 {
81                         NoReflectionHelper.InstallProvider (provider);
82                 }
83
84                 /*
85                  * Create @HttpWebRequest with the specified @provider (may be null to use the default one).
86                  * 
87                  * NOTE: This needs to be written as "System.Uri" to avoid ambiguity with Mono.Security.Uri in the
88                  *        mobile build.
89                  * 
90                  */
91                 public static HttpWebRequest CreateHttpsRequest (System.Uri requestUri, MonoTlsProvider provider, MonoTlsSettings settings = null)
92                 {
93                         return NoReflectionHelper.CreateHttpsRequest (requestUri, provider, settings);
94                 }
95
96                 public static HttpListener CreateHttpListener (X509Certificate certificate, MonoTlsProvider provider = null, MonoTlsSettings settings = null)
97                 {
98                         return (HttpListener)NoReflectionHelper.CreateHttpListener (certificate, provider, settings);
99                 }
100         }
101 }
102