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

Code before:
                    CborReaderState.UnsignedInteger or CborReaderState.NegativeInteger => new CoseHeaderLabel(reader.ReadInt32()),
                    CborReaderState.TextString => new CoseHeaderLabel(reader.ReadTextString()),
                    _ => throw new CryptographicException(SR.Format(SR.DecodeErrorWhileDecoding, SR.DecodeSign1MapLabelWasIncorrect))
                };

                CoseHeaderValue value = CoseHeaderValue.FromEncodedValue(reader.ReadEncodedValue().Span);
                headerParameters.Add(label, value);
            }
            reader.ReadEndMap();
        }

        private static byte[]? DecodePayload(CborReader reader)
        {
            CborReaderState state = reader.PeekState();
            if (state == CborReaderState.Null)
            {
                reader.ReadNull();
                return null;
            }
            if (state == CborReaderState.ByteString)
            {
                return reader.ReadByteString();
            }

            throw new CryptographicException(SR.Format(SR.DecodeErrorWhileDecoding, SR.DecodeSign1PayloadWasIncorrect));
        }

        private static byte[] DecodeSignature(CborReader reader)
        {
            return reader.ReadByteString();
        }

        private static List<CoseSignature> DecodeCoseSignaturesArray(CborReader reader)
        {
            int? signaturesLength = reader.ReadStartArray();
            List<CoseSignature> signatures = new List<CoseSignature>(signaturesLength.GetValueOrDefault());

            while (reader.PeekState() == CborReaderState.StartArray)
            {
                CoseSignature signature = DecodeCoseSignature(reader.ReadEncodedValue());
                signatures.Add(signature);
            }

            reader.ReadEndArray();

            if (signatures.Count < 1)
            {
                throw new CryptographicException(SR.Format(SR.DecodeErrorWhileDecoding, SR.MultiSignMessageMustCarryAtLeastOneSignature));
            }

            return signatures;

Review comment (suggestion):
Comparing `e.ParamName` to the string literal `"value"` is brittle. Prefer `nameof(value)` here to avoid a magic string and reduce the chance of typos during future edits; also consider including the original exception as the inner exception when rethrowing as `CryptographicException` to preserve diagnostic context.
```suggestion
                    if (e.ParamName == nameof(value))
                    {
                        throw new CryptographicException(e.Message, e);
```

Code after:

                if (state == CborReaderState.EndMap)
                {
                    reader.ReadEndMap();
                    break;
                }

                CoseHeaderLabel label = state switch
                {
                    CborReaderState.UnsignedInteger or CborReaderState.NegativeInteger => new CoseHeaderLabel(reader.ReadInt32()),
                    CborReaderState.TextString => new CoseHeaderLabel(reader.ReadTextString()),
                    _ => throw new CryptographicException(SR.Format(SR.DecodeErrorWhileDecoding, SR.DecodeSign1MapLabelWasIncorrect))
                };

                CoseHeaderValue value = CoseHeaderValue.FromEncodedValue(reader.ReadEncodedValue().Span);

                try
                {
                    headerParameters.Add(label, value);
                }
                catch (ArgumentException e)
                {
                    // Lift the well-known header value validation into a CryptographicException.
                    if (e.ParamName == "value")
                    {
                        throw new CryptographicException(e.Message);
                    }

                    Debug.Fail("Unexpected ArgumentException from CoseHeaderMap.Add");
                    throw new CryptographicException(SR.DecodeErrorWhileDecodingSeeInnerEx, e);
                }
            }
        }

        private static byte[]? DecodePayload(CborReader reader)
        {
            CborReaderState state = reader.PeekState();
            if (state == CborReaderState.Null)
            {
                reader.ReadNull();
                return null;
            }
            if (state == CborReaderState.ByteString)
            {
                return reader.ReadByteString();
            }

            throw new CryptographicException(SR.Format(SR.DecodeErrorWhileDecoding, SR.DecodeSign1PayloadWasIncorrect));
        }

        private static byte[] DecodeSignature(CborReader reader)