示例#1
0
        public void MultiSign_SignWithCriticalHeaders_NotTransportingTheSpecifiedCriticalHeaderThrows_AddSignature()
        {
            if (MessageKind != CoseMessageKind.MultiSign)
            {
                return;
            }

            ReadOnlySpan <byte>  encodedMsg   = Sign(s_sampleContent, GetCoseSigner(DefaultKey, DefaultHash));
            CoseMultiSignMessage multiSignMsg = Assert.IsType <CoseMultiSignMessage>(Decode(encodedMsg));

            multiSignMsg.RemoveSignature(0);

            CoseHeaderMap signProtectedHeaders = GetHeaderMapWithAlgorithm(DefaultAlgorithm);

            AddCriticalHeaders(signProtectedHeaders, null, includeSpecifiedCritHeader: false);

            CoseSigner signer = GetCoseSigner(DefaultKey, DefaultHash, signProtectedHeaders);

            Assert.Throws <CryptographicException>(() => AddSignature(multiSignMsg, s_sampleContent, signer));
        }
示例#2
0
        public void MultiSign_SignWithCriticalHeaders_AddSignature()
        {
            if (MessageKind != CoseMessageKind.MultiSign)
            {
                return;
            }

            ReadOnlySpan <byte>  encodedMsg   = Sign(s_sampleContent, GetCoseSigner(DefaultKey, DefaultHash));
            CoseMultiSignMessage multiSignMsg = Assert.IsType <CoseMultiSignMessage>(Decode(encodedMsg));

            multiSignMsg.RemoveSignature(0);

            CoseHeaderMap signProtectedHeaders = GetHeaderMapWithAlgorithm(DefaultAlgorithm);
            List <(CoseHeaderLabel, ReadOnlyMemory <byte>)> expectedSignProtected = GetExpectedProtectedHeaders(DefaultAlgorithm);

            AddCriticalHeaders(signProtectedHeaders, expectedSignProtected, includeSpecifiedCritHeader: true);

            CoseSigner signer = GetCoseSigner(DefaultKey, DefaultHash, signProtectedHeaders);

            AddSignature(multiSignMsg, s_sampleContent, signer);

            AssertCoseSignMessage(multiSignMsg.Encode(), s_sampleContent, DefaultKey, DefaultAlgorithm, expectedProtectedHeaders: expectedSignProtected);
        }