Merge pull request #2166 from ermshiperete/FontHeight
[mono.git] / mcs / class / System / Mono.Net.Security / CallbackHelpers.cs
1 //
2 // CallbackHelpers.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
29 #if MONO_X509_ALIAS
30 extern alias PrebuiltSystem;
31 #endif
32 #if MONO_SECURITY_ALIAS
33 extern alias MonoSecurity;
34 #endif
35
36 #if MONO_SECURITY_ALIAS
37 using MSI = MonoSecurity::Mono.Security.Interface;
38 #else
39 using MSI = Mono.Security.Interface;
40 #endif
41 #if MONO_X509_ALIAS
42 using XX509CertificateCollection = PrebuiltSystem::System.Security.Cryptography.X509Certificates.X509CertificateCollection;
43 using XX509Chain = PrebuiltSystem::System.Security.Cryptography.X509Certificates.X509Chain;
44 #else
45 using XX509CertificateCollection = System.Security.Cryptography.X509Certificates.X509CertificateCollection;
46 using XX509Chain = System.Security.Cryptography.X509Certificates.X509Chain;
47 #endif
48
49 using System;
50 using System.IO;
51 using System.Net;
52 using System.Net.Security;
53 using System.Security.Cryptography.X509Certificates;
54
55 namespace Mono.Net.Security.Private
56 {
57         /*
58          * Strictly private - do not use outside the Mono.Net.Security directory.
59          */
60         static class CallbackHelpers
61         {
62                 internal static MSI.MonoRemoteCertificateValidationCallback PublicToMono (RemoteCertificateValidationCallback callback)
63                 {
64                         if (callback == null)
65                                 return null;
66
67                         return (h, c, ch, e) => callback (h, c, (X509Chain)(object)ch, (SslPolicyErrors)e);
68                 }
69
70                 internal static MSI.MonoLocalCertificateSelectionCallback PublicToMono (LocalCertificateSelectionCallback callback)
71                 {
72                         if (callback == null)
73                                 return null;
74
75                         return (t, lc, rc, ai) => callback (null, t, (XX509CertificateCollection)(object)lc, rc, ai);
76                 }
77
78                 internal static MSI.MonoRemoteCertificateValidationCallback InternalToMono (RemoteCertValidationCallback callback)
79                 {
80                         if (callback == null)
81                                 return null;
82
83                         return (h, c, ch, e) => callback (h, c, (X509Chain)(object)ch, (SslPolicyErrors)e);
84                 }
85
86                 internal static RemoteCertificateValidationCallback InternalToPublic (string hostname, RemoteCertValidationCallback callback)
87                 {
88                         if (callback == null)
89                                 return null;
90
91                         return (s, c, ch, e) => callback (hostname, c, ch, e);
92                 }
93
94                 internal static MSI.MonoLocalCertificateSelectionCallback InternalToMono (LocalCertSelectionCallback callback)
95                 {
96                         if (callback == null)
97                                 return null;
98
99                         return (t, lc, rc, ai) => callback (t, (XX509CertificateCollection)(object)lc, rc, ai);
100                 }
101
102                 internal static RemoteCertificateValidationCallback MonoToPublic (MSI.MonoRemoteCertificateValidationCallback callback)
103                 {
104                         if (callback == null)
105                                 return null;
106
107                         return (t, c, ch, e) => callback (null, c, (XX509Chain)(object)ch, (MSI.MonoSslPolicyErrors)e);
108                 }
109
110                 internal static LocalCertificateSelectionCallback MonoToPublic (MSI.MonoLocalCertificateSelectionCallback callback)
111                 {
112                         if (callback == null)
113                                 return null;
114
115                         return (s, t, lc, rc, ai) => callback (t, (XX509CertificateCollection)(object)lc, rc, ai);
116                 }
117
118                 internal static RemoteCertValidationCallback MonoToInternal (MSI.MonoRemoteCertificateValidationCallback callback)
119                 {
120                         if (callback == null)
121                                 return null;
122
123                         return (h, c, ch, e) => callback (h, c, (XX509Chain)(object)ch, (MSI.MonoSslPolicyErrors)e);
124                 }
125
126                 internal static LocalCertSelectionCallback MonoToInternal (MSI.MonoLocalCertificateSelectionCallback callback)
127                 {
128                         if (callback == null)
129                                 return null;
130
131                         return (t, lc, rc, ai) => callback (t, (XX509CertificateCollection)(object)lc, rc, ai);
132                 }
133
134         }
135 }
136
137 #endif