public void IsSupportedAlgorithmAndKey(SupportedAlgorithmTheoryData theoryData) { var context = TestUtilities.WriteHeader($"{this}.IsSupportedAlgorithm", theoryData); try { if (theoryData.SecurityKey.CryptoProviderFactory.IsSupportedAlgorithm(theoryData.Algorithm, theoryData.SecurityKey) != theoryData.IsSupportedAlgorithm) { context.AddDiff($"SecurityKey.CryptoProviderFactory.IsSupportedAlgorithm != theoryData.IsSupportedAlgorithm. Algorithm: '{theoryData.Algorithm}', theoryData.SecurityKey: '{theoryData.SecurityKey}', theoryData.IsSupportedAlgorithm: '{theoryData.IsSupportedAlgorithm}'."); } theoryData.ExpectedException.ProcessNoException(context); } catch (Exception ex) { theoryData.ExpectedException.ProcessException(ex, context); } try { if (theoryData.SecurityKey.IsSupportedAlgorithm(theoryData.Algorithm) != theoryData.IsSupportedAlgorithm) { context.AddDiff($"SecurityKey.IsSupportedAlgorithm != theoryData.IsSupportedAlgorithm. Algorithm: '{theoryData.Algorithm}', theoryData.SecurityKey: '{theoryData.SecurityKey}', theoryData.IsSupportedAlgorithm: '{theoryData.IsSupportedAlgorithm}'."); } theoryData.ExpectedException.ProcessNoException(context); } catch (Exception ex) { theoryData.ExpectedException.ProcessException(ex, context); } TestUtilities.AssertFailIfErrors(context); }
public void IsSymmetricKeyWrapSupported(SupportedAlgorithmTheoryData theoryData) { var context = TestUtilities.WriteHeader($"{this}.IsSymmetricKeyWrapSupported", theoryData); try { if (SupportedAlgorithms.IsSupportedSymmetricKeyWrap(theoryData.Algorithm, theoryData.SecurityKey) != theoryData.IsSupportedAlgorithm) { context.AddDiff($"SupportedAlgorithms.IsSymmetricKeyWrapSupported != theoryData.IsSupportedAlgorithm. Algorithm: '{theoryData.Algorithm}', theoryData.SecurityKey: '{theoryData.SecurityKey}', theoryData.IsSupportedAlgorithm: '{theoryData.IsSupportedAlgorithm}'."); } theoryData.ExpectedException.ProcessNoException(context); } catch (Exception ex) { theoryData.ExpectedException.ProcessException(ex, context); } TestUtilities.AssertFailIfErrors(context); }
public void GetDigestFromSignatureAlgorithm(SupportedAlgorithmTheoryData theoryData) { var context = TestUtilities.WriteHeader($"{this}.GetDigestFromSignatureAlgorithm", theoryData); try { if (!theoryData.Digest.Equals(SupportedAlgorithms.GetDigestFromSignatureAlgorithm(theoryData.Algorithm))) { context.AddDiff($"(!theoryData.Digest.Equals(SupportedAlgorithms.GetDigestFromSignatureAlgorithm(theoryData.Algorithm)). '{theoryData.Digest}' != Expected result from: '{theoryData.Algorithm}'."); } theoryData.ExpectedException.ProcessNoException(context); } catch (Exception ex) { theoryData.ExpectedException.ProcessException(ex, context); } TestUtilities.AssertFailIfErrors(context); }
public void Constructors(SupportedAlgorithmTheoryData theoryData) { var context = TestUtilities.WriteHeader($"{this}.Constructors", theoryData); try { var providerContext = Guid.NewGuid().ToString(); var provider = CryptoProviderFactory.Default.CreateKeyWrapProvider(theoryData.SecurityKey, theoryData.Algorithm); provider.Context = providerContext; // validation is defered until first use provider.WrapKey(Guid.NewGuid().ToByteArray()); theoryData.ExpectedException.ProcessNoException(context); if (provider.Algorithm != theoryData.Algorithm) { context.AddDiff($"provider.Algorithm: '{provider.Algorithm}' != theoryData.Algorithm: '{theoryData.Algorithm}'."); } if (provider.Context != providerContext) { context.AddDiff($"provider.Context: '{provider.Context}' != providerContext: '{providerContext}'."); } if (!ReferenceEquals(provider.Key, theoryData.SecurityKey)) { context.AddDiff("!ReferenceEquals(provider.Key, theoryData.SecurityKey))"); } } catch (Exception ex) { theoryData.ExpectedException.ProcessException(ex, context); } TestUtilities.AssertFailIfErrors(context); }