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