Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/Microsoft.Data.SqlClient/tests/Common/Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<IntermediateOutputPath>$(ObjFolder)$(Configuration).$(Platform).$(AssemblyName)</IntermediateOutputPath>
<OutputPath>$(BinFolder)$(Configuration).$(Platform).$(AssemblyName)</OutputPath>
<IsTestProject>true</IsTestProject>
<Nullable>enable</Nullable>
</PropertyGroup>

<!-- OS Constants ==================================================== -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected X509Certificate2 CreateCertificate(string subjectName, IEnumerable<str
DateTimeOffset notBefore = DateTimeOffset.UtcNow.AddDays(-1);
DateTimeOffset notAfter = DateTimeOffset.UtcNow.AddDays(1);
byte[] passwordBytes = new byte[32];
string password = null;
string? password = null;
Random rnd = new Random();

rnd.NextBytes(passwordBytes);
Expand Down Expand Up @@ -256,7 +256,7 @@ private static RSA CreateRSA(bool forceCsp)

protected void AddToStore(X509Certificate2 cert, StoreLocation storeLocation, StoreName storeName)
{
CertificateStoreContext storeContext = _certificateStoreModifications.Find(csc => csc.Location == storeLocation && csc.Name == storeName);
CertificateStoreContext? storeContext = _certificateStoreModifications.Find(csc => csc.Location == storeLocation && csc.Name == storeName);

if (storeContext == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public sealed class ColumnEncryptionCertificateFixture : CertificateFixtureBase
public X509Certificate2 CertificateWithoutPrivateKey { get; }

private readonly X509Certificate2 _currentUserCertificate;
private readonly X509Certificate2 _localMachineCertificate;
private readonly X509Certificate2? _localMachineCertificate;

public ColumnEncryptionCertificateFixture()
{
Expand Down Expand Up @@ -57,11 +57,19 @@ public ColumnEncryptionCertificateFixture()

public X509Certificate2 GetCertificate(StoreLocation storeLocation)
{
return storeLocation == StoreLocation.CurrentUser
? _currentUserCertificate
: storeLocation == StoreLocation.LocalMachine && IsAdmin
? _localMachineCertificate
: throw new InvalidOperationException("Attempted to retrieve the certificate added to the local machine store; this requires administrator rights.");
if (storeLocation == StoreLocation.CurrentUser)
{
return _currentUserCertificate;
}

if (storeLocation == StoreLocation.LocalMachine &&
IsAdmin &&
_localMachineCertificate is not null)
{
return _localMachineCertificate;
}

throw new InvalidOperationException("Attempted to retrieve the certificate added to the local machine store; this requires administrator rights.");
}

public static bool IsAdmin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public ColumnMasterKeyCertificateFixture()
{
}

public X509Certificate2 ColumnMasterKeyCertificate { get; }
public X509Certificate2? ColumnMasterKeyCertificate { get; }

protected ColumnMasterKeyCertificateFixture(bool createCertificate)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ public CspCertificateFixture()

public string CspCertificatePath { get; }

public string CspKeyPath { get; }
public string? CspKeyPath { get; }

private string GetCspPathFromCertificate()
private string? GetCspPathFromCertificate()
{
RSA privateKey = CspCertificate.GetRSAPrivateKey();
RSA? privateKey = CspCertificate.GetRSAPrivateKey();

if (privateKey is RSACryptoServiceProvider csp)
{
return string.Concat(csp.CspKeyContainerInfo.ProviderName, @"/", csp.CspKeyContainerInfo.KeyContainerName);
}
else if (privateKey is RSACng cng)
else if (privateKey is RSACng cng && cng.Key.Provider is not null)
{
return string.Concat(cng.Key.Provider.Provider, @"/", cng.Key.KeyName);
}
Expand Down
Loading
Loading