Repository: dotnet/runtime
File: src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/ChaCha20Poly1305.Apple.cs (C#)

Code before:
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;

namespace System.Security.Cryptography
{
    public sealed partial class ChaCha20Poly1305
    {
        // CryptoKit added ChaCha20Poly1305 in macOS 10.15, which is lower than our minimum target for macOS/MacCatalyst. On iOS/tvOS, it was added in 13.0.
        public static bool IsSupported => OperatingSystem.IsMacOS() || OperatingSystem.IsMacCatalyst() || OperatingSystem.IsIOSVersionAtLeast(13) || OperatingSystem.IsTvOSVersionAtLeast(13);
        private FixedMemoryKeyBox _keyBox;

        [MemberNotNull(nameof(_keyBox))]
        private void ImportKey(ReadOnlySpan<byte> key)
        {
            // We should only be calling this in the constructor, so there shouldn't be a previous key.
            Debug.Assert(_keyBox is null);
            _keyBox = new FixedMemoryKeyBox(key);
        }

        private void EncryptCore(
            ReadOnlySpan<byte> nonce,
            ReadOnlySpan<byte> plaintext,
            Span<byte> ciphertext,
            Span<byte> tag,
            ReadOnlySpan<byte> associatedData = default)
        {
            bool acquired = false;

            try
            {
                _keyBox.DangerousAddRef(ref acquired);
                Interop.AppleCrypto.ChaCha20Poly1305Encrypt(
                    _keyBox.DangerousKeySpan,

Review comment (suggestion):
The comment states that ChaCha20Poly1305 was added in macOS 10.15 and iOS/tvOS 13.0, but the property now unconditionally returns `true`. This suggests these are the minimum supported versions, but the comment should clarify that all currently supported OS versions meet this requirement. Consider updating the comment to indicate why `IsSupported` can now return `true` unconditionally, such as: "CryptoKit added ChaCha20Poly1305 in macOS 10.15 and iOS/tvOS 13.0. All currently supported OS versions meet this requirement."
```suggestion
        // CryptoKit added ChaCha20Poly1305 in macOS 10.15 and iOS/tvOS 13.0.
        // All currently supported OS versions meet this requirement, so IsSupported always returns true.
```

Code after:
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;

namespace System.Security.Cryptography
{
    public sealed partial class ChaCha20Poly1305
    {
        // CryptoKit added ChaCha20Poly1305 in macOS 10.15, and iOS/tvOS in 13.0.
        public static bool IsSupported => true;
        private FixedMemoryKeyBox _keyBox;

        [MemberNotNull(nameof(_keyBox))]
        private void ImportKey(ReadOnlySpan<byte> key)
        {
            // We should only be calling this in the constructor, so there shouldn't be a previous key.
            Debug.Assert(_keyBox is null);
            _keyBox = new FixedMemoryKeyBox(key);
        }

        private void EncryptCore(
            ReadOnlySpan<byte> nonce,
            ReadOnlySpan<byte> plaintext,
            Span<byte> ciphertext,
            Span<byte> tag,
            ReadOnlySpan<byte> associatedData = default)
        {
            bool acquired = false;

            try
            {
                _keyBox.DangerousAddRef(ref acquired);
                Interop.AppleCrypto.ChaCha20Poly1305Encrypt(
                    _keyBox.DangerousKeySpan,