2 // Pkcs9AttributeTest.cs - NUnit tests for Pkcs9Attribute
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
8 // Copyright (C) 2004-2005 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.Collections;
35 using System.Security.Cryptography;
36 using System.Security.Cryptography.Pkcs;
38 namespace MonoTests.System.Security.Cryptography.Pkcs {
41 public class Pkcs9AttributeObjectTest {
43 static string defaultOid = "1.2.840.113549.1.7.1";
44 static string defaultName = "PKCS 7 Data";
47 public void ConstructorEmpty ()
49 Pkcs9AttributeObject a = new Pkcs9AttributeObject ();
50 Assert.IsNull (a.Oid, "Oid");
51 Assert.IsNull (a.RawData, "RawData");
55 [ExpectedException (typeof (ArgumentNullException))]
56 public void ConstructorAsnEncodedDataNull ()
58 Pkcs9AttributeObject a = new Pkcs9AttributeObject (null);
62 public void ConstructorOidArray ()
64 Oid o = new Oid (defaultOid);
65 Pkcs9AttributeObject a = new Pkcs9AttributeObject (o, new byte[0]);
66 Assert.AreEqual (defaultName, a.Oid.FriendlyName, "Oid.FriendlyName");
67 Assert.AreEqual (defaultOid, a.Oid.Value, "Oid.Value");
68 Assert.AreEqual (0, a.RawData.Length, "RawData");
72 [ExpectedException (typeof (ArgumentNullException))]
73 public void ConstructorOidNullArray ()
76 Pkcs9AttributeObject a = new Pkcs9AttributeObject (o, new byte[0]);
80 [ExpectedException (typeof (ArgumentNullException))]
81 public void ConstructorOidArrayNull ()
83 Oid o = new Oid (defaultOid);
84 Pkcs9AttributeObject a = new Pkcs9AttributeObject (o, null);
88 public void ConstructorStringArray ()
90 Pkcs9AttributeObject a = new Pkcs9AttributeObject (defaultOid, new byte[0]);
91 Assert.AreEqual (defaultName, a.Oid.FriendlyName, "Oid.FriendlyName");
92 Assert.AreEqual (defaultOid, a.Oid.Value, "Oid.Value");
93 Assert.AreEqual (0, a.RawData.Length, "RawData");
97 [ExpectedException (typeof (ArgumentNullException))]
98 public void ConstructorStringNullArray ()
101 Pkcs9AttributeObject a = new Pkcs9AttributeObject (s, new byte[0]);
105 [ExpectedException (typeof (ArgumentNullException))]
106 public void ConstructorStringArrayNull ()
108 Pkcs9AttributeObject a = new Pkcs9AttributeObject (defaultOid, null);
112 [ExpectedException (typeof (ArgumentNullException))]
113 public void CopyFrom_Null ()
115 new Pkcs9AttributeObject ().CopyFrom (null);
119 [ExpectedException (typeof (ArgumentException))]
120 public void CopyFrom_SigningTime_Raw ()
122 Pkcs9SigningTime st = new Pkcs9SigningTime (DateTime.UtcNow);
123 Pkcs9AttributeObject a = new Pkcs9AttributeObject ();
124 a.CopyFrom (new AsnEncodedData (st.RawData));
128 [ExpectedException (typeof (ArgumentException))]
129 public void CopyFrom_SigningTime_OidRaw ()
131 Pkcs9SigningTime st = new Pkcs9SigningTime (DateTime.UtcNow);
132 Pkcs9AttributeObject a = new Pkcs9AttributeObject ();
133 a.CopyFrom (new AsnEncodedData (st.Oid, st.RawData));
137 [ExpectedException (typeof (ArgumentException))]
138 public void CopyFrom_Self ()
140 Pkcs9AttributeObject a = new Pkcs9AttributeObject ("1.2.3.4", new byte[2] { 0x05, 0x00 } );
141 a.CopyFrom (new AsnEncodedData (a.Oid, a.RawData));