public void VerifyData_Span_UsesTryHashDataAndVerifySignature() { var input = new byte[1024]; new Random(42).NextBytes(input); using (var wrapperDsa = new OverrideAbstractDSA(DSA.Create(1024))) { AssertExtensions.Throws <ArgumentException>("hashAlgorithm", () => wrapperDsa.VerifyData((Span <byte>) new byte[1], new byte[1], new HashAlgorithmName(null))); AssertExtensions.Throws <ArgumentException>("hashAlgorithm", () => wrapperDsa.VerifyData((Span <byte>) new byte[1], new byte[1], new HashAlgorithmName(""))); byte[] signature = wrapperDsa.SignData(input, HashAlgorithmName.SHA1); Assert.True(wrapperDsa.VerifyData(input.AsSpan(), signature, HashAlgorithmName.SHA1)); Assert.False(wrapperDsa.VerifyData(input.AsSpan(), signature.AsSpan().Slice(0, signature.Length - 1), HashAlgorithmName.SHA1)); } }
public void VerifyData_Stream_UsesHashDataAndVerifySignature() { var input = new byte[1024]; new Random(42).NextBytes(input); using (var wrapperDsa = new OverrideAbstractDSA(DSA.Create(1024))) { AssertExtensions.Throws <ArgumentNullException>("data", () => wrapperDsa.VerifyData((Stream)null, null, HashAlgorithmName.SHA1)); AssertExtensions.Throws <ArgumentNullException>("signature", () => wrapperDsa.VerifyData(new MemoryStream(new byte[1]), null, HashAlgorithmName.SHA1)); AssertExtensions.Throws <ArgumentNullException>("hashAlgorithm", () => wrapperDsa.VerifyData(new MemoryStream(new byte[1]), new byte[1], new HashAlgorithmName(null))); AssertExtensions.Throws <ArgumentException>("hashAlgorithm", () => wrapperDsa.VerifyData(new MemoryStream(new byte[1]), new byte[1], new HashAlgorithmName(""))); byte[] signature = wrapperDsa.SignData(new MemoryStream(input), HashAlgorithmName.SHA1); Assert.True(wrapperDsa.VerifyData(new MemoryStream(input), signature, HashAlgorithmName.SHA1)); Assert.False(wrapperDsa.VerifyData(new MemoryStream(input), signature.AsSpan(0, signature.Length - 1).ToArray(), HashAlgorithmName.SHA1)); } }
public void VerifyData_Array_UsesHashDataAndVerifySignature() { var input = new byte[1024]; new Random(42).NextBytes(input); using (var wrapperDsa = new OverrideAbstractDSA(DSA.Create(1024))) { AssertExtensions.Throws <ArgumentNullException>("data", () => wrapperDsa.VerifyData((byte[])null, null, HashAlgorithmName.SHA1)); AssertExtensions.Throws <ArgumentNullException>("data", () => wrapperDsa.VerifyData(null, 0, 0, null, HashAlgorithmName.SHA1)); AssertExtensions.Throws <ArgumentOutOfRangeException>("offset", () => wrapperDsa.VerifyData(new byte[1], -1, 0, null, HashAlgorithmName.SHA1)); AssertExtensions.Throws <ArgumentOutOfRangeException>("offset", () => wrapperDsa.VerifyData(new byte[1], 2, 0, null, HashAlgorithmName.SHA1)); AssertExtensions.Throws <ArgumentOutOfRangeException>("count", () => wrapperDsa.VerifyData(new byte[1], 0, -1, null, HashAlgorithmName.SHA1)); AssertExtensions.Throws <ArgumentOutOfRangeException>("count", () => wrapperDsa.VerifyData(new byte[1], 0, 2, null, HashAlgorithmName.SHA1)); AssertExtensions.Throws <ArgumentNullException>("signature", () => wrapperDsa.VerifyData(new byte[1], 0, 1, null, HashAlgorithmName.SHA1)); AssertExtensions.Throws <ArgumentException>("hashAlgorithm", () => wrapperDsa.VerifyData(new byte[1], new byte[1], new HashAlgorithmName(null))); AssertExtensions.Throws <ArgumentException>("hashAlgorithm", () => wrapperDsa.VerifyData(new byte[1], new byte[1], new HashAlgorithmName(""))); byte[] signature = wrapperDsa.SignData(input, HashAlgorithmName.SHA1); Assert.True(wrapperDsa.VerifyData(input.AsSpan(), signature, HashAlgorithmName.SHA1)); Assert.False(wrapperDsa.VerifyData(input.AsSpan(), signature.AsSpan().Slice(0, signature.Length - 1), HashAlgorithmName.SHA1)); } }