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.
32 using NUnit
.Framework
;
35 using System
.Security
.Cryptography
;
36 using System
.Security
.Cryptography
.Pkcs
;
38 namespace MonoTests
.System
.Security
.Cryptography
.Pkcs
{
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";
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
);
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
);
68 //BUG [ExpectedException (typeof (ArgumentNullException))]
69 public void ConstructorOidNull ()
71 AlgorithmIdentifier ai
= new AlgorithmIdentifier (null);
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
);
85 //BUG [ExpectedException (typeof (ArgumentNullException))]
86 public void ConstructorOidNullKeyLength ()
88 AlgorithmIdentifier ai
= new AlgorithmIdentifier (null, 128);
92 //BUG [ExpectedException (typeof (ArgumentOutOfRangeException))]
93 public void ConstructorOidKeyLengthNegative ()
95 Oid o
= new Oid (validOid
);
96 AlgorithmIdentifier ai
= new AlgorithmIdentifier (o
, -1);
100 public void KeyLength ()
102 AlgorithmIdentifier ai
= new AlgorithmIdentifier ();
103 ai
.KeyLength
= Int32
.MaxValue
;
104 AssertEquals ("KeyLength-Max", Int32
.MaxValue
, ai
.KeyLength
);
106 AssertEquals ("KeyLength-Zero", 0, ai
.KeyLength
);
107 ai
.KeyLength
= Int32
.MinValue
;
108 AssertEquals ("KeyLength-Min", Int32
.MinValue
, ai
.KeyLength
);
114 AlgorithmIdentifier ai
= new AlgorithmIdentifier ();
115 ai
.Oid
= new Oid (validOid
);
116 AssertEquals ("Oid", validOid
, ai
.Oid
.Value
);
118 AssertNull ("Oid", ai
.Oid
);
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
);