public static void OidHasNoNamespaceRequirement() { Pkcs12SafeBag safeBag = new TestSafeBag(Oids.Aes192); byte[] encoded = safeBag.Encode(); Assert.NotNull(encoded); }
public static void GetBagIdIsFactory() { Pkcs12SafeBag safeBag = new TestSafeBag(Oids.Aes192); Oid firstCall = safeBag.GetBagId(); Oid secondCall = safeBag.GetBagId(); Assert.Equal(Oids.Aes192, firstCall.Value); Assert.Equal(firstCall.Value, secondCall.Value); #if !NETCOREAPP Assert.NotSame(firstCall, secondCall); #endif }
public static void AttributesIsMutable() { Pkcs12SafeBag safeBag = new TestSafeBag(Oids.Aes192); CryptographicAttributeObjectCollection firstCall = safeBag.Attributes; Assert.Same(firstCall, safeBag.Attributes); Assert.Equal(0, firstCall.Count); firstCall.Add(new Pkcs9DocumentDescription("Description")); Assert.Equal(1, safeBag.Attributes.Count); Assert.Same(firstCall, safeBag.Attributes); }
public static void GetBagIdIsFactory() { Pkcs12SafeBag safeBag = new TestSafeBag(Oids.Aes192); Oid firstCall = safeBag.GetBagId(); Oid secondCall = safeBag.GetBagId(); Assert.NotSame(firstCall, secondCall); Assert.Equal(Oids.Aes192, firstCall.Value); Assert.Equal(firstCall.Value, secondCall.Value); secondCall.Value = Oids.Cms3DesWrap; Assert.NotEqual(firstCall.Value, secondCall.Value); Assert.Equal(Oids.Aes192, firstCall.Value); }
public static void BaseClassHonorsSkipCopy(bool skipCopy) { byte[] test = { 0x05, 0x00 }; Pkcs12SafeBag bag = new TestSafeBag(Oids.ContentType, test, skipCopy); bool isSame = test.AsSpan().Overlaps(bag.EncodedBagValue.Span); if (skipCopy) { Assert.True(isSame, "Is same memory"); } else { Assert.False(isSame, "Is same memory"); } }
public static void BaseClassVerifiesSingleBer(string inputHex, bool expectSuccess) { byte[] inputBytes = inputHex.HexToByteArray(); Func <TestSafeBag> func = () => new TestSafeBag(Oids.BasicConstraints2, inputBytes); if (expectSuccess) { TestSafeBag bag = func(); Assert.True(bag.EncodedBagValue.Span.SequenceEqual(inputBytes)); } else { Assert.ThrowsAny <CryptographicException>(func); } }
public static void TryEncodeBoundary() { TestSafeBag safeBag = new TestSafeBag(Oids.ContentType); byte[] encoded = safeBag.Encode(); byte[] buf = new byte[encoded.Length + 4]; buf.AsSpan().Fill(0xCA); Assert.False(safeBag.TryEncode(buf.AsSpan(0, encoded.Length - 1), out int bytesWritten)); Assert.Equal(0, bytesWritten); Assert.True(buf.All(b => b == 0xCA)); Assert.True(safeBag.TryEncode(buf.AsSpan(1), out bytesWritten)); Assert.Equal(encoded.Length, bytesWritten); Assert.Equal(0xCA, buf[0]); Assert.Equal(0xCA, buf[bytesWritten + 1]); Assert.True(encoded.AsSpan().SequenceEqual(buf.AsSpan(1, bytesWritten))); buf.AsSpan().Fill(0xCA); Assert.True(safeBag.TryEncode(buf.AsSpan(2, bytesWritten), out bytesWritten)); Assert.Equal(encoded.Length, bytesWritten); Assert.True(encoded.AsSpan().SequenceEqual(buf.AsSpan(2, bytesWritten))); }
public static void OidValidatedLate() { Pkcs12SafeBag safeBag = new TestSafeBag("potato"); Assert.ThrowsAny <CryptographicException>(() => safeBag.Encode()); }