Merge pull request #498 from Unroll-Me/master
[mono.git] / mcs / class / corlib / System.Security.Cryptography / CryptoConfig.fullaot.cs
1 //
2 // CryptoConfig.cs: Handles cryptographic implementations and OIDs mappings.
3 //
4 // Authors:
5 //      Sebastien Pouliot (sebastien@xamarin.com)
6 //      Tim Coleman (tim@timcoleman.com)
7 //
8 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
9 // Copyright (C) Tim Coleman, 2004
10 // Copyright (C) 2004-2007,2011 Novell, Inc (http://www.novell.com)
11 // Copyright 2011 Xamarin, Inc. (http://www.xamarin.com)
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 //
32
33 #if FULL_AOT_RUNTIME
34
35 // This is a special version of CryptoConfig that is not configurable and
36 // every "choice" is statiscally compiled. As long as CreateFromName is not
37 // used the linker will be able to eliminate the crypto code from the applications
38
39 using System.Runtime.InteropServices;
40 using System.Security.Permissions;
41
42 namespace System.Security.Cryptography {
43
44         [ComVisible (true)]
45         public partial class CryptoConfig {
46
47                 // try to avoid hitting the CreateFromName overloads to help the linker
48
49                 public static object CreateFromName (string name)
50                 {
51                         return CreateFromName (name, null);
52                 }
53
54                 [PermissionSet (SecurityAction.LinkDemand, Unrestricted = true)]
55                 public static object CreateFromName (string name, params object[] args)
56                 {
57                         if (name == null)
58                                 throw new ArgumentNullException ("name");
59
60                         switch (name.ToLowerInvariant ()) {
61                         case "system.security.cryptography.dsacryptoserviceprovider":
62                         case "system.security.cryptography.dsa":
63                         case "dsa":
64                                 return new DSACryptoServiceProvider ();
65                         case "system.security.cryptography.dsasignaturedeformatter":
66                                 return new DSASignatureDeformatter ();
67                         case "system.security.cryptography.dsasignatureformatter":
68                                 return new DSASignatureFormatter ();
69                         case "system.security.cryptography.dsasignaturedescription":
70                         case "http://www.w3.org/2000/09/xmldsig#dsa-sha1":
71                                 return new DSASignatureDescription ();
72                         case "system.security.cryptography.descryptoserviceprovider":
73                         case "system.security.cryptography.des":
74                         case "des":
75                                 return new DESCryptoServiceProvider ();
76                         case "system.security.cryptography.hmacmd5":
77                         case "hmacmd5":
78                                 return new HMACMD5 ();
79                         case "system.security.cryptography.hmacripemd160":
80                         case "hmacripemd160":
81                         case "http://www.w3.org/2001/04/xmldsig-more#hmac-ripemd160":
82                                 return new HMACRIPEMD160 ();
83                         case "system.security.cryptography.keyedhashalgorithm":
84                         case "system.security.cryptography.hmac":
85                         case "system.security.cryptography.hmacsha1":
86                         case "hmacsha1":
87                                 return new HMACSHA1 ();
88                         case "system.security.cryptography.hmacsha256":
89                         case "hmacsha256":
90                         case "http://www.w3.org/2001/04/xmldsig-more#hmac-sha256":
91                                 return new HMACSHA256 ();
92                         case "system.security.cryptography.hmacsha384":
93                         case "hmacsha384":
94                         case "http://www.w3.org/2001/04/xmldsig-more#hmac-sha384":
95                                 return new HMACSHA384 ();
96                         case "system.security.cryptography.hmacsha512":
97                         case "hmacsha512":
98                         case "http://www.w3.org/2001/04/xmldsig-more#hmac-sha512":
99                                 return new HMACSHA512 ();
100                         case "system.security.cryptography.mactripledes":
101                         case "mactripledes":
102                                 return new MACTripleDES ();
103                         case "system.security.cryptography.md5cryptoserviceprovider":
104                         case "system.security.cryptography.md5":
105                         case "md5":
106                                 return new MD5CryptoServiceProvider ();
107                         case "system.security.cryptography.rc2cryptoserviceprovider":
108                         case "system.security.cryptography.rc2":
109                         case "rc2":
110                                 return new RC2CryptoServiceProvider ();
111                         case "system.security.cryptography.symmetricalgorithm":
112                         case "system.security.cryptography.rijndaelmanaged":
113                         case "system.security.cryptography.rijndael":
114                         case "rijndael":
115                                 return new RijndaelManaged ();
116                         case "system.security.cryptography.ripemd160managed":
117                         case "system.security.cryptography.ripemd160":
118                         case "ripemd-160":
119                         case "ripemd160":
120                                 return new RIPEMD160Managed ();
121                         case "system.security.cryptography.rngcryptoserviceprovider":
122                         case "system.security.cryptography.randomnumbergenerator":
123                         case "randomnumbergenerator":
124                                 return new RNGCryptoServiceProvider ();
125                         case "system.security.cryptography.asymmetricalgorithm":
126                         case "system.security.cryptography.rsa":
127                         case "rsa":
128                                 return new RSACryptoServiceProvider ();
129                         case "system.security.cryptography.rsapkcs1signaturedeformatter":
130                                 return new RSAPKCS1SignatureDeformatter ();
131                         case "system.security.cryptography.rsapkcs1signatureformatter":
132                                 return new RSAPKCS1SignatureFormatter ();
133                         case "system.security.cryptography.rsapkcs1sha1signaturedescription":
134                         case "http://www.w3.org/2000/09/xmldsig#rsa-sha1":
135                                 return new RSAPKCS1SHA1SignatureDescription ();
136                         case "system.security.cryptography.hashalgorithm":
137                         case "system.security.cryptography.sha1":
138                         case "system.security.cryptography.sha1cryptoserviceprovider":
139                         case "sha1":
140                         case "sha":
141                         case "http://www.w3.org/2000/09/xmldsig#sha1":
142                                 return new SHA1CryptoServiceProvider ();
143                         case "system.security.cryptography.sha1managed":
144                                 return new SHA1Managed ();
145                         case "system.security.cryptography.sha256managed":
146                         case "system.security.cryptography.sha256":
147                         case "sha256":
148                         case "sha-256":
149                         case "http://www.w3.org/2001/04/xmlenc#sha256":
150                                 return new SHA256Managed ();
151                         case "system.security.cryptography.sha384managed":
152                         case "system.security.cryptography.sha384":
153                         case "sha384":
154                         case "sha-384":
155                                 return new SHA384Managed ();
156                         case "system.security.cryptography.sha512managed":
157                         case "system.security.cryptography.sha512":
158                         case "sha512":
159                         case "sha-512":
160                         case "http://www.w3.org/2001/04/xmlenc#sha512":
161                                 return new SHA512Managed ();
162                         case "system.security.cryptography.tripledescryptoserviceprovider":
163                         case "system.security.cryptography.tripledes":
164                         case "triple des":
165                         case "tripledes":
166                         case "3des":
167                                 return new TripleDESCryptoServiceProvider ();
168                         default:
169                                 // method doesn't throw any exception
170                                 return null;
171                         }
172                 }
173
174                 public static string MapNameToOID (string name)
175                 {
176                         if (name == null)
177                                 throw new ArgumentNullException ("name");
178
179                         switch (name.ToLowerInvariant ()) {
180                         case "system.security.cryptography.sha1cryptoserviceprovider":
181                         case "system.security.cryptography.sha1managed":
182                         case "system.security.cryptography.sha1":
183                         case "sha1":
184                                 return "1.3.14.3.2.26";
185                         case "system.security.cryptography.md5cryptoserviceprovider":
186                         case "system.security.cryptography.md5":
187                         case "md5":
188                                 return "1.2.840.113549.2.5";
189                         case "system.security.cryptography.sha256managed":
190                         case "system.security.cryptography.sha256":
191                         case "sha256":
192                                 return "2.16.840.1.101.3.4.2.1";
193                         case "system.security.cryptography.sha384managed":
194                         case "system.security.cryptography.sha384":
195                         case "sha384":
196                                 return "2.16.840.1.101.3.4.2.2";
197                         case "system.security.cryptography.sha512managed":
198                         case "system.security.cryptography.sha512":
199                         case "sha512":
200                                 return "2.16.840.1.101.3.4.2.3";
201                         case "system.security.cryptography.ripemd160managed":
202                         case "system.security.cryptography.ripemd160":
203                         case "ripemd160":
204                                 return "1.3.36.3.2.1";
205                         case "tripledeskeywrap":
206                                 return "1.2.840.113549.1.9.16.3.6";
207                         case "des":
208                                 return "1.3.14.3.2.7";
209                         case "tripledes":
210                                 return "1.2.840.113549.3.7";
211                         case "rc2":
212                                 return "1.2.840.113549.3.2";
213                         default:
214                                 return null;
215                         }
216                 }
217         }
218 }
219
220 #endif