2 // SubjectKeyIdentifierExtensionTest.cs - NUnit Test Cases for
3 // Mono.Security.X509.Extensions.SubjectKeyIdentifierExtension
6 // Lex Li <support@lextm.com>
8 // Copyright (C) 2014 Lex Li
10 // Permission is hereby granted, free of charge, to any person obtaining a copy of this
11 // software and associated documentation files (the "Software"), to deal in the Software
12 // without restriction, including without limitation the rights to use, copy, modify, merge,
13 // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
14 // to whom the Software is furnished to do so, subject to the following conditions:
16 // The above copyright notice and this permission notice shall be included in all copies or
17 // substantial portions of the Software.
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
20 // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
21 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
22 // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 // DEALINGS IN THE SOFTWARE.
27 using Mono.Security.X509.Extensions;
28 using NUnit.Framework;
30 namespace MonoTests.Mono.Security.X509.Extensions
33 public class SubjectKeyIdentifierExtensionTest
35 private void Empty (SubjectKeyIdentifierExtension ski)
37 Assert.IsFalse (ski.Critical, "Critical");
38 Assert.AreEqual ("2.5.29.14", ski.Oid, "Oid");
39 Assert.IsNotNull (ski.Name, "Name");
40 Assert.IsFalse (ski.Name == ski.Oid, "Name!=Oid");
41 Assert.AreEqual (new byte[] {
42 0x00, 0x00, 0x00, 0x00, 0x00,
43 0x00, 0x00, 0x00, 0x00, 0x00,
44 0x00, 0x00, 0x00, 0x00, 0x00,
45 0x00, 0x00, 0x00, 0x00, 0x00
46 }, ski.Identifier, "Identifier");
50 public void Constructor_Empty ()
52 SubjectKeyIdentifierExtension ski = new SubjectKeyIdentifierExtension ();
53 ski.Identifier = new byte[] {
54 0x00, 0x00, 0x00, 0x00, 0x00,
55 0x00, 0x00, 0x00, 0x00, 0x00,
56 0x00, 0x00, 0x00, 0x00, 0x00,
57 0x00, 0x00, 0x00, 0x00, 0x00
63 public void Constructor_Extension ()
65 SubjectKeyIdentifierExtension ext = new SubjectKeyIdentifierExtension ();
66 ext.Identifier = new byte[] {
67 0x00, 0x00, 0x00, 0x00, 0x00,
68 0x00, 0x00, 0x00, 0x00, 0x00,
69 0x00, 0x00, 0x00, 0x00, 0x00,
70 0x00, 0x00, 0x00, 0x00, 0x00
72 SubjectKeyIdentifierExtension ski = new SubjectKeyIdentifierExtension (ext);
77 public void Constructor_ASN1 ()
79 SubjectKeyIdentifierExtension ext = new SubjectKeyIdentifierExtension ();
80 ext.Identifier = new byte[] {
81 0x00, 0x00, 0x00, 0x00, 0x00,
82 0x00, 0x00, 0x00, 0x00, 0x00,
83 0x00, 0x00, 0x00, 0x00, 0x00,
84 0x00, 0x00, 0x00, 0x00, 0x00
86 SubjectKeyIdentifierExtension ski = new SubjectKeyIdentifierExtension (ext.ASN1);
91 public void AuthorityKeyIdentifier_Critical ()
93 SubjectKeyIdentifierExtension ski = new SubjectKeyIdentifierExtension ();
95 ski.Identifier = new byte[] {
96 0x00, 0x00, 0x00, 0x00, 0x00,
97 0x00, 0x00, 0x00, 0x00, 0x00,
98 0x00, 0x00, 0x00, 0x00, 0x00,
99 0x00, 0x00, 0x00, 0x00, 0x00
101 Assert.AreEqual ("30-20-06-03-55-1D-0E-01-01-FF-04-16-04-14-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00", BitConverter.ToString (ski.GetBytes ()), "GetBytes");
103 SubjectKeyIdentifierExtension ski2 = new SubjectKeyIdentifierExtension (ski.ASN1);
104 Assert.IsTrue (ski2.Critical, "Critical");
105 Assert.AreEqual (new byte[] {
106 0x00, 0x00, 0x00, 0x00, 0x00,
107 0x00, 0x00, 0x00, 0x00, 0x00,
108 0x00, 0x00, 0x00, 0x00, 0x00,
109 0x00, 0x00, 0x00, 0x00, 0x00
110 }, ski2.Identifier, "Identifier");
114 [ExpectedException (typeof(InvalidOperationException))]
115 public void EmptyIdentifier ()
117 SubjectKeyIdentifierExtension ext = new SubjectKeyIdentifierExtension ();
118 SubjectKeyIdentifierExtension ski = new SubjectKeyIdentifierExtension (ext);