Skip to content

Commit 633e044

Browse files
authored
Enable CA1419 (SafeHandle public parameterless ctor) (#55460)
1 parent 375ca44 commit 633e044

File tree

47 files changed

+94
-25
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+94
-25
lines changed

eng/CodeAnalysis.ruleset

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
<Rule Id="CA1416" Action="Warning" /> <!-- Validate platform compatibility -->
6969
<Rule Id="CA1417" Action="Warning" /> <!-- Do not use 'OutAttribute' on string parameters for P/Invokes -->
7070
<Rule Id="CA1418" Action="Warning" /> <!-- Use valid platform string -->
71+
<Rule Id="CA1419" Action="Warning" /> <!-- Provide a public parameterless constructor for concrete types derived from 'System.Runtime.InteropServices.SafeHandle' -->
7172
<Rule Id="CA1501" Action="None" /> <!-- Avoid excessive inheritance -->
7273
<Rule Id="CA1502" Action="None" /> <!-- Avoid excessive complexity -->
7374
<Rule Id="CA1505" Action="None" /> <!-- Avoid unmaintainable code -->

src/libraries/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.Keychain.macOS.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ internal sealed class SafeTemporaryKeychainHandle : SafeKeychainHandle
401401
private static readonly Dictionary<IntPtr, SafeTemporaryKeychainHandle> s_lookup =
402402
new Dictionary<IntPtr, SafeTemporaryKeychainHandle>();
403403

404-
internal SafeTemporaryKeychainHandle()
404+
public SafeTemporaryKeychainHandle()
405405
{
406406
}
407407

src/libraries/Common/src/Interop/Windows/HttpApi/Interop.HttpApi.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ internal sealed class SafeLocalFreeChannelBinding : ChannelBinding
508508
{
509509
private int _size;
510510

511-
private SafeLocalFreeChannelBinding() { }
511+
public SafeLocalFreeChannelBinding() { }
512512

513513
public override int Size
514514
{

src/libraries/Common/src/Interop/Windows/SspiCli/SecuritySafeHandles.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public static int SetContextAttributes(
128128

129129
internal sealed class SafeFreeContextBuffer_SECURITY : SafeFreeContextBuffer
130130
{
131-
internal SafeFreeContextBuffer_SECURITY() : base() { }
131+
public SafeFreeContextBuffer_SECURITY() : base() { }
132132

133133
protected override bool ReleaseHandle()
134134
{

src/libraries/Common/src/Microsoft/Win32/SafeHandles/Asn1SafeHandles.Unix.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ public override bool IsInvalid
6868

6969
internal sealed class SafeSharedAsn1IntegerHandle : SafeInteriorHandle
7070
{
71-
private SafeSharedAsn1IntegerHandle() :
71+
public SafeSharedAsn1IntegerHandle() :
7272
base(IntPtr.Zero, ownsHandle: true)
7373
{
7474
}
7575
}
7676

7777
internal sealed class SafeSharedAsn1OctetStringHandle : SafeInteriorHandle
7878
{
79-
private SafeSharedAsn1OctetStringHandle() :
79+
public SafeSharedAsn1OctetStringHandle() :
8080
base(IntPtr.Zero, ownsHandle: true)
8181
{
8282
}

src/libraries/Common/src/Microsoft/Win32/SafeHandles/GssSafeHandles.PlatformNotSupported.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public override bool IsInvalid
1818
}
1919

2020
protected override bool ReleaseHandle() => throw new PlatformNotSupportedException();
21-
private SafeGssNameHandle()
21+
22+
public SafeGssNameHandle()
2223
: base(IntPtr.Zero, true)
2324
{
2425
}
@@ -27,7 +28,7 @@ private SafeGssNameHandle()
2728
[UnsupportedOSPlatform("tvos")]
2829
internal sealed class SafeGssCredHandle : SafeHandle
2930
{
30-
private SafeGssCredHandle()
31+
public SafeGssCredHandle()
3132
: base(IntPtr.Zero, true)
3233
{
3334
}
@@ -43,7 +44,7 @@ public override bool IsInvalid
4344
[UnsupportedOSPlatform("tvos")]
4445
internal sealed class SafeGssContextHandle : SafeHandle
4546
{
46-
private SafeGssContextHandle()
47+
public SafeGssContextHandle()
4748
: base(IntPtr.Zero, true)
4849
{
4950
}

src/libraries/Common/src/Microsoft/Win32/SafeHandles/SafeUnicodeStringHandle.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
using System;
55
using System.Runtime.InteropServices;
66

7+
#pragma warning disable CA1419 // TODO https://github.com/dotnet/roslyn-analyzers/issues/5232: not intended for use with P/Invoke
8+
79
namespace Microsoft.Win32.SafeHandles
810
{
911
/// <summary>

src/libraries/Common/src/System/Net/Security/SecurityContextTokenHandle.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ internal sealed class SecurityContextTokenHandle : CriticalHandleZeroOrMinusOneI
1616
#endif
1717
private int _disposed;
1818

19-
private SecurityContextTokenHandle() : base()
19+
public SecurityContextTokenHandle() : base()
2020
{
2121
}
2222

src/libraries/Common/src/System/Net/Security/Unix/SafeDeleteNegoContext.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
using System.Text;
88
using Microsoft.Win32.SafeHandles;
99

10+
#pragma warning disable CA1419 // TODO https://github.com/dotnet/roslyn-analyzers/issues/5232: not intended for use with P/Invoke
11+
1012
namespace System.Net.Security
1113
{
1214
internal sealed class SafeDeleteNegoContext : SafeDeleteContext

src/libraries/Common/src/System/Net/Security/Unix/SafeDeleteSslContext.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
using System.Security.Cryptography;
1212
using System.Security.Cryptography.X509Certificates;
1313

14+
#pragma warning disable CA1419 // TODO https://github.com/dotnet/roslyn-analyzers/issues/5232: not intended for use with P/Invoke
15+
1416
namespace System.Net.Security
1517
{
1618
internal sealed class SafeDeleteSslContext : SafeDeleteContext

0 commit comments

Comments
 (0)