public override void PerformTest() { KeyUsage k = new KeyUsage(KeyUsage.DigitalSignature); if ((k.GetBytes()[0] != (byte)KeyUsage.DigitalSignature) || (k.PadBits != 7)) { Fail("failed digitalSignature"); } k = new KeyUsage(KeyUsage.NonRepudiation); if ((k.GetBytes()[0] != (byte)KeyUsage.NonRepudiation) || (k.PadBits != 6)) { Fail("failed nonRepudiation"); } k = new KeyUsage(KeyUsage.KeyEncipherment); if ((k.GetBytes()[0] != (byte)KeyUsage.KeyEncipherment) || (k.PadBits != 5)) { Fail("failed keyEncipherment"); } k = new KeyUsage(KeyUsage.CrlSign); if ((k.GetBytes()[0] != (byte)KeyUsage.CrlSign) || (k.PadBits != 1)) { Fail("failed cRLSign"); } k = new KeyUsage(KeyUsage.DecipherOnly); if ((k.GetBytes()[1] != (byte)(KeyUsage.DecipherOnly >> 8)) || (k.PadBits != 7)) { Fail("failed decipherOnly"); } // test for zero length bit string try { Asn1Object.FromByteArray(new DerBitString(new byte[0], 0).GetEncoded()); } catch (IOException e) { Fail(e.ToString()); } DoTestRandomPadBits(); DoTestZeroLengthStrings(); }
public ITestResult Perform() { KeyUsage k = new KeyUsage(KeyUsage.DigitalSignature); if ((k.GetBytes()[0] != (byte)KeyUsage.DigitalSignature) || (k.PadBits != 7)) { return(new SimpleTestResult(false, Name + ": failed digitalSignature")); } k = new KeyUsage(KeyUsage.NonRepudiation); if ((k.GetBytes()[0] != (byte)KeyUsage.NonRepudiation) || (k.PadBits != 6)) { return(new SimpleTestResult(false, Name + ": failed nonRepudiation")); } k = new KeyUsage(KeyUsage.KeyEncipherment); if ((k.GetBytes()[0] != (byte)KeyUsage.KeyEncipherment) || (k.PadBits != 5)) { return(new SimpleTestResult(false, Name + ": failed keyEncipherment")); } k = new KeyUsage(KeyUsage.CrlSign); if ((k.GetBytes()[0] != (byte)KeyUsage.CrlSign) || (k.PadBits != 1)) { return(new SimpleTestResult(false, Name + ": failed cRLSign")); } k = new KeyUsage(KeyUsage.DecipherOnly); if ((k.GetBytes()[1] != (byte)(KeyUsage.DecipherOnly >> 8)) || (k.PadBits != 7)) { return(new SimpleTestResult(false, Name + ": failed decipherOnly")); } // test for zero length bit string try { Asn1Object.FromByteArray(new DerBitString(new byte[0], 0).GetEncoded()); } catch (IOException e) { return(new SimpleTestResult(false, Name + ": " + e)); } return(new SimpleTestResult(true, Name + ": Okay")); }
/// <inheritdoc /> public override void InjectReferenceValue(X509Certificate2 value) { Certificate = value; DerBitString derBitString = GetExtensionValue(value) as DerBitString; if (derBitString == null) { if (IsRequired()) { throw new PolicyRequiredException("Extention " + ExtentionIdentifier.Display + " is marked as required by is not present."); } PolicyValue = new PolicyValue <int>(0); return; } var keyUsage = new KeyUsage(derBitString.IntValue); byte[] data = keyUsage.GetBytes(); int intValue = (data.Length == 1) ? data[0] & 0xff : (data[1] & 0xff) << 8 | (data[0] & 0xff); PolicyValue = new PolicyValue <int>(intValue); }