Adjust corlib unit tests to reduce failures when executed on the NET_2_1 profile
[mono.git] / mcs / class / corlib / Test / System.Security.Cryptography / CryptoConfigTest.cs
1 //
2 // CryptoConfigTest.cs - NUnit Test Cases for CryptoConfig
3 //
4 // Author:
5 //      Sebastien Pouliot  <sebastien@ximian.com>
6 //
7 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
8 // Copyright (C) 2004-2007,2011 Novell, Inc (http://www.novell.com)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 using NUnit.Framework;
31 using System;
32 using System.Security.Cryptography;
33
34 namespace MonoTests.System.Security.Cryptography {
35
36 [TestFixture]
37 public class CryptoConfigTest {
38
39         void CreateFromName (string name, string objectname)
40         {
41                 object o = CryptoConfig.CreateFromName (name);
42                 if (objectname == null)
43                         Assert.IsNull (o, name);
44                 else
45                         Assert.AreEqual (objectname, o.ToString (), name);
46         }
47
48         [Test]
49         [ExpectedException (typeof (ArgumentNullException))]
50         public void CreateFromNameNull () 
51         {
52                 object o = CryptoConfig.CreateFromName (null);
53         }
54
55         // validate that CryptoConfig create the exact same implementation between mono and MS
56         [Test]
57         public void CreateFromName () 
58         {
59                 CreateFromName ("SHA", "System.Security.Cryptography.SHA1CryptoServiceProvider");
60                 // FIXME: We need to support the machine.config file to get exact same results
61                 // with the MS .NET Framework
62                 CreateFromName ("SHA1", "System.Security.Cryptography.SHA1CryptoServiceProvider");
63                 CreateFromName( "System.Security.Cryptography.SHA1", "System.Security.Cryptography.SHA1CryptoServiceProvider");
64                 // after installing the WSDK - changes to the machine.config file (not documented)
65 //              CreateFromName ("SHA1", "System.Security.Cryptography.SHA1Managed");
66 //              CreateFromName ("System.Security.Cryptography.SHA1", "System.Security.Cryptography.SHA1Managed");
67                 CreateFromName ("System.Security.Cryptography.HashAlgorithm", "System.Security.Cryptography.SHA1CryptoServiceProvider");
68                 CreateFromName ("System.Security.Cryptography.SHA1CryptoServiceProvider", "System.Security.Cryptography.SHA1CryptoServiceProvider");
69                 CreateFromName ("MD5", "System.Security.Cryptography.MD5CryptoServiceProvider");  
70                 CreateFromName ("System.Security.Cryptography.MD5", "System.Security.Cryptography.MD5CryptoServiceProvider");  
71                 CreateFromName ("System.Security.Cryptography.MD5CryptoServiceProvider", "System.Security.Cryptography.MD5CryptoServiceProvider");
72                 CreateFromName ("SHA256", "System.Security.Cryptography.SHA256Managed");  
73                 CreateFromName ("SHA-256", "System.Security.Cryptography.SHA256Managed");  
74                 CreateFromName ("System.Security.Cryptography.SHA256", "System.Security.Cryptography.SHA256Managed");  
75                 CreateFromName ("SHA384", "System.Security.Cryptography.SHA384Managed");  
76                 CreateFromName ("SHA-384", "System.Security.Cryptography.SHA384Managed");  
77                 CreateFromName ("System.Security.Cryptography.SHA384", "System.Security.Cryptography.SHA384Managed");  
78                 CreateFromName ("SHA512", "System.Security.Cryptography.SHA512Managed");  
79                 CreateFromName ("SHA-512", "System.Security.Cryptography.SHA512Managed");  
80                 CreateFromName ("System.Security.Cryptography.SHA512", "System.Security.Cryptography.SHA512Managed");  
81                 CreateFromName ("RSA", "System.Security.Cryptography.RSACryptoServiceProvider");  
82                 CreateFromName ("System.Security.Cryptography.RSA", "System.Security.Cryptography.RSACryptoServiceProvider");  
83                 CreateFromName ("System.Security.Cryptography.AsymmetricAlgorithm", "System.Security.Cryptography.RSACryptoServiceProvider");  
84                 CreateFromName ("DSA", "System.Security.Cryptography.DSACryptoServiceProvider");  
85                 CreateFromName ("System.Security.Cryptography.DSA", "System.Security.Cryptography.DSACryptoServiceProvider");  
86                 CreateFromName ("DES", "System.Security.Cryptography.DESCryptoServiceProvider");  
87                 CreateFromName ("System.Security.Cryptography.DES", "System.Security.Cryptography.DESCryptoServiceProvider");  
88                 CreateFromName ("3DES", "System.Security.Cryptography.TripleDESCryptoServiceProvider");  
89                 CreateFromName ("TripleDES", "System.Security.Cryptography.TripleDESCryptoServiceProvider");  
90                 CreateFromName ("Triple DES", "System.Security.Cryptography.TripleDESCryptoServiceProvider");  
91                 CreateFromName ("System.Security.Cryptography.TripleDES", "System.Security.Cryptography.TripleDESCryptoServiceProvider");  
92                 // LAMESPEC SymmetricAlgorithm documented as TripleDESCryptoServiceProvider
93                 CreateFromName ("System.Security.Cryptography.SymmetricAlgorithm", "System.Security.Cryptography.RijndaelManaged");  
94                 CreateFromName ("RC2", "System.Security.Cryptography.RC2CryptoServiceProvider");  
95                 CreateFromName ("System.Security.Cryptography.RC2", "System.Security.Cryptography.RC2CryptoServiceProvider");  
96                 CreateFromName ("Rijndael", "System.Security.Cryptography.RijndaelManaged");  
97                 CreateFromName ("System.Security.Cryptography.Rijndael", "System.Security.Cryptography.RijndaelManaged");
98                 // LAMESPEC Undocumented Names in CryptoConfig
99                 CreateFromName ("RandomNumberGenerator", "System.Security.Cryptography.RNGCryptoServiceProvider");
100                 CreateFromName ("System.Security.Cryptography.RandomNumberGenerator", "System.Security.Cryptography.RNGCryptoServiceProvider");
101                 CreateFromName ("System.Security.Cryptography.KeyedHashAlgorithm", "System.Security.Cryptography.HMACSHA1");
102                 CreateFromName ("HMACSHA1", "System.Security.Cryptography.HMACSHA1");
103                 CreateFromName ("System.Security.Cryptography.HMACSHA1", "System.Security.Cryptography.HMACSHA1");
104                 CreateFromName ("MACTripleDES", "System.Security.Cryptography.MACTripleDES");
105                 CreateFromName ("System.Security.Cryptography.MACTripleDES", "System.Security.Cryptography.MACTripleDES");
106 #if NET_2_0
107                 // new HMAC - new base class doesn't return anything with it's short name
108                 Assert.IsNull (CryptoConfig.CreateFromName ("HMAC"), "HMAC");
109                 CreateFromName ("System.Security.Cryptography.HMAC", "System.Security.Cryptography.HMACSHA1");
110                 CreateFromName ("HMACMD5", "System.Security.Cryptography.HMACMD5");
111                 CreateFromName ("System.Security.Cryptography.HMACMD5", "System.Security.Cryptography.HMACMD5");
112                 CreateFromName ("HMACRIPEMD160", "System.Security.Cryptography.HMACRIPEMD160");
113                 CreateFromName ("System.Security.Cryptography.HMACRIPEMD160", "System.Security.Cryptography.HMACRIPEMD160");
114                 CreateFromName ("HMACSHA256", "System.Security.Cryptography.HMACSHA256");
115                 CreateFromName ("System.Security.Cryptography.HMACSHA256", "System.Security.Cryptography.HMACSHA256");
116                 CreateFromName ("HMACSHA384", "System.Security.Cryptography.HMACSHA384");
117                 CreateFromName ("System.Security.Cryptography.HMACSHA384", "System.Security.Cryptography.HMACSHA384");
118                 CreateFromName ("HMACSHA512", "System.Security.Cryptography.HMACSHA512");
119                 CreateFromName ("System.Security.Cryptography.HMACSHA512", "System.Security.Cryptography.HMACSHA512");
120                 // new hash algorithm
121                 CreateFromName ("RIPEMD160", "System.Security.Cryptography.RIPEMD160Managed");
122                 CreateFromName ("RIPEMD-160", "System.Security.Cryptography.RIPEMD160Managed");
123                 CreateFromName ("System.Security.Cryptography.RIPEMD160", "System.Security.Cryptography.RIPEMD160Managed");
124                 // x.509 stuff
125 #if !TARGET_JVM //TargetJvmNotWorking - this algorithm should be added to System
126                 CreateFromName ("X509Chain", "System.Security.Cryptography.X509Certificates.X509Chain");
127 #endif
128 #endif
129                 // note: CryptoConfig can create any object !
130                 CreateFromName ("System.Security.Cryptography.CryptoConfig", "System.Security.Cryptography.CryptoConfig");
131                 CreateFromName ("System.IO.MemoryStream", "System.IO.MemoryStream");
132                 // non existing algo should return null (without exception)
133                 Assert.IsNull (CryptoConfig.CreateFromName ("NonExistingAlgorithm"), "NonExistingAlgorithm");
134         }
135
136         // additional names (URL) used for XMLDSIG (System.Security.Cryptography.Xml)
137         // URL taken from http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/
138         [Test]
139 #if NET_2_1
140         [Ignore ("System.Security.dll is not part of Moonlight, MonoTouch and Mono for Android")]
141 #endif
142         public void CreateFromURL () 
143         {
144                 // URL used in SignatureMethod element
145                 CreateFromName ("http://www.w3.org/2000/09/xmldsig#dsa-sha1", "System.Security.Cryptography.DSASignatureDescription");
146                 CreateFromName ("http://www.w3.org/2000/09/xmldsig#rsa-sha1", "System.Security.Cryptography.RSAPKCS1SHA1SignatureDescription");
147                 CreateFromName ("http://www.w3.org/2000/09/xmldsig#hmac-sha1", null);
148                 // URL used in DigestMethod element 
149                 CreateFromName ("http://www.w3.org/2000/09/xmldsig#sha1", "System.Security.Cryptography.SHA1CryptoServiceProvider");
150 #if !TARGET_JVM //TargetJvmNotWorking - algorithms from System.Security assembly
151                 // URL used in Canonicalization or Transform elements 
152                 CreateFromName ("http://www.w3.org/TR/2001/REC-xml-c14n-20010315", "System.Security.Cryptography.Xml.XmlDsigC14NTransform");
153                 CreateFromName ("http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments", "System.Security.Cryptography.Xml.XmlDsigC14NWithCommentsTransform");
154                 // URL used in Transform element 
155                 CreateFromName ("http://www.w3.org/2000/09/xmldsig#base64", "System.Security.Cryptography.Xml.XmlDsigBase64Transform");
156                 // after installing the WSDK - changes to the machine.config file (not documented)
157 //              CreateFromName ("http://www.w3.org/TR/1999/REC-xpath-19991116", "Microsoft.WSDK.Security.XmlDsigXPathTransform");
158                 CreateFromName ("http://www.w3.org/TR/1999/REC-xpath-19991116", "System.Security.Cryptography.Xml.XmlDsigXPathTransform");
159                 CreateFromName ("http://www.w3.org/TR/1999/REC-xslt-19991116", "System.Security.Cryptography.Xml.XmlDsigXsltTransform");
160                 CreateFromName ("http://www.w3.org/2000/09/xmldsig#enveloped-signature", "System.Security.Cryptography.Xml.XmlDsigEnvelopedSignatureTransform");
161                 // URL used in Reference element 
162                 CreateFromName ("http://www.w3.org/2000/09/xmldsig#Object", null);
163                 CreateFromName ("http://www.w3.org/2000/09/xmldsig#Manifest", null);
164                 CreateFromName ("http://www.w3.org/2000/09/xmldsig#SignatureProperties", null);
165                 // LAMESPEC: only documentated in ".NET Framework Security" book
166                 CreateFromName ("http://www.w3.org/2000/09/xmldsig# X509Data", "System.Security.Cryptography.Xml.KeyInfoX509Data");
167                 CreateFromName ("http://www.w3.org/2000/09/xmldsig# KeyName", "System.Security.Cryptography.Xml.KeyInfoName");
168                 CreateFromName ("http://www.w3.org/2000/09/xmldsig# KeyValue/DSAKeyValue", "System.Security.Cryptography.Xml.DSAKeyValue");
169                 CreateFromName ("http://www.w3.org/2000/09/xmldsig# KeyValue/RSAKeyValue", "System.Security.Cryptography.Xml.RSAKeyValue");
170                 CreateFromName ("http://www.w3.org/2000/09/xmldsig# RetrievalMethod", "System.Security.Cryptography.Xml.KeyInfoRetrievalMethod");
171 #if NET_2_0
172                 CreateFromName ("http://www.w3.org/2001/04/xmlenc#sha256", "System.Security.Cryptography.SHA256Managed");
173                 CreateFromName ("http://www.w3.org/2001/04/xmlenc#sha384", null);
174                 CreateFromName ("http://www.w3.org/2001/04/xmlenc#sha512", "System.Security.Cryptography.SHA512Managed");
175
176                 CreateFromName ("http://www.w3.org/2001/04/xmldsig-more#hmac-sha256", "System.Security.Cryptography.HMACSHA256");
177                 CreateFromName ("http://www.w3.org/2001/04/xmldsig-more#hmac-sha384", "System.Security.Cryptography.HMACSHA384");
178                 CreateFromName ("http://www.w3.org/2001/04/xmldsig-more#hmac-sha512", "System.Security.Cryptography.HMACSHA512");
179                 CreateFromName ("http://www.w3.org/2001/04/xmldsig-more#hmac-ripemd160", "System.Security.Cryptography.HMACRIPEMD160");
180 #endif
181 #endif
182         }
183
184         [Test]
185         public void CreateFromName_UpperCase () 
186         {
187                 CreateFromName ("SHA", "System.Security.Cryptography.SHA1CryptoServiceProvider");
188 #if NET_2_0
189                 CreateFromName ("SYSTEM.SECURITY.CRYPTOGRAPHY.TRIPLEDES", "System.Security.Cryptography.TripleDESCryptoServiceProvider");  
190                 CreateFromName ("HTTP://WWW.W3.ORG/2000/09/XMLDSIG#DSA-SHA1", "System.Security.Cryptography.DSASignatureDescription");
191 #else
192                 CreateFromName ("SYSTEM.SECURITY.CRYPTOGRAPHY.TRIPLEDES", null);  
193                 CreateFromName ("HTTP://WWW.W3.ORG/2000/09/XMLDSIG#DSA-SHA1", null);
194 #endif
195         }
196
197         [Test]
198         public void CreateFromName_LowerCase () 
199         {
200 #if NET_2_0
201                 CreateFromName ("sha", "System.Security.Cryptography.SHA1CryptoServiceProvider");
202                 CreateFromName ("system.security.cryptography.tripledes", "System.Security.Cryptography.TripleDESCryptoServiceProvider");  
203 #else
204                 CreateFromName ("sha", null);
205                 CreateFromName ("system.security.cryptography.tripledes", null);  
206 #endif
207                 CreateFromName ("http://www.w3.org/2000/09/xmldsig#dsa-sha1", "System.Security.Cryptography.DSASignatureDescription");
208         }
209
210         [Test]
211         public void CreateFromName_MixedCase () 
212         {
213 #if NET_2_0
214                 CreateFromName ("ShA", "System.Security.Cryptography.SHA1CryptoServiceProvider");
215                 CreateFromName ("SyStEm.SeCuRiTy.CrYpToGrApHy.TrIpLeDeS", "System.Security.Cryptography.TripleDESCryptoServiceProvider");  
216                 CreateFromName ("hTtP://wWw.W3.oRg/2000/09/xMlDsIg#dSa-sHa1", "System.Security.Cryptography.DSASignatureDescription");
217 #else
218                 CreateFromName ("ShA", null);
219                 CreateFromName ("SyStEm.SeCuRiTy.CrYpToGrApHy.TrIpLeDeS", null);  
220                 CreateFromName ("hTtP://wWw.W3.oRg/2000/09/xMlDsIg#dSa-sHa1", null);
221 #endif
222         }
223
224         // Tests created using "A Layer Man Guide to ASN.1" from RSA, page 19-20
225         // Need to find an OID ? goto http://www.alvestrand.no/~hta/objectid/top.html
226         static byte[] oidETSI = { 0x06, 0x03, 0x04, 0x00, 0x00 };
227         static byte[] oidSHA1 = { 0x06, 0x05, 0x2B, 0x0E, 0x03, 0x02, 0x1A };
228         static byte[] oidASN1CharacterModule = { 0x06, 0x04, 0x51, 0x00, 0x00, 0x00 };
229         static byte[] oidmd5withRSAEncryption = { 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x04 };
230
231         [Test]
232 #if NET_2_0
233         [ExpectedException (typeof (ArgumentNullException))]
234 #else
235         [ExpectedException (typeof (NullReferenceException))]
236 #endif
237         public void EncodeOIDNull () 
238         {
239                 byte[] o = CryptoConfig.EncodeOID (null);
240         }
241
242         [Test]
243         public void EncodeOID () 
244         {
245                 // OID starts with 0, 1 or 2
246                 Assert.AreEqual (oidETSI, CryptoConfig.EncodeOID ("0.4.0.0"), "OID starting with 0.");
247                 Assert.AreEqual (oidSHA1, CryptoConfig.EncodeOID ("1.3.14.3.2.26"), "OID starting with 1.");
248                 Assert.AreEqual (oidASN1CharacterModule, CryptoConfig.EncodeOID ("2.1.0.0.0"), "OID starting with 2.");
249                 // OID numbers can span multiple bytes
250                 Assert.AreEqual (oidmd5withRSAEncryption, CryptoConfig.EncodeOID ("1.2.840.113549.1.1.4"), "OID with numbers spanning multiple bytes");
251         }
252
253         [Test]
254         [ExpectedException (typeof (CryptographicUnexpectedOperationException))]
255         // LAMESPEC: OID greater that 0x7F (127) bytes aren't supported by the MS Framework
256         public void EncodeOID_BiggerThan127bytes () 
257         {
258                 // "ms"-invalid OID - greater than 127 bytes (length encoding)
259                 // OID longer than 127 bytes (so length must be encoded on multiple bytes)
260                 string baseOID = "1.3.6.1.4.1.11071.0.";
261                 string lastPart = "1111111111"; // must fit in int32
262                 for (int i = 1; i < 30; i++) {
263                         baseOID += lastPart + ".";
264                 }
265                 baseOID += "0";
266                 byte[] tooLongOID = CryptoConfig.EncodeOID (baseOID);
267         }
268                 
269         [Test]
270         [ExpectedException (typeof (OverflowException))]
271         // LAMESPEC: OID with numbers > Int32 aren't supported by the MS BCL
272         public void EncodeOID_BiggerThanInt32 () 
273         {
274                 // "ms"-invalid OID - where a number of the OID > Int32
275                 byte[] tooLongOID = CryptoConfig.EncodeOID ("1.1.4294967295");
276         }
277
278         [Test]
279         public void EncodeOID_InvalidStart () 
280         {
281                 // invalid OID - must start with 0, 1 or 2
282                 // however it works with MS BCL
283                 byte[] oid3 = CryptoConfig.EncodeOID ("3.0");
284                 byte[] res3 = { 0x06, 0x01, 0x78 };
285                 Assert.AreEqual (res3, oid3, "OID: 3.0");
286         }
287
288         [Test]
289         [ExpectedException (typeof (CryptographicUnexpectedOperationException))]
290         public void EncodeOID_TooShort () 
291         {
292                 // invalid OID - must have at least 2 parts (according to X.208)
293                 byte[] tooShortOID = CryptoConfig.EncodeOID ("0");
294         }
295
296         [Test]
297         public void EncodeOID_InvalidSecondPart () 
298         {
299                 // invalid OID - second value < 40 for 0. and 1. (modulo 40)
300                 // however it works with MS BCL
301                 byte[] tooBigSecondPartOID = CryptoConfig.EncodeOID ("0.40");
302                 byte[] tooBigSecondPartRes = { 0x06, 0x01, 0x28 };
303                 Assert.AreEqual (tooBigSecondPartRes, tooBigSecondPartOID, "OID: 0.40");
304         }
305
306         [Test]
307         [ExpectedException (typeof (ArgumentNullException))]
308         public void MapNameToOIDNull () 
309         {
310                 CryptoConfig.MapNameToOID (null);
311         }
312
313         private void MapNameToOID (string name, string oid)
314         {
315                 Assert.AreEqual (oid, CryptoConfig.MapNameToOID (name), "oid(" + name + ")");
316         }
317
318         // LAMESPEC: doesn't support all names defined in CryptoConfig 
319         // non supported names (in MSFW) are commented or null-ed
320         // LAMESPEC: undocumented but full class name is supported
321         [Test]
322         public void MapNameToOID() 
323         {
324 //              MapNameToOID ("SHA", "1.3.14.3.2.26");
325                 MapNameToOID ("SHA1", "1.3.14.3.2.26");
326                 MapNameToOID ("System.Security.Cryptography.SHA1", "1.3.14.3.2.26");
327 //              MapNameToOID ("System.Security.Cryptography.HashAlgorithm", "1.3.14.3.2.26");
328                 MapNameToOID ("System.Security.Cryptography.SHA1CryptoServiceProvider", "1.3.14.3.2.26");
329                 MapNameToOID ("System.Security.Cryptography.SHA1Managed", "1.3.14.3.2.26");
330                 MapNameToOID ("MD5", "1.2.840.113549.2.5");
331                 MapNameToOID ("System.Security.Cryptography.MD5", "1.2.840.113549.2.5");
332                 MapNameToOID ("System.Security.Cryptography.MD5CryptoServiceProvider", "1.2.840.113549.2.5");
333 #if NET_2_0
334                 MapNameToOID ("SHA256", "2.16.840.1.101.3.4.2.1");
335                 MapNameToOID ("System.Security.Cryptography.SHA256", "2.16.840.1.101.3.4.2.1");
336                 MapNameToOID ("System.Security.Cryptography.SHA256Managed", "2.16.840.1.101.3.4.2.1");
337                 MapNameToOID ("SHA384", "2.16.840.1.101.3.4.2.2");
338                 MapNameToOID ("System.Security.Cryptography.SHA384", "2.16.840.1.101.3.4.2.2");
339                 MapNameToOID ("System.Security.Cryptography.SHA384Managed", "2.16.840.1.101.3.4.2.2");
340                 MapNameToOID ("SHA512", "2.16.840.1.101.3.4.2.3");
341                 MapNameToOID ("System.Security.Cryptography.SHA512", "2.16.840.1.101.3.4.2.3");
342                 MapNameToOID ("System.Security.Cryptography.SHA512Managed", "2.16.840.1.101.3.4.2.3");
343                 MapNameToOID ("RIPEMD160", "1.3.36.3.2.1");
344                 MapNameToOID ("System.Security.Cryptography.RIPEMD160", "1.3.36.3.2.1");
345                 MapNameToOID ("System.Security.Cryptography.RIPEMD160Managed", "1.3.36.3.2.1");
346 #else
347                 MapNameToOID ("SHA256", "2.16.840.1.101.3.4.1");
348 //              MapNameToOID ("SHA-256", "2.16.840.1.101.3.4.1");
349                 MapNameToOID ("System.Security.Cryptography.SHA256", "2.16.840.1.101.3.4.1");
350                 MapNameToOID ("System.Security.Cryptography.SHA256Managed", "2.16.840.1.101.3.4.1");
351                 MapNameToOID ("SHA384", "2.16.840.1.101.3.4.2");
352 //              MapNameToOID ("SHA-384", "2.16.840.1.101.3.4.2");
353                 MapNameToOID ("System.Security.Cryptography.SHA384", "2.16.840.1.101.3.4.2");
354                 MapNameToOID ("System.Security.Cryptography.SHA384Managed", "2.16.840.1.101.3.4.2");
355                 MapNameToOID ("SHA512", "2.16.840.1.101.3.4.3");
356 //              MapNameToOID ("SHA-512", "2.16.840.1.101.3.4.3");
357                 MapNameToOID ("System.Security.Cryptography.SHA512", "2.16.840.1.101.3.4.3");
358                 MapNameToOID ("System.Security.Cryptography.SHA512Managed", "2.16.840.1.101.3.4.3");
359 #endif
360                 // LAMESPEC: only documentated in ".NET Framework Security" book
361                 MapNameToOID ("TripleDESKeyWrap", "1.2.840.113549.1.9.16.3.6");
362 #if NET_2_0
363                 // new OID defined in Fx 2.0
364                 MapNameToOID ("DES", "1.3.14.3.2.7");
365                 MapNameToOID ("TripleDES", "1.2.840.113549.3.7");
366                 MapNameToOID ("RC2", "1.2.840.113549.3.2");
367 #else
368                 // no OID defined before Fx 2.0
369                 MapNameToOID ("DES", null);
370                 MapNameToOID ("TripleDES", null);
371                 MapNameToOID ("RC2", null);
372 #endif
373                 MapNameToOID ("RSA", null);
374                 MapNameToOID ("DSA", null);
375                 MapNameToOID ("3DES", null);
376                 // no OID defined ?
377                 MapNameToOID ("System.Security.Cryptography.RSA", null);
378                 MapNameToOID ("System.Security.Cryptography.AsymmetricAlgorithm", null);
379                 MapNameToOID ("System.Security.Cryptography.DSA", null);
380                 MapNameToOID ("System.Security.Cryptography.DES", null);
381                 MapNameToOID ("Triple DES", null);
382                 MapNameToOID ("System.Security.Cryptography.TripleDES", null);
383                 MapNameToOID ("System.Security.Cryptography.RC2", null);
384                 MapNameToOID ("Rijndael", null);
385                 MapNameToOID ("System.Security.Cryptography.Rijndael", null);
386                 MapNameToOID ("System.Security.Cryptography.SymmetricAlgorithm", null);
387                 // LAMESPEC Undocumented Names in CryptoConfig
388                 MapNameToOID ("RandomNumberGenerator", null);
389                 MapNameToOID ("System.Security.Cryptography.RandomNumberGenerator", null);
390                 MapNameToOID ("System.Security.Cryptography.KeyedHashAlgorithm", null);
391 #if NET_2_0
392                 MapNameToOID ("HMAC", null);
393                 MapNameToOID ("System.Security.Cryptography.HMAC", null);
394                 MapNameToOID ("HMACMD5", null);
395                 MapNameToOID ("System.Security.Cryptography.HMACMD5", null);
396                 MapNameToOID ("HMACRIPEMD160", null);
397                 MapNameToOID ("System.Security.Cryptography.HMACRIPEMD160", null);
398                 MapNameToOID ("HMACSHA256", null);
399                 MapNameToOID ("System.Security.Cryptography.HMACSHA256", null);
400                 MapNameToOID ("HMACSHA384", null);
401                 MapNameToOID ("System.Security.Cryptography.HMACSHA384", null);
402                 MapNameToOID ("HMACSHA512", null);
403                 MapNameToOID ("System.Security.Cryptography.HMACSHA512", null);
404 #endif
405                 MapNameToOID ("HMACSHA1", null);
406                 MapNameToOID ("System.Security.Cryptography.HMACSHA1", null);
407                 MapNameToOID ("MACTripleDES", null);
408                 MapNameToOID ("System.Security.Cryptography.MACTripleDES", null);
409                 // non existing algo should return null (without exception)
410                 MapNameToOID ("NonExistingAlgorithm", null);
411         }
412
413         [Test]
414         public void MapNameToOID_UpperCase () 
415         {
416                 MapNameToOID ("SHA1", "1.3.14.3.2.26");
417 #if NET_2_0
418                 MapNameToOID ("SYSTEM.SECURITY.CRYPTOGRAPHY.MD5CRYPTOSERVICEPROVIDER", "1.2.840.113549.2.5");
419 #else
420                 MapNameToOID ("SYSTEM.SECURITY.CRYPTOGRAPHY.MD5CRYPTOSERVICEPROVIDER", null);
421 #endif
422         }
423
424         [Test]
425         public void MapNameToOID_LowerCase () 
426         {
427 #if NET_2_0
428                 MapNameToOID ("sha1", "1.3.14.3.2.26");
429                 MapNameToOID ("system.security.cryptography.md5cryptoserviceprovider", "1.2.840.113549.2.5");
430 #else
431                 MapNameToOID ("sha1", null);
432                 MapNameToOID ("system.security.cryptography.md5cryptoserviceprovider", null);
433 #endif
434         }
435
436         [Test]
437         public void MapNameToOID_MixedCase () 
438         {
439 #if NET_2_0
440                 MapNameToOID ("sHa1", "1.3.14.3.2.26");
441                 MapNameToOID ("SySteM.SeCuRiTy.CrYpToGrApHy.Md5cRyPtOsErViCePrOvIdEr", "1.2.840.113549.2.5");
442 #else
443                 MapNameToOID ("sHa1", null);
444                 MapNameToOID ("SySteM.SeCuRiTy.CrYpToGrApHy.Md5cRyPtOsErViCePrOvIdEr", null);
445 #endif
446         }
447
448         [Test]
449         public void CCToString () 
450         {
451                 // under normal circumstance there are no need to create a CryptoConfig object
452                 // because all interesting stuff are in static methods
453                 CryptoConfig cc = new CryptoConfig ();
454                 Assert.AreEqual ("System.Security.Cryptography.CryptoConfig", cc.ToString ());
455         }
456 }
457
458 }