Merge pull request #2201 from rolfbjarne/linker-better-xml-processing-errors
[mono.git] / mcs / class / System / Mono.Net.Security / NoReflectionHelper.cs
1 //
2 // NoReflectionHelper.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
27 #if SECURITY_DEP
28 #if MONO_SECURITY_ALIAS
29 extern alias MonoSecurity;
30 using MSI = MonoSecurity::Mono.Security.Interface;
31 using MX = MonoSecurity::Mono.Security.X509;
32 #else
33 using MSI = Mono.Security.Interface;
34 using MX = Mono.Security.X509;
35 #endif
36 using System.Security.Cryptography.X509Certificates;
37 #endif
38
39 using System;
40 using System.Net;
41
42 namespace Mono.Net.Security
43 {
44         //
45         // Internal APIs which are used by Mono.Security.dll to avoid using reflection.
46         //
47         internal static class NoReflectionHelper
48         {
49                 internal static object GetDefaultCertificateValidator (object provider, object settings)
50                 {
51                         #if SECURITY_DEP
52                         return ChainValidationHelper.GetDefaultValidator ((MSI.MonoTlsProvider)provider, (MSI.MonoTlsSettings)settings);
53                         #else
54                         throw new NotSupportedException ();
55                         #endif
56                 }
57
58                 internal static object GetProvider ()
59                 {
60                         #if SECURITY_DEP
61                         return MonoTlsProviderFactory.GetProvider ();
62                         #else
63                         throw new NotSupportedException ();
64                         #endif
65                 }
66
67                 internal static object GetDefaultProvider ()
68                 {
69                         #if SECURITY_DEP
70                         return MonoTlsProviderFactory.GetDefaultProvider ();
71                         #else
72                         throw new NotSupportedException ();
73                         #endif
74                 }
75
76                 internal static bool HasProvider {
77                         get {
78                                 #if SECURITY_DEP
79                                 return MonoTlsProviderFactory.HasProvider;
80                                 #else
81                                 throw new NotSupportedException ();
82                                 #endif
83                         }
84                 }
85
86                 internal static void InstallProvider (object provider)
87                 {
88                         #if SECURITY_DEP
89                         MonoTlsProviderFactory.InstallProvider ((MSI.MonoTlsProvider)provider);
90                         #else
91                         throw new NotSupportedException ();
92                         #endif
93                 }
94
95                 internal static HttpWebRequest CreateHttpsRequest (Uri requestUri, object provider, object settings)
96                 {
97                         #if SECURITY_DEP
98                         return MonoTlsProviderFactory.CreateHttpsRequest (requestUri, (MSI.MonoTlsProvider)provider, (MSI.MonoTlsSettings)settings);
99                         #else
100                         throw new NotSupportedException ();
101                         #endif
102                 }
103
104                 internal static object CreateHttpListener (object certificate, object provider, object settings)
105                 {
106                         #if SECURITY_DEP
107                         return MonoTlsProviderFactory.CreateHttpListener ((X509Certificate)certificate, (MSI.MonoTlsProvider)provider, (MSI.MonoTlsSettings)settings);
108                         #else
109                         throw new NotSupportedException ();
110                         #endif
111                 }
112         }
113 }