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