2 // KeyUsageExtensionTest.cs - NUnit Test Cases for
3 // Mono.Security.X509.Extensions.KeyUsageExtension
6 // Sebastien Pouliot <sebastien@ximian.com>
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
15 using Mono
.Security
.X509
;
16 using Mono
.Security
.X509
.Extensions
;
18 using NUnit
.Framework
;
20 namespace MonoTests
.Mono
.Security
.X509
.Extensions
{
23 public class KeyUsageExtensionTest
{
25 private void Empty (KeyUsageExtension kue
)
27 Assert
.IsFalse (kue
.Critical
, "Critical");
28 Assert
.AreEqual ("2.5.29.15", kue
.Oid
, "Oid");
29 Assert
.IsNotNull (kue
.Name
, "Name");
30 Assert
.IsFalse (kue
.Name
== kue
.Oid
, "Name!=Oid");
31 Assert
.AreEqual (KeyUsages
.none
, kue
.KeyUsage
, "KeyUsage");
32 Assert
.IsTrue (kue
.Support (KeyUsages
.none
), "Support(none)");
33 Assert
.IsFalse (kue
.Support (KeyUsages
.digitalSignature
), "Support(digitalSignature)");
34 Assert
.IsFalse (kue
.Support (KeyUsages
.decipherOnly
), "Support(decipherOnly)");
38 public void Constructor_Empty ()
40 KeyUsageExtension kue
= new KeyUsageExtension ();
45 public void Constructor_Extension ()
47 KeyUsageExtension ext
= new KeyUsageExtension ();
48 KeyUsageExtension kue
= new KeyUsageExtension (ext
);
53 public void Constructor_ASN1 ()
55 KeyUsageExtension ext
= new KeyUsageExtension ();
56 KeyUsageExtension kue
= new KeyUsageExtension (ext
.ASN1
);
61 public void KeyUsage ()
63 KeyUsageExtension kue
= new KeyUsageExtension ();
64 foreach (KeyUsages ku
in Enum
.GetValues (typeof (KeyUsages
))) {
66 byte[] rawext
= kue
.GetBytes ();
68 if ((int) ku
> Byte
.MaxValue
) {
70 Assert
.AreEqual ((byte) ku
, rawext
[rawext
.Length
- 2], ku
.ToString () + ".Value2");
71 Assert
.AreEqual ((byte) ((int) ku
>> 8), rawext
[rawext
.Length
- 1], ku
.ToString () + ".Value1");
73 Assert
.AreEqual ((byte) ku
, rawext
[rawext
.Length
- 1], ku
.ToString () + ".Value");
75 Assert
.AreEqual (length
, rawext
.Length
, ku
.ToString () + ".Length");
80 public void KeyUsage_MaxValue ()
82 KeyUsageExtension kue
= new KeyUsageExtension ();
83 kue
.KeyUsage
= (KeyUsages
) Int32
.MaxValue
;
84 Assert
.IsTrue (kue
.Support (KeyUsages
.none
), "Support(none)");
85 Assert
.IsTrue (kue
.Support (KeyUsages
.digitalSignature
), "Support(digitalSignature)");
86 Assert
.IsTrue (kue
.Support (KeyUsages
.nonRepudiation
), "Support(nonRepudiation)");
87 Assert
.IsTrue (kue
.Support (KeyUsages
.keyEncipherment
), "Support(keyEncipherment)");
88 Assert
.IsTrue (kue
.Support (KeyUsages
.dataEncipherment
), "Support(dataEncipherment)");
89 Assert
.IsTrue (kue
.Support (KeyUsages
.keyAgreement
), "Support(keyAgreement)");
90 Assert
.IsTrue (kue
.Support (KeyUsages
.keyCertSign
), "Support(keyCertSign)");
91 Assert
.IsTrue (kue
.Support (KeyUsages
.cRLSign
), "Support(cRLSign)");
92 Assert
.IsTrue (kue
.Support (KeyUsages
.encipherOnly
), "Support(encipherOnly)");
93 Assert
.IsTrue (kue
.Support (KeyUsages
.decipherOnly
), "Support(decipherOnly)");
97 public void Critical ()
99 KeyUsageExtension kue
= new KeyUsageExtension ();
101 foreach (KeyUsages ku
in Enum
.GetValues (typeof (KeyUsages
))) {
103 byte[] rawext
= kue
.GetBytes ();
105 if ((int) ku
> Byte
.MaxValue
) {
107 Assert
.AreEqual ((byte) ku
, rawext
[rawext
.Length
- 2], ku
.ToString () + ".Value2");
108 Assert
.AreEqual ((byte) ((int)ku
>> 8), rawext
[rawext
.Length
- 1], ku
.ToString () + ".Value1");
110 Assert
.AreEqual ((byte) ku
, rawext
[rawext
.Length
- 1], ku
.ToString () + ".Value");
112 Assert
.AreEqual (length
, rawext
.Length
, ku
.ToString () + ".Length");
113 Assert
.AreEqual (1, rawext
[7], ku
.ToString () + ".Critical.Tag");
114 Assert
.AreEqual (1, rawext
[8], ku
.ToString () + ".Critical.Length");
115 Assert
.AreEqual (255, rawext
[9], ku
.ToString () + ".Critical.Value");