-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Add cryptographic operation counts to prevent process crashes
Showing
5 changed files
with
116 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...es/System.Security.Cryptography/src/System/Security/Cryptography/ConcurrencyBlock.NoOp.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Threading; | ||
|
||
namespace System.Security.Cryptography | ||
{ | ||
internal struct ConcurrencyBlock | ||
{ | ||
private int _count; | ||
|
||
internal static Scope Enter(ref ConcurrencyBlock block) | ||
{ | ||
int count = Interlocked.Increment(ref block._count); | ||
|
||
if (count != 1) | ||
{ | ||
Interlocked.Decrement(ref block._count); | ||
throw new CryptographicException(SR.Cryptography_ConcurrentUseNotSupported); | ||
} | ||
|
||
return new Scope(ref block._count); | ||
} | ||
|
||
internal ref struct Scope | ||
{ | ||
private ref int _parentCount; | ||
|
||
internal Scope(ref int parentCount) | ||
{ | ||
_parentCount = ref parentCount; | ||
} | ||
|
||
internal void Dispose() | ||
{ | ||
Interlocked.Decrement(ref _parentCount); | ||
} | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...braries/System.Security.Cryptography/src/System/Security/Cryptography/ConcurrencyBlock.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Threading; | ||
|
||
namespace System.Security.Cryptography | ||
{ | ||
internal struct ConcurrencyBlock | ||
{ | ||
internal static Scope Enter(ref ConcurrencyBlock block) | ||
{ | ||
_ = block; | ||
return default; | ||
} | ||
|
||
internal ref struct Scope | ||
{ | ||
#pragma warning disable CA1822 // Member can be marked static | ||
internal void Dispose() | ||
{ | ||
} | ||
#pragma warning restore CA1822 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters