internal abstract class UnixPkcs12Reader : IDisposable
{
private const string DecryptedSentinel = nameof(UnixPkcs12Reader);
+ private const int ErrorInvalidPasswordHResult = unchecked((int)0x80070056);
private PfxAsn _pfxAsn;
private ContentInfoAsn[] _safeContentsValues;
}
catch (Exception e)
{
- throw new CryptographicException(SR.Cryptography_Pfx_BadPassword, e);
+ throw new CryptographicException(SR.Cryptography_Pfx_BadPassword, e)
+ {
+ HResult = ErrorInvalidPasswordHResult
+ };
}
finally
{
return;
}
- throw new CryptographicException(SR.Cryptography_Pfx_BadPassword);
+ throw new CryptographicException(SR.Cryptography_Pfx_BadPassword)
+ {
+ HResult = ErrorInvalidPasswordHResult
+ };
}
private void Decrypt(ReadOnlySpan<char> password, ReadOnlyMemory<byte> authSafeContents)
// Use a MAC count of 1 because we're not persisting things, and the password
// is with the test... just save some CPU cycles.
private const int MacCount = 1;
+ protected const int ErrorInvalidPasswordHResult = unchecked((int)0x80070056);
// Use SHA-1 for Windows 7-8.1 support.
private static readonly HashAlgorithmName s_digestAlgorithm = HashAlgorithmName.SHA1;
cert2.Attributes.Add(id2);
key1.Attributes.Add(id3);
key2.Attributes.Add(id4);
-
+
AddContents(keyContents, builder, pw, encrypt: false);
AddContents(certContents, builder, pw, encrypt: true);
builder.SealWithMac(pw, s_digestAlgorithm, MacCount);
-2146893819);
}
}
-
+
[Theory]
[InlineData(false, false)]
[InlineData(false, true)]
() => coll.Import(pfxBytes, wrongPassword, s_importFlags));
AssertMessageContains("password", ex);
+ Assert.Equal(ErrorInvalidPasswordHResult, ex.HResult);
}
protected override void ReadUnreadablePfx(
() => new X509Certificate2(pfxBytes, wrongPassword, s_importFlags));
AssertMessageContains("password", ex);
+ Assert.Equal(ErrorInvalidPasswordHResult, ex.HResult);
}
protected override void ReadUnreadablePfx(