* AsnEncodedDataTest.cs: Fixed for Fx 2.0 beta1.
* CryptographicAttributeTest.cs: New. Moved from S.S.C.Pkcs.
* OidTest.cs: Fixed for Fx 2.0 beta1.
svn path=/trunk/mcs/; revision=30939
// AsnEncodedDataTest.cs - NUnit tests for AsnEncodedData
//
// Author:
-// Sebastien Pouliot (spouliot@motus.com)
+// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
namespace MonoTests.System.Security.Cryptography {
[TestFixture]
- public class AsnEncodedDataTest : Assertion {
+ public class AsnEncodedDataTest {
static byte[] asnNullBytes = { 0x05, 0x00 };
static string asnNullString = "05 00";
static byte[] asnLongBytes = { 0x30,0x5C,0x02,0x55,0x2D,0x58,0xE9,0xBF,0xF0,0x31,0xCD,0x79,0x06,0x50,0x5A,0xD5,0x9E,0x0E,0x2C,0xE6,0xC2,0xF7,0xF9,0xD2,0xCE,0x55,0x64,0x85,0xB1,0x90,0x9A,0x92,0xB3,0x36,0xC1,0xBC,0xEA,0xC8,0x23,0xB7,0xAB,0x3A,0xA7,0x64,0x63,0x77,0x5F,0x84,0x22,0x8E,0xE5,0xB6,0x45,0xDD,0x46,0xAE,0x0A,0xDD,0x00,0xC2,0x1F,0xBA,0xD9,0xAD,0xC0,0x75,0x62,0xF8,0x95,0x82,0xA2,0x80,0xB1,0x82,0x69,0xFA,0xE1,0xAF,0x7F,0xBC,0x7D,0xE2,0x7C,0x76,0xD5,0xBC,0x2A,0x80,0xFB,0x02,0x03,0x01,0x00,0x01 };
static string asnLongString = "30 5c 02 55 2d 58 e9 bf f0 31 cd 79 06 50 5a d5 9e 0e 2c e6 c2 f7 f9 d2 ce 55 64 85 b1 90 9a 92 b3 36 c1 bc ea c8 23 b7 ab 3a a7 64 63 77 5f 84 22 8e e5 b6 45 dd 46 ae 0a dd 00 c2 1f ba d9 ad c0 75 62 f8 95 82 a2 80 b1 82 69 fa e1 af 7f bc 7d e2 7c 76 d5 bc 2a 80 fb 02 03 01 00 01";
- private void AssertEquals (string message, byte[] expected, byte[] actual)
- {
- AssertEquals (message, BitConverter.ToString (expected), BitConverter.ToString (actual));
- }
-
[Test]
- public void ConstructorStringData ()
+ public void Constructor_StringData ()
{
AsnEncodedData aed = new AsnEncodedData ("oid", asnNullBytes);
- AssertEquals ("Format", asnNullString, aed.Format (true));
+ Assert.AreEqual ("oid", aed.Oid.Value, "Oid.Value");
+ Assert.IsNull (aed.Oid.FriendlyName, "Oid.FriendlyName");
+ Assert.AreEqual (BitConverter.ToString (asnNullBytes), BitConverter.ToString (aed.RawData), "RawData");
+ Assert.AreEqual (asnNullString, aed.Format (true), "Format");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
- public void ConstructorStringNullData ()
+ public void Constructor_StringNullData ()
{
string oid = null; // do not confuse compiler
AsnEncodedData aed = new AsnEncodedData (oid, asnNullBytes);
- AssertEquals ("Format", asnNullString, aed.Format (true));
}
[Test]
- //BUG [ExpectedException (typeof (ArgumentNullException))]
- [ExpectedException (typeof (NullReferenceException))]
- public void ConstructorStringDataNull ()
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void Constructor_StringDataNull ()
{
AsnEncodedData aed = new AsnEncodedData ("oid", null);
- AssertEquals ("Format", asnNullString, aed.Format (true));
}
[Test]
- public void ConstructorOidData ()
+ public void Constructor_OidData ()
{
Oid o = new Oid ("1.0");
AsnEncodedData aed = new AsnEncodedData (o, asnNullBytes);
- AssertEquals ("Format", asnNullString, aed.Format (true));
+ Assert.AreEqual ("1.0", aed.Oid.Value, "Oid.Value");
+ Assert.IsNull (aed.Oid.FriendlyName, "Oid.FriendlyName");
+ Assert.AreEqual (BitConverter.ToString (asnNullBytes), BitConverter.ToString (aed.RawData), "RawData");
+ Assert.AreEqual (asnNullString, aed.Format (true), "Format");
}
[Test]
- //BUG [ExpectedException (typeof (ArgumentNullException))]
- [ExpectedException (typeof (NullReferenceException))]
- public void ConstructorOidNullData ()
+ // BUG [ExpectedException (typeof (ArgumentNullException))]
+ public void Constructor_OidNullData ()
{
Oid o = null;
AsnEncodedData aed = new AsnEncodedData (o, asnNullBytes);
+ Assert.IsNull (aed.Oid, "Oid");
+ Assert.AreEqual (BitConverter.ToString (asnNullBytes), BitConverter.ToString (aed.RawData), "RawData");
+ Assert.AreEqual (asnNullString, aed.Format (true), "Format");
}
[Test]
- //BUG [ExpectedException (typeof (ArgumentNullException))]
- [ExpectedException (typeof (NullReferenceException))]
- public void ConstructorOidDataNull ()
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void Constructor_OidDataNull ()
{
Oid o = new Oid ("1.0");
AsnEncodedData aed = new AsnEncodedData (o, null);
}
[Test]
- public void ConstructorAsn ()
+ public void Constructor_Asn ()
{
AsnEncodedData aed = new AsnEncodedData ("oid", asnNullBytes);
AsnEncodedData aed2 = new AsnEncodedData (aed);
- AssertEquals ("FriendlyName", aed.RawData, aed2.RawData);
+ Assert.AreEqual (aed.Oid.Value, aed2.Oid.Value, "Oid.Value");
+ Assert.AreEqual (aed.Oid.FriendlyName, aed2.Oid.FriendlyName, "Oid.FriendlyName");
+ Assert.AreEqual (BitConverter.ToString (aed.RawData), BitConverter.ToString (aed2.RawData), "RawData");
string s1 = aed.Format (false);
string s2 = aed.Format (true);
- AssertEquals ("Format", s1, s2);
+ Assert.AreEqual (s1, s2, "Format");
}
[Test]
- //BUG [ExpectedException (typeof (ArgumentNullException))]
- [ExpectedException (typeof (NullReferenceException))]
- public void ConstructorAsnNull ()
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void Constructor_ByteArrayNull ()
+ {
+ byte[] array = null;
+ AsnEncodedData aed = new AsnEncodedData (array);
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void Constructor_AsnNull ()
{
- AsnEncodedData aed = new AsnEncodedData (null);
+ AsnEncodedData asn = null;
+ AsnEncodedData aed = new AsnEncodedData (asn);
}
[Test]
public void Format ()
{
AsnEncodedData aed = new AsnEncodedData ("1.2.840.113549.1.1.1", asnLongBytes);
+ Assert.AreEqual ("1.2.840.113549.1.1.1", aed.Oid.Value, "Oid.Value");
+ Assert.AreEqual ("RSA", aed.Oid.FriendlyName, "Oid.FriendlyName");
+ Assert.AreEqual (BitConverter.ToString (asnLongBytes), BitConverter.ToString (aed.RawData), "RawData");
string result = aed.Format (false);
- AssertEquals ("Format(false)", asnLongString, result);
+ Assert.AreEqual (asnLongString, result, "Format(false)");
}
[Test]
public void FormatMultiline ()
{
AsnEncodedData aed = new AsnEncodedData ("1.2.840.113549.1.1.1", asnLongBytes);
+ Assert.AreEqual ("1.2.840.113549.1.1.1", aed.Oid.Value, "Oid.Value");
+ Assert.AreEqual ("RSA", aed.Oid.FriendlyName, "Oid.FriendlyName");
+ Assert.AreEqual (BitConverter.ToString (asnLongBytes), BitConverter.ToString (aed.RawData), "RawData");
string result = aed.Format (true);
- AssertEquals ("Format(true)", asnLongString, result);
+ Assert.AreEqual (asnLongString, result, "Format(true)");
}
}
}
+2004-07-09 Sebastien Pouliot <sebastien@ximian.com>
+
+ * AsnEncodedDataTest.cs: Fixed for Fx 2.0 beta1.
+ * CryptographicAttributeTest.cs: New. Moved from S.S.C.Pkcs.
+ * OidTest.cs: Fixed for Fx 2.0 beta1.
+
2003-11-06 Sebastien Pouliot <spouliot@videotron.ca>
* AsnEncodedDataTest.cs: New. Unit tests for AsnEncodedData (.NET 1.2).
--- /dev/null
+//
+// CryptographicAttributeTest.cs - NUnit tests for CryptographicAttribute
+//
+// Author:
+// Sebastien Pouliot <sebastien@ximian.com>
+//
+// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#if NET_2_0
+
+using NUnit.Framework;
+
+using System;
+using System.Collections;
+using System.Security.Cryptography;
+
+namespace MonoTests.System.Security.Cryptography {
+
+ [TestFixture]
+ public class CryptographicAttributeTest : Assertion {
+
+ static string defaultOid = "1.2.840.113549.1.7.1";
+ static string defaultName = "PKCS 7 Data";
+
+ [Test]
+ public void ConstructorOid ()
+ {
+ Oid o = new Oid (defaultOid);
+ CryptographicAttribute ca = new CryptographicAttribute (o);
+ AssertEquals ("Oid.FriendlyName", defaultName, ca.Oid.FriendlyName);
+ AssertEquals ("Oid.Value", defaultOid, ca.Oid.Value);
+ AssertEquals ("Values", 0, ca.Values.Count);
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void ConstructorOidNull ()
+ {
+ CryptographicAttribute ca = new CryptographicAttribute (null);
+ }
+
+ [Test]
+ public void ConstructorOidCollection ()
+ {
+ Oid o = new Oid (defaultOid);
+ AsnEncodedDataCollection coll = new AsnEncodedDataCollection ();
+ CryptographicAttribute ca = new CryptographicAttribute (o, coll);
+ AssertEquals ("Oid.FriendlyName", defaultName, ca.Oid.FriendlyName);
+ AssertEquals ("Oid.Value", defaultOid, ca.Oid.Value);
+ AssertEquals ("Values", 0, ca.Values.Count);
+ coll.Add (new AsnEncodedData (new byte [0]));
+ AssertEquals ("Values", 1, ca.Values.Count);
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void ConstructorOidNullCollection ()
+ {
+ AsnEncodedDataCollection coll = new AsnEncodedDataCollection ();
+ CryptographicAttribute ca = new CryptographicAttribute (null, coll);
+ }
+
+ [Test]
+ public void ConstructorOidAsnEncodedDataCollectionNull ()
+ {
+ Oid o = new Oid (defaultOid);
+ AsnEncodedDataCollection coll = null;
+ CryptographicAttribute ca = new CryptographicAttribute (o, coll);
+ AssertEquals ("Oid.FriendlyName", defaultName, ca.Oid.FriendlyName);
+ AssertEquals ("Oid.Value", defaultOid, ca.Oid.Value);
+ AssertEquals ("Values", 0, ca.Values.Count);
+ }
+ }
+}
+
+#endif
// OidTest.cs - NUnit tests for Oid
//
// Author:
-// Sebastien Pouliot (spouliot@motus.com)
+// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
namespace MonoTests.System.Security.Cryptography {
[TestFixture]
- public class OidTest : Assertion {
+ public class OidTest {
static string invalidOid = "1.0";
static string invalidName = "friendlyName";
public void ConstructorEmpty ()
{
Oid o = new Oid ();
- AssertNull ("FriendlyName", o.FriendlyName);
- AssertNull ("Value", o.Value);
+ Assert.IsNull (o.FriendlyName, "FriendlyName");
+ Assert.IsNull (o.Value, "Value");
}
[Test]
- public void ConstructorValidValue ()
+ public void ConstructorValidString ()
{
Oid o = new Oid (validOid);
- AssertEquals ("FriendlyName", validName, o.FriendlyName);
- AssertEquals ("Value", validOid, o.Value);
+ Assert.AreEqual (validName, o.FriendlyName, "FriendlyName");
+ Assert.AreEqual (validOid, o.Value, "Value");
}
[Test]
- public void ConstructorInvalidValue ()
+ public void ConstructorInvalidString ()
{
Oid o = new Oid (invalidOid);
- AssertNull ("FriendlyName", o.FriendlyName);
- AssertEquals ("Value", invalidOid, o.Value);
+ Assert.IsNull (o.FriendlyName, "FriendlyName");
+ Assert.AreEqual (invalidOid, o.Value, "Value");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
- public void ConstructorValueNull ()
+ public void ConstructorNullString ()
{
string oid = null; // do not confuse compiler
Oid o = new Oid (oid);
}
[Test]
- public void ConstructorValueName ()
+ public void ConstructorStringString ()
{
Oid o = new Oid (validOid, invalidName);
- AssertEquals ("FriendlyName", invalidName, o.FriendlyName);
- AssertEquals ("Value", validOid, o.Value);
+ Assert.AreEqual (invalidName, o.FriendlyName, "FriendlyName");
+ Assert.AreEqual (validOid, o.Value, "Value");
}
[Test]
//BUG [ExpectedException (typeof (ArgumentNullException))]
- public void ConstructorValueNullName ()
+ public void ConstructorStringNullString ()
{
Oid o = new Oid (null, validName);
- AssertEquals ("FriendlyName", validName, o.FriendlyName);
- AssertNull ("Value", o.Value);
+ Assert.AreEqual (validName, o.FriendlyName, "FriendlyName");
+ Assert.IsNull (o.Value, "Value");
}
[Test]
- //BUG [ExpectedException (typeof (ArgumentNullException))]
- public void ConstructorValueNameNull ()
+ public void ConstructorStringStringNull ()
{
Oid o = new Oid (validOid, null);
- AssertNull ("FriendlyName", o.FriendlyName);
- AssertEquals ("Value", validOid, o.Value);
+ Assert.IsNull (o.FriendlyName, "FriendlyName");
+ Assert.AreEqual (validOid, o.Value, "Value");
}
[Test]
{
Oid o = new Oid (validOid, invalidName);
Oid o2 = new Oid (o);
- AssertEquals ("FriendlyName==invalid", invalidName, o.FriendlyName);
- AssertEquals ("FriendlyName", o.FriendlyName, o2.FriendlyName);
- AssertEquals ("Value", o.Value, o2.Value);
+ Assert.AreEqual (invalidName, o.FriendlyName, "FriendlyName==invalid");
+ Assert.AreEqual (o.FriendlyName, o2.FriendlyName, "FriendlyName");
+ Assert.AreEqual (o.Value, o2.Value, "Value");
}
[Test]
- //BUG [ExpectedException (typeof (ArgumentNullException))]
- [ExpectedException (typeof (NullReferenceException))]
+ [ExpectedException (typeof (ArgumentNullException))]
public void ConstructorOidNull ()
{
Oid onull = null; // do not confuse compiler
public void FriendlyName ()
{
Oid o = new Oid (invalidOid, invalidName);
- AssertEquals ("FriendlyName", invalidName, o.FriendlyName);
- AssertEquals ("Value", invalidOid, o.Value);
+ Assert.AreEqual (invalidName, o.FriendlyName, "FriendlyName-1");
+ Assert.AreEqual (invalidOid, o.Value, "Value-1");
o.FriendlyName = validName;
- AssertEquals ("FriendlyName", validName, o.FriendlyName);
- AssertEquals ("Value", validOid, o.Value); // surprise!
+ Assert.AreEqual (validName, o.FriendlyName, "FriendlyName-2");
+ Assert.AreEqual (validOid, o.Value, "Value-2"); // surprise!
}
[Test]
- [ExpectedException (typeof (ArgumentNullException))]
public void FriendlyNameNull ()
{
Oid o = new Oid (validOid, invalidName);
- AssertEquals ("FriendlyName", invalidName, o.FriendlyName);
+ Assert.AreEqual (invalidName, o.FriendlyName, "FriendlyName");
o.FriendlyName = null;
+ Assert.IsNull (o.FriendlyName, "FriendlyName-Null");
}
[Test]
public void Value ()
{
Oid o = new Oid (validOid, invalidName);
- AssertEquals ("Value", validOid, o.Value);
+ Assert.AreEqual (validOid, o.Value, "Value-1");
o.Value = invalidName;
- AssertEquals ("Value", invalidName, o.Value);
+ Assert.AreEqual (invalidName, o.Value, "Value-2");
}
[Test]
- [ExpectedException (typeof (ArgumentNullException))]
public void ValueNull ()
{
Oid o = new Oid (validOid, invalidName);
- AssertEquals ("Value", validOid, o.Value);
+ Assert.AreEqual (validOid, o.Value, "Value");
o.Value = null;
- AssertNull ("Value==null", o.Value);
+ Assert.IsNull (o.Value, "Value-Null");
+ }
+
+ [Test]
+ public void WellKnownOid ()
+ {
+ Oid o = new Oid ("1.2.840.113549.1.1.1");
+ Assert.AreEqual ("1.2.840.113549.1.1.1", o.Value, "RSA Value");
+ Assert.AreEqual ("RSA", o.FriendlyName, "RSA FriendlyName");
+
+ o = new Oid ("1.2.840.113549.1.7.1");
+ Assert.AreEqual ("1.2.840.113549.1.7.1", o.Value, "PKCS 7 Data Value");
+ Assert.AreEqual ("PKCS 7 Data", o.FriendlyName, "PKCS 7 Data FriendlyName");
+
+ o = new Oid ("1.2.840.113549.1.9.5");
+ Assert.AreEqual ("1.2.840.113549.1.9.5", o.Value, "Signing Time Value");
+ Assert.AreEqual ("Signing Time", o.FriendlyName, "Signing Time FriendlyName");
+
+ o = new Oid ("1.2.840.113549.3.7");
+ Assert.AreEqual ("1.2.840.113549.3.7", o.Value, "3des Value");
+ Assert.AreEqual ("3des", o.FriendlyName, "3des FriendlyName");
+
+ // TODO: add other well known oid as we find them
}
}
}