Merge pull request #1542 from ninjarobot/UriTemplateMatchException
[mono.git] / mcs / class / System.Security / Test / System.Security.Cryptography.Pkcs / ContentInfoTest.cs
1 //
2 // ContentInfoTest.cs - NUnit tests for ContentInfo
3 //
4 // Author:
5 //      Sebastien Pouliot  <sebastien@ximian.com>
6 //
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
8 // Copyright (C) 2004-2005 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.
28 //
29
30
31 using NUnit.Framework;
32
33 using System;
34 using System.Security.Cryptography;
35 using System.Security.Cryptography.Pkcs;
36
37 namespace MonoTests.System.Security.Cryptography.Pkcs {
38
39         [TestFixture]
40         public class ContentInfoTest {
41
42                 static string defaultOid = "1.2.840.113549.1.7.1";
43                 static string defaultName = "PKCS 7 Data";
44                 static byte[] asnNull = { 0x05, 0x00 };
45
46                 [Test]
47                 public void ConstructorContent () 
48                 {
49                         ContentInfo ci = new ContentInfo (asnNull);
50                         Assert.AreEqual (asnNull, ci.Content, "Content");
51                         Assert.AreEqual (defaultName, ci.ContentType.FriendlyName, "ContentType.FriendlyName");
52                         Assert.AreEqual (defaultOid, ci.ContentType.Value, "ContentType.Value");
53                 }
54
55                 [Test]
56                 [ExpectedException (typeof (ArgumentNullException))]
57                 public void ConstructorOidNull () 
58                 {
59                         ContentInfo ci = new ContentInfo (null);
60                 }
61
62                 [Test]
63                 public void ConstructorOidContent () 
64                 {
65                         Oid o = new Oid (defaultOid);
66                         ContentInfo ci = new ContentInfo (o, asnNull);
67                         Assert.AreEqual (asnNull, ci.Content, "Content");
68                         Assert.AreEqual (defaultName, ci.ContentType.FriendlyName, "ContentType.FriendlyName");
69                         Assert.AreEqual (defaultOid, ci.ContentType.Value, "ContentType.Value");
70                 }
71
72                 [Test]
73                 public void ConstructorNonPkcs7Oid ()
74                 {
75                         Oid o = new Oid ("1.2.3.4");
76                         ContentInfo ci = new ContentInfo (o, asnNull);
77                         Assert.AreEqual (asnNull, ci.Content, "Content");
78                         Assert.AreEqual ("1.2.3.4", ci.ContentType.Value, "ContentType.Value");
79                 }
80
81                 [Test]
82                 [ExpectedException (typeof (ArgumentNullException))]
83                 public void ConstructorOidNullContent () 
84                 {
85                         ContentInfo ci = new ContentInfo (null, asnNull);
86                 }
87
88                 [Test]
89                 [ExpectedException (typeof (ArgumentNullException))]
90                 public void ConstructorOidContentNull ()
91                 {
92                         Oid o = new Oid (defaultOid);
93                         ContentInfo ci = new ContentInfo (o, null);
94                 }
95
96                 [Test]
97                 public void Oid_ModifyContent ()
98                 {
99                         ContentInfo ci = new ContentInfo (asnNull);
100                         Assert.AreEqual (asnNull, ci.Content, "Content-Before");
101                         ci.Content[0] = 0x04;
102                         Assert.AreEqual (asnNull, ci.Content, "Content-After");
103                         // this means we get a copy (not a reference)
104                 }
105
106                 [Test]
107                 [ExpectedException (typeof (CryptographicException))]
108                 public void GetContentType_invalid ()
109                 {
110                         byte[] invalid = { 0x30, 0x1A, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x00, 0xA0, 0x0D, 0x04, 0x0B, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x4D, 0x6F, 0x6E, 0x6F, 0x21 };
111                         Oid o = ContentInfo.GetContentType (invalid);
112                         Assert.AreEqual ("1.2.840.113549.1.7.0", o.Value, "GetContentType");
113                 }
114
115                 [Test]
116                 public void GetContentType_data ()
117                 {
118                         // ASN1 a0 = new ASN1 (0xA0);
119                         // a0.Add (new ASN1 (0x04, Encoding.ASCII.GetBytes ("Hello Mono!")));
120                         // ASN1 contentInfo = new ASN1 (0x30);
121                         // contentInfo.Add (ASN1Convert.FromOid ("1.2.840.113549.1.7.1"));
122                         // contentInfo.Add (a0);
123                         // byte[] data = contentInfo.GetBytes ();
124                         byte[] data = { 0x30, 0x1A, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01, 0xA0, 0x0D, 0x04, 0x0B, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x4D, 0x6F, 0x6E, 0x6F, 0x21 };
125                         Oid o = ContentInfo.GetContentType (data);
126                         Assert.AreEqual ("1.2.840.113549.1.7.1", o.Value, "GetContentType");
127                 }
128
129                 [Test]
130                 public void GetContentType_signedData () 
131                 {
132                         byte[] signedData = { 0x30, 0x82, 0x03, 0x4C, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x02, 0xA0, 0x82, 0x03, 0x3D, 0x30, 0x82, 0x03, 0x39, 0x02, 0x01, 0x01, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x0E, 0x03, 0x02, 0x1A, 0x05, 0x00, 0x30, 0x11, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01, 0xA0, 0x04, 0x04, 0x02, 0x05, 0x00, 0xA0, 0x82, 0x02, 0x2E, 0x30, 0x82, 0x02, 0x2A, 0x30, 0x82, 0x01, 0x97, 0xA0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x10, 0x91, 0xC4, 0x4B, 0x0D, 0xB7, 0xD8, 0x10, 0x84, 0x42, 0x26, 0x71, 0xB3, 0x97, 0xB5, 0x00, 0x97, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x0E, 0x03, 0x02, 0x1D, 0x05, 0x00, 0x30, 0x28, 0x31, 0x26, 0x30, 0x24, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x1D, 0x4D, 0x6F, 0x74, 0x75, 0x73, 0x20, 0x54, 0x65, 
133                                 0x63, 0x68, 0x6E, 0x6F, 0x6C, 0x6F, 0x67, 0x69, 0x65, 0x73, 0x20, 0x69, 0x6E, 0x63, 0x2E, 0x28, 0x74, 0x65, 0x73, 0x74, 0x29, 0x30, 0x1E, 0x17, 0x0D, 0x30, 0x33, 0x30, 0x38, 0x31, 0x33, 0x30, 0x30, 0x34, 0x33, 0x34, 0x37, 0x5A, 0x17, 0x0D, 0x33, 0x39, 0x31, 0x32, 0x33, 0x31, 0x32, 0x33, 0x35, 0x39, 0x35, 0x39, 0x5A, 0x30, 0x13, 0x31, 0x11, 0x30, 0x0F, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x08, 0x46, 0x41, 0x52, 0x53, 0x43, 0x41, 0x50, 0x45, 0x30, 0x81, 0x9F, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x81, 0x8D, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xD2, 0xCB, 0x47, 0x21, 0xF5, 0x62, 0xDD, 0x35, 0xBF, 0x1D, 0xEC, 0x9A, 0x4C, 0x07, 0x2C, 0x01, 0xF0, 0x28, 0xC2, 0x82, 0x17, 0x8E, 0x58, 0x32, 
134                                 0xD5, 0x4C, 0xAC, 0x86, 0xB4, 0xC9, 0xEB, 0x21, 0x26, 0xF3, 0x22, 0x30, 0xC5, 0x7A, 0xA3, 0x5A, 0xDD, 0x53, 0xAB, 0x1C, 0x06, 0x3E, 0xB2, 0x13, 0xC4, 0x05, 0x1D, 0x95, 0x8B, 0x0A, 0x71, 0x71, 0x11, 0xA7, 0x47, 0x26, 0x61, 0xF1, 0x76, 0xBE, 0x35, 0x72, 0x32, 0xC5, 0xCB, 0x47, 0xA4, 0x22, 0x41, 0x1E, 0xAD, 0x29, 0x11, 0x0D, 0x39, 0x22, 0x0C, 0x79, 0x90, 0xC6, 0x52, 0xA1, 0x10, 0xF6, 0x55, 0x09, 0x4E, 0x51, 0x26, 0x47, 0x0E, 0x94, 0xE6, 0x81, 0xF5, 0x18, 0x6B, 0x99, 0xF0, 0x76, 0xF3, 0xB2, 0x4C, 0x91, 0xE9, 0xBA, 0x3B, 0x3F, 0x6E, 0x63, 0xDA, 0x12, 0xD1, 0x0B, 0x73, 0x0E, 0x12, 0xC7, 0x70, 0x77, 0x22, 0x03, 0x9D, 0x5D, 0x02, 0x03, 0x01, 0x00, 0x01, 0xA3, 0x72, 0x30, 0x70, 0x30, 0x13, 0x06, 0x03, 0x55, 0x1D, 0x25, 0x04, 0x0C, 0x30, 0x0A, 0x06, 0x08, 0x2B, 
135                                 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x01, 0x30, 0x59, 0x06, 0x03, 0x55, 0x1D, 0x01, 0x04, 0x52, 0x30, 0x50, 0x80, 0x10, 0xAE, 0xD7, 0x80, 0x88, 0xA6, 0x3D, 0xBA, 0x50, 0xA1, 0x7E, 0x57, 0xE5, 0x40, 0xC9, 0x6F, 0xC5, 0xA1, 0x2A, 0x30, 0x28, 0x31, 0x26, 0x30, 0x24, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x1D, 0x4D, 0x6F, 0x74, 0x75, 0x73, 0x20, 0x54, 0x65, 0x63, 0x68, 0x6E, 0x6F, 0x6C, 0x6F, 0x67, 0x69, 0x65, 0x73, 0x20, 0x69, 0x6E, 0x63, 0x2E, 0x28, 0x74, 0x65, 0x73, 0x74, 0x29, 0x82, 0x10, 0x9D, 0xAE, 0xA3, 0x39, 0x47, 0x0E, 0xD4, 0xA2, 0x49, 0x78, 0xEA, 0x6C, 0xBA, 0x0D, 0xDE, 0x9C, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x0E, 0x03, 0x02, 0x1D, 0x05, 0x00, 0x03, 0x81, 0x81, 0x00, 0x32, 0x8A, 0x7E, 0xAD, 0xE7, 0x67, 0x9E, 0x5C, 0x4C, 0xD8, 0x33, 0x59, 0x68, 0xCF, 
136                                 0x94, 0xC0, 0x36, 0x47, 0x7A, 0xA7, 0x85, 0xC2, 0xDD, 0xD8, 0xDA, 0x11, 0x3C, 0x66, 0xC1, 0x83, 0xE3, 0xAB, 0x33, 0x06, 0x7C, 0xE3, 0x6A, 0x15, 0x72, 0xB8, 0x83, 0x3D, 0x0B, 0xAB, 0x3C, 0xEE, 0x75, 0x13, 0xBD, 0x5C, 0x96, 0x25, 0x56, 0x36, 0x05, 0xFA, 0xAE, 0xD4, 0xF4, 0xCF, 0x52, 0xEC, 0x11, 0xB5, 0xEA, 0x9F, 0x20, 0xA3, 0xC8, 0x34, 0x72, 0x59, 0x09, 0x51, 0xE7, 0x36, 0x87, 0x86, 0x86, 0x98, 0xB5, 0x30, 0x7B, 0xFB, 0x3D, 0xCC, 0x5E, 0xE8, 0xC9, 0x49, 0xE0, 0xC6, 0xEA, 0x02, 0x76, 0x01, 0xE0, 0xBB, 0x8A, 0x70, 0xEB, 0x07, 0x86, 0xE8, 0x04, 0xE7, 0x48, 0xE4, 0x6C, 0x90, 0xE6, 0x16, 0x42, 0xB4, 0xBB, 0xC0, 0xC4, 0x82, 0x5F, 0xF8, 0xFB, 0x7E, 0xB2, 0x9E, 0xC2, 0x78, 0x26, 0x86, 0x31, 0x81, 0xE1, 0x30, 0x81, 0xDE, 0x02, 0x01, 0x01, 0x30, 0x3C, 0x30, 0x28, 
137                                 0x31, 0x26, 0x30, 0x24, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x1D, 0x4D, 0x6F, 0x74, 0x75, 0x73, 0x20, 0x54, 0x65, 0x63, 0x68, 0x6E, 0x6F, 0x6C, 0x6F, 0x67, 0x69, 0x65, 0x73, 0x20, 0x69, 0x6E, 0x63, 0x2E, 0x28, 0x74, 0x65, 0x73, 0x74, 0x29, 0x02, 0x10, 0x91, 0xC4, 0x4B, 0x0D, 0xB7, 0xD8, 0x10, 0x84, 0x42, 0x26, 0x71, 0xB3, 0x97, 0xB5, 0x00, 0x97, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x0E, 0x03, 0x02, 0x1A, 0x05, 0x00, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x81, 0x80, 0x45, 0x88, 0x80, 0x58, 0xC7, 0x4F, 0xE4, 0xD8, 0x88, 0xB0, 0xC0, 0x08, 0x70, 0x84, 0xCC, 0x8E, 0xA7, 0xF1, 0xA4, 0x07, 0x41, 0x14, 0x3E, 0xF5, 0xEA, 0x6E, 0x05, 0x75, 0xB8, 0x58, 0xAA, 0x5C, 0x0E, 0xFD, 0x7A, 0x07, 0x09, 0xE1, 0x80, 0x94, 
138                                 0xBD, 0xAA, 0x45, 0xBB, 0x55, 0x9C, 0xC2, 0xD9, 0x72, 0x14, 0x4B, 0xA4, 0x64, 0xFB, 0x38, 0x9F, 0xD3, 0x22, 0xED, 0xB3, 0x0B, 0xF7, 0xAE, 0x4D, 0xE6, 0x65, 0x4D, 0x2A, 0x31, 0x18, 0xB5, 0xB4, 0x2D, 0x9E, 0x4E, 0xD7, 0xC0, 0x44, 0x5F, 0xAC, 0x43, 0xDC, 0x4F, 0x3D, 0x6D, 0x2C, 0x8C, 0xA1, 0xFE, 0x08, 0x38, 0xB7, 0xC4, 0xC4, 0x08, 0xDB, 0xF8, 0xF0, 0xC1, 0x55, 0x54, 0x49, 0x9D, 0xA4, 0x7F, 0x76, 0xDE, 0xF4, 0x29, 0x1C, 0x0B, 0x95, 0x10, 0x90, 0xB5, 0x0A, 0x9A, 0xEC, 0xCA, 0x89, 0x9A, 0x85, 0x92, 0x76, 0x78, 0x6F, 0x97, 0x67 };
139                         Oid o = ContentInfo.GetContentType (signedData);
140                         Assert.AreEqual ("1.2.840.113549.1.7.2", o.Value, "GetContentType");
141                 }
142
143                 [Test]
144                 public void GetContentType_envelopedData ()
145                 {
146                         byte[] envelopedData = { 0x30, 0x82, 0x01, 0x1C, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x03, 0xA0, 0x82, 0x01, 0x0D, 0x30, 0x82, 0x01, 0x09, 0x02, 0x01, 0x00, 0x31, 0x81, 0xD6, 0x30, 0x81, 0xD3, 0x02, 0x01, 0x00, 0x30, 0x3C, 0x30, 0x28, 0x31, 0x26, 0x30, 0x24, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x1D, 0x4D, 0x6F, 0x74, 0x75, 0x73, 0x20, 0x54, 0x65, 0x63, 0x68, 0x6E, 0x6F, 0x6C, 0x6F, 0x67, 0x69, 0x65, 0x73, 0x20, 0x69, 0x6E, 0x63, 0x2E, 0x28, 0x74, 0x65, 0x73, 0x74, 0x29, 0x02, 0x10, 0x91, 0xC4, 0x4B, 0x0D, 0xB7, 0xD8, 0x10, 0x84, 0x42, 0x26, 0x71, 0xB3, 0x97, 0xB5, 0x00, 0x97, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x81, 0x80, 0xCA, 0x4B, 0x97, 0x9C, 0xAB, 0x79, 0xC6, 0xDF, 0x6A, 0x27, 0xC7, 0x24, 0xC4, 0x5E, 0x3B, 0x31, 0xAD, 0xBC, 0x25, 0xE6, 0x38, 0x5E, 0x79, 0x26, 0x0E, 0x68, 0x46, 0x1D, 0x21, 0x81, 0x38, 0x92, 0xEC, 0xCB, 0x7C, 0x91, 0xD6, 0x09, 0x38, 0x91, 0xCE, 0x50, 0x5B, 0x70, 0x31, 0xB0, 0x9F, 0xFC, 0xE2, 0xEE, 0x45, 0xBC, 0x4B, 0xF8, 0x9A, 0xD9, 0xEE, 0xE7, 0x4A, 0x3D, 0xCD, 0x8D, 0xFF, 0x10, 0xAB, 0xC8, 0x19, 0x05, 0x54, 0x5E, 0x40, 0x7A, 0xBE, 0x2B, 0xD7, 0x22, 0x97, 0xF3, 0x23, 0xAF, 0x50, 0xF5, 0xEB, 0x43, 0x06, 0xC3, 0xFB, 0x17, 0xCA, 0xBD, 0xAD, 0x28, 0xD8, 0x10, 0x0F, 0x61, 0xCE, 0xF8, 0x25, 0x70, 0xF6, 0xC8, 0x1E, 0x7F, 0x82, 0xE5, 0x94, 0xEB, 0x11, 0xBF, 0xB8, 0x6F, 0xEE, 0x79, 0xCD, 0x63, 0xDD, 0x59, 0x8D, 0x25, 0x0E, 0x78, 0x55, 0xCE, 0x21, 0xBA, 0x13, 0x6B, 0x30, 0x2B, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01, 0x30, 0x14, 0x06, 0x08, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x03, 0x07, 0x04, 0x08, 0x8C, 0x5D, 0xC9, 0x87, 0x88, 0x9C, 0x05, 0x72, 0x80, 0x08, 0x2C, 0xAF, 0x82, 0x91, 0xEC, 0xAD, 0xC5, 0xB5 };
147                         Oid o = ContentInfo.GetContentType (envelopedData);
148                         Assert.AreEqual ("1.2.840.113549.1.7.3", o.Value, "GetContentType");
149                 }
150
151                 [Test]
152                 [ExpectedException (typeof (CryptographicException))]
153                 public void GetContentType_signedAndEnvelopedData ()
154                 {
155                         // Note: signedAndEnvelopedData isn't defined in RFC2630
156                         byte[] signedAndEnvelopedData = { 0x30, 0x82, 0x01, 0x1C, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x04, 0xA0, 0x82, 0x01, 0x0D, 0x30, 0x82, 0x01, 0x09, 0x02, 0x01, 0x00, 0x31, 0x81, 0xD6, 0x30, 0x81, 0xD3, 0x02, 0x01, 0x00, 0x30, 0x3C, 0x30, 0x28, 0x31, 0x26, 0x30, 0x24, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x1D, 0x4D, 0x6F, 0x74, 0x75, 0x73, 0x20, 0x54, 0x65, 0x63, 0x68, 0x6E, 0x6F, 0x6C, 0x6F, 0x67, 0x69, 0x65, 0x73, 0x20, 0x69, 0x6E, 0x63, 0x2E, 0x28, 0x74, 0x65, 0x73, 0x74, 0x29, 0x02, 0x10, 0x91, 0xC4, 0x4B, 0x0D, 0xB7, 0xD8, 0x10, 0x84, 0x42, 0x26, 0x71, 0xB3, 0x97, 0xB5, 0x00, 0x97, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x81, 0x80, 0xCA, 0x4B, 0x97, 0x9C, 0xAB, 0x79, 0xC6, 0xDF, 0x6A, 0x27, 0xC7, 0x24, 0xC4, 0x5E, 0x3B, 0x31, 0xAD, 0xBC, 0x25, 0xE6, 0x38, 0x5E, 0x79, 0x26, 0x0E, 0x68, 0x46, 0x1D, 0x21, 0x81, 0x38, 0x92, 0xEC, 0xCB, 0x7C, 0x91, 0xD6, 0x09, 0x38, 0x91, 0xCE, 0x50, 0x5B, 0x70, 0x31, 0xB0, 0x9F, 0xFC, 0xE2, 0xEE, 0x45, 0xBC, 0x4B, 0xF8, 0x9A, 0xD9, 0xEE, 0xE7, 0x4A, 0x3D, 0xCD, 0x8D, 0xFF, 0x10, 0xAB, 0xC8, 0x19, 0x05, 0x54, 0x5E, 0x40, 0x7A, 0xBE, 0x2B, 0xD7, 0x22, 0x97, 0xF3, 0x23, 0xAF, 0x50, 0xF5, 0xEB, 0x43, 0x06, 0xC3, 0xFB, 0x17, 0xCA, 0xBD, 0xAD, 0x28, 0xD8, 0x10, 0x0F, 0x61, 0xCE, 0xF8, 0x25, 0x70, 0xF6, 0xC8, 0x1E, 0x7F, 0x82, 0xE5, 0x94, 0xEB, 0x11, 0xBF, 0xB8, 0x6F, 0xEE, 0x79, 0xCD, 0x63, 0xDD, 0x59, 0x8D, 0x25, 0x0E, 0x78, 0x55, 0xCE, 0x21, 0xBA, 0x13, 0x6B, 0x30, 0x2B, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01, 0x30, 0x14, 0x06, 0x08, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x03, 0x07, 0x04, 0x08, 0x8C, 0x5D, 0xC9, 0x87, 0x88, 0x9C, 0x05, 0x72, 0x80, 0x08, 0x2C, 0xAF, 0x82, 0x91, 0xEC, 0xAD, 0xC5, 0xB5 };
157                         Oid o = ContentInfo.GetContentType (signedAndEnvelopedData);
158                         Assert.AreEqual ("1.2.840.113549.1.7.4", o.Value, "GetContentType");
159                 }
160
161                 [Test]
162                 [Ignore ("need a working sample")]
163                 public void GetContentType_digestedData ()
164                 {
165                         /*ASN1 eci = new ASN1 (0x30);
166                         eci.Add (ASN1Convert.FromOid ("1.2.840.113549.1.7.1"));
167                         eci.Add (new ASN1 (0x05));
168                         ASN1 dData = new ASN1 (0x30);
169                         dData.Add (new ASN1 (0x02, new byte[1] { 2 }));
170                         dData.Add (PKCS7.AlgorithmIdentifier (CryptoConfig.MapNameToOID ("SHA1")));
171                         ASN1 a0 = new ASN1 (0xA0);
172                         a0.Add (dData);
173                         ASN1 contentInfo = new ASN1 (0x30);
174                         contentInfo.Add (ASN1Convert.FromOid ("1.2.840.113549.1.7.5"));
175                         contentInfo.Add (a0);
176                         byte[] digestedData = contentInfo.GetBytes ();*/
177
178                         byte[] digestedData = null;
179                         Oid o = ContentInfo.GetContentType (digestedData);
180                         Assert.AreEqual ("1.2.840.113549.1.7.5", o.Value, "GetContentType");
181                 }
182
183                 [Test]
184                 [Ignore ("need a working sample")]
185                 public void GetContentType_encryptedData ()
186                 {
187                         /* ASN1 eci = new ASN1 (0x30);
188                         eci.Add (ASN1Convert.FromOid ("1.2.840.113549.1.7.1"));
189                         eci.Add (PKCS7.AlgorithmIdentifier ("1.2.840.113549.1.1.1"));
190                         ASN1 eData = new ASN1 (0x30);
191                         eData.Add (new ASN1 (0x02, new byte[1] { 2 }));
192                         eData.Add (eci);
193                         ASN1 a0 = new ASN1 (0xA0);
194                         a0.Add (eci);
195                         ASN1 contentInfo = new ASN1 (0x30);
196                         contentInfo.Add (ASN1Convert.FromOid ("1.2.840.113549.1.7.6"));
197                         contentInfo.Add (a0);
198                         byte[] encryptedData = contentInfo.GetBytes (); */
199
200                         byte[] encryptedData = null;
201                         Oid o = ContentInfo.GetContentType (encryptedData);
202                         Assert.AreEqual ("1.2.840.113549.1.7.6", o.Value, "GetContentType");
203                 }
204
205                 [Test]
206                 [ExpectedException (typeof (CryptographicException))]
207                 public void GetContentType_unknown ()
208                 {
209                         byte[] unknown = { 0x30, 0x1A, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x07, 0xA0, 0x0D, 0x04, 0x0B, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x4D, 0x6F, 0x6E, 0x6F, 0x21 };
210                         Oid o = ContentInfo.GetContentType (unknown);
211                         Assert.AreEqual ("1.2.840.113549.1.7.7", o.Value, "GetContentType");
212                 }
213
214                 [Test]
215                 [ExpectedException (typeof (CryptographicException))]
216                 public void GetContentTypeBadASN1 () 
217                 {
218                         // ContentInfo ::= SEQUENCE {
219                         // contentType ContentType, -> ContentType ::= OBJECT IDENTIFIER
220                         // content [0] EXPLICIT ANY DEFINED BY contentType OPTIONAL 
221
222                         // Generated using Mono.Security.dll and the following code
223                         byte [] badasn = new byte [] { 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01, 0x05, 0x00 };
224                         // ASN1 contentInfo = new ASN1 (0x30);
225                         // contentInfo.Add (ASN1Convert.FromOid (defaultOid));
226                         // contentInfo.Add (new ASN1 (asnNull));
227                         
228                         Oid o = ContentInfo.GetContentType (badasn);
229                 }
230
231                 [Test]
232                 [ExpectedException (typeof (ArgumentNullException))]
233                 public void GetContentTypeNull () 
234                 {
235                         Oid o = ContentInfo.GetContentType (null);
236                 }
237         }
238 }
239