**** Merged from MCS ****
[mono-project.git] / mcs / class / System.Security / Test / System.Security.Cryptography.Pkcs / AlgorithmIdentifierTest.cs
blobe1e73be2bb001bf28226319e090a628c0e124015
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.
30 #if NET_2_0
32 using NUnit.Framework;
34 using System;
35 using System.Security.Cryptography;
36 using System.Security.Cryptography.Pkcs;
38 namespace MonoTests.System.Security.Cryptography.Pkcs {
40 [TestFixture]
41 public class AlgorithmIdentifierTest : Assertion {
43 static string defaultOid = "1.2.840.113549.3.7";
44 static string defaultName = "3des";
45 static string validOid = "1.2.840.113549.1.1.1";
47 [Test]
48 public void ConstructorEmpty ()
50 AlgorithmIdentifier ai = new AlgorithmIdentifier ();
51 AssertEquals ("KeyLength", 0, ai.KeyLength);
52 AssertEquals ("Oid.FriendlyName", defaultName, ai.Oid.FriendlyName);
53 AssertEquals ("Oid.Value", defaultOid, ai.Oid.Value);
54 AssertEquals ("Parameters", 0, ai.Parameters.Length);
57 [Test]
58 public void ConstructorOid ()
60 Oid o = new Oid (validOid);
61 AlgorithmIdentifier ai = new AlgorithmIdentifier (o);
62 AssertEquals ("KeyLength", 0, ai.KeyLength);
63 AssertEquals ("Oid", validOid, ai.Oid.Value);
64 AssertEquals ("Parameters", 0, ai.Parameters.Length);
67 [Test]
68 //BUG [ExpectedException (typeof (ArgumentNullException))]
69 public void ConstructorOidNull ()
71 AlgorithmIdentifier ai = new AlgorithmIdentifier (null);
74 [Test]
75 public void ConstructorOidKeyLength ()
77 Oid o = new Oid (validOid);
78 AlgorithmIdentifier ai = new AlgorithmIdentifier (o, 128);
79 AssertEquals ("KeyLength", 128, ai.KeyLength);
80 AssertEquals ("Oid", validOid, ai.Oid.Value);
81 AssertEquals ("Parameters", 0, ai.Parameters.Length);
84 [Test]
85 //BUG [ExpectedException (typeof (ArgumentNullException))]
86 public void ConstructorOidNullKeyLength ()
88 AlgorithmIdentifier ai = new AlgorithmIdentifier (null, 128);
91 [Test]
92 //BUG [ExpectedException (typeof (ArgumentOutOfRangeException))]
93 public void ConstructorOidKeyLengthNegative ()
95 Oid o = new Oid (validOid);
96 AlgorithmIdentifier ai = new AlgorithmIdentifier (o, -1);
99 [Test]
100 public void KeyLength ()
102 AlgorithmIdentifier ai = new AlgorithmIdentifier ();
103 ai.KeyLength = Int32.MaxValue;
104 AssertEquals ("KeyLength-Max", Int32.MaxValue, ai.KeyLength);
105 ai.KeyLength = 0;
106 AssertEquals ("KeyLength-Zero", 0, ai.KeyLength);
107 ai.KeyLength = Int32.MinValue;
108 AssertEquals ("KeyLength-Min", Int32.MinValue, ai.KeyLength);
111 [Test]
112 public void Oid ()
114 AlgorithmIdentifier ai = new AlgorithmIdentifier ();
115 ai.Oid = new Oid (validOid);
116 AssertEquals ("Oid", validOid, ai.Oid.Value);
117 ai.Oid = null;
118 AssertNull ("Oid", ai.Oid);
121 [Test]
122 public void Parameters ()
124 AlgorithmIdentifier ai = new AlgorithmIdentifier ();
125 ai.Parameters = new byte[2] { 0x05, 0x00 }; // ASN.1 NULL
126 AssertEquals ("Oid", "05-00", BitConverter.ToString (ai.Parameters));
127 ai.Parameters = null;
128 AssertNull ("Parameters", ai.Parameters);
133 #endif