From 9a36e3d9ff248506968d097839b6e5a81d583257 Mon Sep 17 00:00:00 2001 From: Pranav Senthilnathan Date: Fri, 17 Jul 2026 16:54:04 -0700 Subject: [PATCH 1/4] Add System.Security.Cryptography Copilot instructions Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 42bda83a-f457-4dcc-a426-e12aa6e4d47e --- ...stem-security-cryptography.instructions.md | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/instructions/system-security-cryptography.instructions.md diff --git a/.github/instructions/system-security-cryptography.instructions.md b/.github/instructions/system-security-cryptography.instructions.md new file mode 100644 index 00000000000000..eace4987554a3a --- /dev/null +++ b/.github/instructions/system-security-cryptography.instructions.md @@ -0,0 +1,23 @@ +--- +applyTo: "src/libraries/System.Security.Cryptography/**" +--- + +# System.Security.Cryptography — Folder-Specific Guidance + +## Code Style + +- Prefer scoped `using (...) { ... }` statements over `using` declarations (`using var ...`) so resource lifetimes and disposal scopes are explicit. This reinforces `csharp_prefer_simple_using_statement = false:none` in `.editorconfig`. +- When an `if` statement follows another statement in the same block, insert a blank line before the `if`. Do not add an artificial leading blank line when the `if` is the first statement in a block. + +## Correctness + +- Check the success result of `Try*` methods and any bytes-written value, whether returned directly or through an `out` parameter. When control flow guarantees an expected result or byte count, use `Debug.Assert`, a parameterless `CryptographicException`, or both, as appropriate. + +## Security + +- Clear owned writable buffers containing keys or other secret material with `CryptographicOperations.ZeroMemory` as soon as they are no longer needed. For rented buffers, return them with `ArrayPool.Return(..., clearArray: true)`. +- Use `CryptographicOperations.FixedTimeEquals` for secret-dependent comparisons; do not implement ad hoc comparison loops or use ordinary sequence equality. + +## Tests + +- Avoid throwing `SkipTestException`, which creates noisy test output. Prefer `[ConditionalFact]` or `[ConditionalTheory]` with a condition; when that is not possible, return early from the test. From 1a3cddd523074408954474f282607c2981df8316 Mon Sep 17 00:00:00 2001 From: Pranav Senthilnathan Date: Fri, 17 Jul 2026 17:00:44 -0700 Subject: [PATCH 2/4] Clarify member accessibility in crypto code Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 42bda83a-f457-4dcc-a426-e12aa6e4d47e --- .../instructions/system-security-cryptography.instructions.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/instructions/system-security-cryptography.instructions.md b/.github/instructions/system-security-cryptography.instructions.md index eace4987554a3a..efbe9a1318b9d0 100644 --- a/.github/instructions/system-security-cryptography.instructions.md +++ b/.github/instructions/system-security-cryptography.instructions.md @@ -8,6 +8,7 @@ applyTo: "src/libraries/System.Security.Cryptography/**" - Prefer scoped `using (...) { ... }` statements over `using` declarations (`using var ...`) so resource lifetimes and disposal scopes are explicit. This reinforces `csharp_prefer_simple_using_statement = false:none` in `.editorconfig`. - When an `if` statement follows another statement in the same block, insert a blank line before the `if`. Do not add an artificial leading blank line when the `if` is the first statement in a block. +- Declare members of internal types as `internal`, not `public`, except when `public` accessibility is required to implement a contract such as an interface. ## Correctness From 8e4d84b9872700940e1dabd00ed3e285c1830938 Mon Sep 17 00:00:00 2001 From: Pranav Senthilnathan Date: Fri, 17 Jul 2026 17:07:33 -0700 Subject: [PATCH 3/4] Use crypto-specific buffer clearing helpers Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 42bda83a-f457-4dcc-a426-e12aa6e4d47e --- .../instructions/system-security-cryptography.instructions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/instructions/system-security-cryptography.instructions.md b/.github/instructions/system-security-cryptography.instructions.md index efbe9a1318b9d0..a7b125a3dcbc82 100644 --- a/.github/instructions/system-security-cryptography.instructions.md +++ b/.github/instructions/system-security-cryptography.instructions.md @@ -16,7 +16,7 @@ applyTo: "src/libraries/System.Security.Cryptography/**" ## Security -- Clear owned writable buffers containing keys or other secret material with `CryptographicOperations.ZeroMemory` as soon as they are no longer needed. For rented buffers, return them with `ArrayPool.Return(..., clearArray: true)`. +- Clear owned writable buffers containing keys or other secret material with `CryptographicOperations.ZeroMemory` as soon as they are no longer needed. Use `CryptoPool.Rent` and `CryptoPool.Return` for rented buffers. For pinned arrays that should be cleared on disposal, use `PinAndClear.Track`. - Use `CryptographicOperations.FixedTimeEquals` for secret-dependent comparisons; do not implement ad hoc comparison loops or use ordinary sequence equality. ## Tests From 2c80f423f3bc384c55ade497eb395ff3a7fb727f Mon Sep 17 00:00:00 2001 From: Pranav Senthilnathan Date: Fri, 17 Jul 2026 17:08:06 -0700 Subject: [PATCH 4/4] Mention CryptoPoolLease for rented buffers Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 42bda83a-f457-4dcc-a426-e12aa6e4d47e --- .../instructions/system-security-cryptography.instructions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/instructions/system-security-cryptography.instructions.md b/.github/instructions/system-security-cryptography.instructions.md index a7b125a3dcbc82..2ba622c28c24c5 100644 --- a/.github/instructions/system-security-cryptography.instructions.md +++ b/.github/instructions/system-security-cryptography.instructions.md @@ -16,7 +16,7 @@ applyTo: "src/libraries/System.Security.Cryptography/**" ## Security -- Clear owned writable buffers containing keys or other secret material with `CryptographicOperations.ZeroMemory` as soon as they are no longer needed. Use `CryptoPool.Rent` and `CryptoPool.Return` for rented buffers. For pinned arrays that should be cleared on disposal, use `PinAndClear.Track`. +- Clear owned writable buffers containing keys or other secret material with `CryptographicOperations.ZeroMemory` as soon as they are no longer needed. Use `CryptoPoolLease` or `CryptoPool.Rent` and `CryptoPool.Return` for rented buffers. For pinned arrays that should be cleared on disposal, use `PinAndClear.Track`. - Use `CryptographicOperations.FixedTimeEquals` for secret-dependent comparisons; do not implement ad hoc comparison loops or use ordinary sequence equality. ## Tests