Merge pull request #1542 from ninjarobot/UriTemplateMatchException
[mono.git] / mcs / class / System.Security / Test / System.Security.Cryptography.Pkcs / AlgorithmIdentifierTest.cs
1 //
2 // AlgorithmIdentifierTest.cs - NUnit tests for AlgorithmIdentifier
3 //
4 // Author:
5 //      Sebastien Pouliot  <sebastien@ximian.com>
6 //
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
8 // Copyright (C) 2004 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
31 using NUnit.Framework;
32
33 using System;
34 using System.Security.Cryptography;
35 using System.Security.Cryptography.Pkcs;
36
37 namespace MonoTests.System.Security.Cryptography.Pkcs {
38
39         [TestFixture]
40         public class AlgorithmIdentifierTest {
41
42                 static string defaultOid = "1.2.840.113549.3.7";
43                 static string defaultName = "3des";
44                 static string validOid = "1.2.840.113549.1.1.1";
45
46                 [Test]
47                 public void ConstructorEmpty () 
48                 {
49                         AlgorithmIdentifier ai = new AlgorithmIdentifier ();
50                         Assert.AreEqual (0, ai.KeyLength, "KeyLength");
51                         Assert.AreEqual (defaultName, ai.Oid.FriendlyName, "Oid.FriendlyName");
52                         Assert.AreEqual (defaultOid, ai.Oid.Value, "Oid.Value");
53                         Assert.AreEqual (0, ai.Parameters.Length, "Parameters");
54                 }
55
56                 [Test]
57                 public void ConstructorOid () 
58                 {
59                         Oid o = new Oid (validOid);
60                         AlgorithmIdentifier ai = new AlgorithmIdentifier (o);
61                         Assert.AreEqual (0, ai.KeyLength, "KeyLength");
62                         Assert.AreEqual (validOid, ai.Oid.Value, "Oid");
63                         Assert.AreEqual (0, ai.Parameters.Length, "Parameters");
64                 }
65
66                 [Test]
67                 //BUG [ExpectedException (typeof (ArgumentNullException))]
68                 public void ConstructorOidNull () 
69                 {
70                         AlgorithmIdentifier ai = new AlgorithmIdentifier (null);
71                         Assert.IsNull (ai.Oid, "Oid");
72                         Assert.AreEqual (0, ai.KeyLength, "KeyLength");
73                         Assert.AreEqual (0, ai.Parameters.Length, "Parameters");
74                 }
75
76                 [Test]
77                 public void ConstructorOidKeyLength ()
78                 {
79                         Oid o = new Oid (validOid);
80                         AlgorithmIdentifier ai = new AlgorithmIdentifier (o, 128);
81                         Assert.AreEqual (128, ai.KeyLength, "KeyLength");
82                         Assert.AreEqual (validOid, ai.Oid.Value, "Oid");
83                         Assert.AreEqual (0, ai.Parameters.Length, "Parameters");
84                 }
85
86                 [Test]
87                 //BUG [ExpectedException (typeof (ArgumentNullException))]
88                 public void ConstructorOidNullKeyLength () 
89                 {
90                         AlgorithmIdentifier ai = new AlgorithmIdentifier (null, 128);
91                         Assert.IsNull (ai.Oid, "Oid");
92                         Assert.AreEqual (128, ai.KeyLength, "KeyLength");
93                         Assert.AreEqual (0, ai.Parameters.Length, "Parameters");
94                 }
95
96                 [Test]
97                 //BUG [ExpectedException (typeof (ArgumentOutOfRangeException))]
98                 public void ConstructorOidKeyLengthNegative () 
99                 {
100                         Oid o = new Oid (validOid);
101                         AlgorithmIdentifier ai = new AlgorithmIdentifier (o, -1);
102                         Assert.AreEqual (-1, ai.KeyLength, "KeyLength");
103                         Assert.AreEqual (validOid, ai.Oid.Value, "Oid");
104                         Assert.AreEqual (0, ai.Parameters.Length, "Parameters");
105                 }
106
107                 [Test]
108                 public void KeyLength () 
109                 {
110                         AlgorithmIdentifier ai = new AlgorithmIdentifier ();
111                         ai.KeyLength = Int32.MaxValue;
112                         Assert.AreEqual (Int32.MaxValue, ai.KeyLength, "KeyLength-Max");
113                         ai.KeyLength = 0;
114                         Assert.AreEqual (0, ai.KeyLength, "KeyLength-Zero");
115                         ai.KeyLength = Int32.MinValue;
116                         Assert.AreEqual (Int32.MinValue, ai.KeyLength, "KeyLength-Min");
117                 }
118
119                 [Test]
120                 public void Oid () 
121                 {
122                         AlgorithmIdentifier ai = new AlgorithmIdentifier ();
123                         ai.Oid = new Oid (validOid);
124                         Assert.AreEqual (validOid, ai.Oid.Value, "Oid");
125                         ai.Oid = null;
126                         Assert.IsNull (ai.Oid, "Oid-Null");
127                 }
128
129                 [Test]
130                 public void Parameters () 
131                 {
132                         AlgorithmIdentifier ai = new AlgorithmIdentifier ();
133                         ai.Parameters = new byte[2] { 0x05, 0x00 }; // ASN.1 NULL
134                         Assert.AreEqual ("05-00", BitConverter.ToString (ai.Parameters), "Parameters");
135                         ai.Parameters = null;
136                         Assert.IsNull (ai.Parameters, "Parameters-Null");
137                 }
138         }
139 }
140