Ejemplo n.º 1
0
        public static void TryDecode_WithExtensions(bool withExcessData)
        {
            const string PaddingHex = "0403010203";

            byte[] inputBytes = (
                "307C0201013051300D06096086480165030402030500044060EDD3D91924EC2A2AABA0BD16997" +
                "4AF5A04BC5495342871CF52EF9AF8DF36BAB5B2E456B26C00B42147626C5ADDAAC986291091FA" +
                "7387D504A5BF62427176AD06022A03020501234567890101FFA016300A06042A0304050402050" +
                "030080602010204020400" + PaddingHex).HexToByteArray();

            var dataRange = new ReadOnlyMemory <byte>(inputBytes, 0, inputBytes.Length - PaddingHex.Length / 2);

            ReadOnlyMemory <byte> toUse = withExcessData ? inputBytes : dataRange;

            Rfc3161TimestampRequest request;
            int bytesRead;

            Assert.True(Rfc3161TimestampRequest.TryDecode(toUse, out request, out bytesRead), "TryDecode");
            Assert.Equal(dataRange.Length, bytesRead);
            Assert.NotNull(request);

            const string ExpectedHashHex =
                "60EDD3D91924EC2A2AABA0BD169974AF5A04BC5495342871CF52EF9AF8DF36BA" +
                "B5B2E456B26C00B42147626C5ADDAAC986291091FA7387D504A5BF62427176AD";

            Assert.Equal(1, request.Version);
            Assert.Equal(ExpectedHashHex, request.GetMessageHash().ByteArrayToHex());
            Assert.Equal(Oids.Sha512, request.HashAlgorithmId.Value);
            Assert.NotNull(request.RequestedPolicyId);
            Assert.Equal("1.2.3", request.RequestedPolicyId.Value);
            Assert.True(request.GetNonce().HasValue, "request.GetNonce().HasValue");
            Assert.Equal("0123456789", request.GetNonce().Value.ByteArrayToHex());
            Assert.True(request.RequestSignerCertificate, "request.RequestSignerCertificate");
            Assert.True(request.HasExtensions, "request.HasExtensions");

            X509ExtensionCollection extensions = request.GetExtensions();

            Assert.Equal(2, extensions.Count);
            Assert.Equal("1.2.3.4.5", extensions[0].Oid.Value);
            Assert.Equal("0500", extensions[0].RawData.ByteArrayToHex());
            Assert.Equal("0.1.2", extensions[1].Oid.Value);
            Assert.Equal("0400", extensions[1].RawData.ByteArrayToHex());
        }