public void ConstructorEmpty ()
		{
			X509EnhancedKeyUsageExtension eku = new X509EnhancedKeyUsageExtension ();
			Assert.IsFalse (eku.Critical, "Critical");
			Assert.IsNull (eku.RawData, "RawData");
			Assert.AreEqual (oid, eku.Oid.Value, "Oid.Value");
			Assert.AreEqual (fname, eku.Oid.FriendlyName, "Oid.FriendlyName");
			Assert.AreEqual (String.Empty, eku.Format (true), "Format(true)");
			Assert.AreEqual (String.Empty, eku.Format (false), "Format(false)");
		}
		public void ConstructorEmpty ()
		{
			X509EnhancedKeyUsageExtension eku = new X509EnhancedKeyUsageExtension ();
			Assert.IsFalse (eku.Critical, "Critical");
			Assert.IsNull (eku.RawData, "RawData");
			Assert.AreEqual (oid, eku.Oid.Value, "Oid.Value");
			// FIXME: Don't expect that FriendlyName is English. This test fails under non-English Windows.
			//Assert.AreEqual (fname, eku.Oid.FriendlyName, "Oid.FriendlyName");
			Assert.AreEqual (String.Empty, eku.Format (true), "Format(true)");
			Assert.AreEqual (String.Empty, eku.Format (false), "Format(false)");
		}
		public void ConstructorAsnEncodedData ()
		{
			AsnEncodedData aed = new AsnEncodedData (new byte[] { 0x30, 0x05, 0x06, 0x03, 0x2A, 0x03, 0x04 });
			X509EnhancedKeyUsageExtension eku = new X509EnhancedKeyUsageExtension (aed, true);
			Assert.IsTrue (eku.Critical, "Critical");
			Assert.AreEqual (7, eku.RawData.Length, "RawData");	// original Oid ignored
			Assert.AreEqual (oid, eku.Oid.Value, "Oid.Value");
			Assert.AreEqual (fname, eku.Oid.FriendlyName, "Oid.FriendlyName");
			Assert.AreEqual (1, eku.EnhancedKeyUsages.Count, "EnhancedKeyUsages");
			Assert.AreEqual ("1.2.3.4", eku.EnhancedKeyUsages[0].Value, "EnhancedKeyUsages Oid");
			Assert.AreEqual ("Unknown Key Usage (1.2.3.4)" + Environment.NewLine, eku.Format (true), "Format(true)");
			Assert.AreEqual ("Unknown Key Usage (1.2.3.4)", eku.Format (false), "Format(false)");
		}
		public void ConstructorAsnEncodedData_BadAsn ()
		{
			AsnEncodedData aed = new AsnEncodedData ("1.2.3", new byte[0]);
			X509EnhancedKeyUsageExtension eku = new X509EnhancedKeyUsageExtension (aed, true);
			Assert.AreEqual (String.Empty, eku.Format (true), "Format(true)");
			Assert.AreEqual (String.Empty, eku.Format (false), "Format(false)");
			OidCollection oc = eku.EnhancedKeyUsages;
		}
예제 #5
0
		[Category ("NotDotNet")] // FriendlyName should not only be English.
		public void Build_X509EnhancedKeyUsageExtension ()
		{
			AsnEncodedData aed = new AsnEncodedData (new byte[] { 0x30, 0x05, 0x06, 0x03, 0x2A, 0x03, 0x04 });
			Assert.AreEqual ("30 05 06 03 2a 03 04", aed.Format (true), "Format(true)");
			Assert.AreEqual ("30 05 06 03 2a 03 04", aed.Format (false), "Format(false)");
			aed.Oid = new Oid ("2.5.29.37");
			// and now "AsnEncodedData" knows how to (magically) decode the data without involving the class
			// FIXME: Don't expect that FriendlyName is English. This test fails under non-English Windows.
			Assert.AreEqual ("Unknown Key Usage (1.2.3.4)" + Environment.NewLine, aed.Format (true), "aed.Format(true)");
			Assert.AreEqual ("Unknown Key Usage (1.2.3.4)", aed.Format (false), "aed.Format(false)");
			// compare with the output of the "appropriate" class
			X509EnhancedKeyUsageExtension eku = new X509EnhancedKeyUsageExtension (aed, false);
			// FIXME: Don't expect that FriendlyName is English. This test fails under non-English Windows.
			Assert.AreEqual ("Unknown Key Usage (1.2.3.4)" + Environment.NewLine, eku.Format (true), "eku.Format(true)");
			Assert.AreEqual ("Unknown Key Usage (1.2.3.4)", eku.Format (false), "eku.Format(false)");
		}
		public void ConstructorOidCollection ()
		{
			OidCollection oc = new OidCollection ();
			X509EnhancedKeyUsageExtension eku = new X509EnhancedKeyUsageExtension (oc, true);
			Assert.AreEqual ("30-00", BitConverter.ToString (eku.RawData), "RawData");
			Assert.AreEqual (0, eku.EnhancedKeyUsages.Count, "Count 0");
			Assert.AreEqual ("Information Not Available", eku.Format (true), "Format(true)");
			Assert.AreEqual ("Information Not Available", eku.Format (false), "Format(false)");
			oc.Add (new Oid ("1.2.3.4"));
			Assert.AreEqual (0, eku.EnhancedKeyUsages.Count, "Count still 0");
			int n = eku.EnhancedKeyUsages.Add (new Oid ("1.2.3"));
			Assert.AreEqual (0, n, "Add");
			Assert.AreEqual (0, eku.EnhancedKeyUsages.Count, "Count again 0");	// readonly!
			Assert.AreEqual (1, oc.Count, "Count 1 - oc");
			Assert.AreEqual ("1.2.3.4", oc [0].Value, "Value - oc");

			oc.Add (new Oid ("1.3.6.1.5.5.7.3.1"));
			eku = new X509EnhancedKeyUsageExtension (oc, true);
			Assert.AreEqual (2, eku.EnhancedKeyUsages.Count, "Count 2");
			Assert.AreEqual ("1.2.3.4", eku.EnhancedKeyUsages[0].Value, "Value - 1");
			Assert.AreEqual ("1.3.6.1.5.5.7.3.1", eku.EnhancedKeyUsages[1].Value, "Value - 2");
			Assert.AreEqual ("Unknown Key Usage (1.2.3.4)" + Environment.NewLine + "Server Authentication (1.3.6.1.5.5.7.3.1)" + Environment.NewLine,
				eku.Format (true), "Format(true)");
			Assert.AreEqual ("Unknown Key Usage (1.2.3.4), Server Authentication (1.3.6.1.5.5.7.3.1)", eku.Format (false), "Format(false)");
		}