Repository: dotnet/runtime
File: src/libraries/System.Security.Cryptography.Cose/tests/CoseMessageTests.Sign.CustomHeaderMaps.cs (C#)

Code before:

        [Theory]
        [InlineData(0UL)]
        [InlineData(ulong.MaxValue)]
        [InlineData(long.MaxValue + 1UL)]
        [InlineData(long.MaxValue - 1UL)]
        public void SignWithCborNegativeIntegerRepresentationAlgorithmHeaderValue(ulong value)
        {
            var writer = new CborWriter();
            writer.WriteCborNegativeIntegerRepresentation(value);
            ReadOnlySpan<byte> encodedValue = writer.Encode();

            CoseHeaderMap protectedHeaders = new CoseHeaderMap();
            protectedHeaders[CoseHeaderLabel.Algorithm] = CoseHeaderValue.FromEncodedValue(encodedValue);

            Assert.Throws<CryptographicException>(() => Sign(s_sampleContent, DefaultKey, DefaultHash, protectedHeaders));
        }

        [Fact]
        public void SignWithCriticalHeaders()
        {
            CoseHeaderMap protectedHeaders = GetHeaderMapWithAlgorithm(DefaultAlgorithm);
            List<(CoseHeaderLabel, ReadOnlyMemory<byte>)> expectedProtectedHeaders = GetExpectedProtectedHeaders(DefaultAlgorithm);
            AddCriticalHeaders(protectedHeaders, expectedProtectedHeaders, includeSpecifiedCritHeader: true);

            CoseSigner signer = GetCoseSigner(DefaultKey, DefaultHash, protectedHeaders);
            ReadOnlySpan<byte> encodedMessage = Sign(s_sampleContent, signer);

            AssertCoseSignMessage(encodedMessage, s_sampleContent, DefaultKey, DefaultAlgorithm, expectedProtectedHeaders);
        }

        [Fact]
        public void SignWithCriticalHeaders_NotTransportingTheSpecifiedCriticalHeaderThrows()
        {
            CoseHeaderMap protectedHeaders = GetHeaderMapWithAlgorithm(DefaultAlgorithm);
            AddCriticalHeaders(protectedHeaders, null, includeSpecifiedCritHeader: false);

            CoseSigner signer = GetCoseSigner(DefaultKey, DefaultHash, protectedHeaders);
            Assert.Throws<ArgumentException>("signer", () => Sign(s_sampleContent, signer));
        }

        [Fact]
        public void MultiSign_SignWithCriticalHeaders_BodyHeaders()
        {
            if (MessageKind != CoseMessageKind.MultiSign)
            {
                return;
            }

            CoseHeaderMap bodyProtectedHeaders = GetEmptyHeaderMap();
            List<(CoseHeaderLabel, ReadOnlyMemory<byte>)> expectedBodyProtected = GetEmptyExpectedHeaders();

Review comment (suggestion):
The call mixes a named argument (`includeSpecifiedCritHeader: ...`) with a positional argument afterwards (`useIndefiniteLength`). C# requires all arguments after the first named argument to also be named, so this won't compile. Make the last argument named as well (e.g., `useIndefiniteLength: useIndefiniteLength`) or pass both booleans positionally.

Code after:

        [Theory]
        [InlineData(0UL)]
        [InlineData(ulong.MaxValue)]
        [InlineData(long.MaxValue + 1UL)]
        [InlineData(long.MaxValue - 1UL)]
        public void SignWithCborNegativeIntegerRepresentationAlgorithmHeaderValue(ulong value)
        {
            var writer = new CborWriter();
            writer.WriteCborNegativeIntegerRepresentation(value);
            ReadOnlySpan<byte> encodedValue = writer.Encode();

            CoseHeaderMap protectedHeaders = new CoseHeaderMap();
            protectedHeaders[CoseHeaderLabel.Algorithm] = CoseHeaderValue.FromEncodedValue(encodedValue);

            Assert.Throws<CryptographicException>(() => Sign(s_sampleContent, DefaultKey, DefaultHash, protectedHeaders));
        }

        [Theory]
        [InlineData(false)]
        [InlineData(true)]
        public void SignWithCriticalHeaders(bool useIndefiniteLength)
        {
            CoseHeaderMap protectedHeaders = GetHeaderMapWithAlgorithm(DefaultAlgorithm);
            List<(CoseHeaderLabel, ReadOnlyMemory<byte>)> expectedProtectedHeaders = GetExpectedProtectedHeaders(DefaultAlgorithm);
            AddCriticalHeaders(protectedHeaders, expectedProtectedHeaders, includeSpecifiedCritHeader: true, useIndefiniteLength);

            CoseSigner signer = GetCoseSigner(DefaultKey, DefaultHash, protectedHeaders);
            ReadOnlySpan<byte> encodedMessage = Sign(s_sampleContent, signer);

            AssertCoseSignMessage(encodedMessage, s_sampleContent, DefaultKey, DefaultAlgorithm, expectedProtectedHeaders);
        }

        [Theory]
        [InlineData(false)]
        [InlineData(true)]
        public void SignWithCriticalHeaders_NotTransportingTheSpecifiedCriticalHeaderThrows(bool useIndefiniteLength)
        {
            CoseHeaderMap protectedHeaders = GetHeaderMapWithAlgorithm(DefaultAlgorithm);
            AddCriticalHeaders(protectedHeaders, null, includeSpecifiedCritHeader: false, useIndefiniteLength);

            CoseSigner signer = GetCoseSigner(DefaultKey, DefaultHash, protectedHeaders);
            Assert.Throws<ArgumentException>("signer", () => Sign(s_sampleContent, signer));
        }

        [Theory]
        [InlineData(false)]
        [InlineData(true)]
        public void MultiSign_SignWithCriticalHeaders_BodyHeaders(bool useIndefiniteLength)
        {
            if (MessageKind != CoseMessageKind.MultiSign)