2 // AlgorithmIdentifierTest.cs - NUnit tests for AlgorithmIdentifier
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
8 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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.
31 using NUnit.Framework;
34 using System.Security.Cryptography;
35 using System.Security.Cryptography.Pkcs;
37 namespace MonoTests.System.Security.Cryptography.Pkcs {
40 public class AlgorithmIdentifierTest {
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";
47 public void ConstructorEmpty ()
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");
57 public void ConstructorOid ()
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");
67 //BUG [ExpectedException (typeof (ArgumentNullException))]
68 public void ConstructorOidNull ()
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");
77 public void ConstructorOidKeyLength ()
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");
87 //BUG [ExpectedException (typeof (ArgumentNullException))]
88 public void ConstructorOidNullKeyLength ()
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");
97 //BUG [ExpectedException (typeof (ArgumentOutOfRangeException))]
98 public void ConstructorOidKeyLengthNegative ()
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");
108 public void KeyLength ()
110 AlgorithmIdentifier ai = new AlgorithmIdentifier ();
111 ai.KeyLength = Int32.MaxValue;
112 Assert.AreEqual (Int32.MaxValue, ai.KeyLength, "KeyLength-Max");
114 Assert.AreEqual (0, ai.KeyLength, "KeyLength-Zero");
115 ai.KeyLength = Int32.MinValue;
116 Assert.AreEqual (Int32.MinValue, ai.KeyLength, "KeyLength-Min");
122 AlgorithmIdentifier ai = new AlgorithmIdentifier ();
123 ai.Oid = new Oid (validOid);
124 Assert.AreEqual (validOid, ai.Oid.Value, "Oid");
126 Assert.IsNull (ai.Oid, "Oid-Null");
130 public void Parameters ()
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");