private void UseAfterDispose(ECDsa ecdsa)
        {
            byte[] data = { 1 };
            byte[] sig;

            // Ensure the key is populated, then dispose it.
            using (ecdsa)
            {
                sig = SignData(ecdsa, data, HashAlgorithmName.SHA256);
            }

            ecdsa.Dispose();

            UseAfterDispose(ecdsa, data, sig);

            if (!(PlatformDetection.IsNetFramework && ecdsa.GetType().Name.EndsWith("Cng")))
            {
                Assert.Throws <ObjectDisposedException>(() => ecdsa.GenerateKey(ECCurve.NamedCurves.nistP256));

                Assert.Throws <ObjectDisposedException>(
                    () => ecdsa.ImportParameters(EccTestData.GetNistP256ReferenceKey()));
            }

            // Either set_KeySize or SignData should throw.
            Assert.Throws <ObjectDisposedException>(
                () =>
            {
                ecdsa.KeySize = 384;
                SignData(ecdsa, data, HashAlgorithmName.SHA256);
            });
        }
Exemplo n.º 2
0
 public AliceRunner(ILogger <AliceRunner> logger)
 {
     _logger        = logger;
     _signAlgorithm = ECDsa.Create();
     _logger.LogInformation($"Using this ECDsa class: {_signAlgorithm.GetType().Name}");
 }