示例#1
0
        public static void BuildWithAllOptions()
        {
            byte[] data = { 1, 9, 7, 5, 0, 4, 0, 4 };
            Oid    requestedPolicyOid = new Oid("1.2.3", "1.2.3");

            byte[] nonce = "0123456789".HexToByteArray();

            X509ExtensionCollection extensionsIn = new X509ExtensionCollection
            {
                new X509Extension("1.2.3.4.5", new byte[] { 0x05, 0x00 }, false),
                new X509Extension("0.1.2", new byte[] { 0x04, 0x00 }, false),
            };

            Rfc3161TimestampRequest req = Rfc3161TimestampRequest.CreateFromData(
                data,
                HashAlgorithmName.SHA512,
                requestedPolicyOid,
                nonce,
                true,
                extensionsIn);

            Assert.NotNull(req);
            Assert.Equal(512 / 8, req.GetMessageHash().Length);
            Assert.Equal(Oids.Sha512, req.HashAlgorithmId.Value);
            Assert.NotNull(req.RequestedPolicyId);
            Assert.NotSame(requestedPolicyOid, req.RequestedPolicyId);
            Assert.Equal(requestedPolicyOid.Value, req.RequestedPolicyId.Value);
            Assert.True(req.GetNonce().HasValue, "req.GetNonce().HasValue");
            Assert.Equal(nonce.ByteArrayToHex(), req.GetNonce().Value.ByteArrayToHex());
            Assert.True(req.RequestSignerCertificate, "req.RequestSignerCertificate");
            Assert.True(req.HasExtensions, "req.HasExtensions");

            X509ExtensionCollection extensionsOut = req.GetExtensions();

            Assert.NotSame(extensionsIn, extensionsOut);
            Assert.Equal(extensionsIn.Count, extensionsOut.Count);
            Assert.NotSame(extensionsIn[0], extensionsOut[0]);
            Assert.NotSame(extensionsIn[0], extensionsOut[1]);
            Assert.NotSame(extensionsIn[1], extensionsOut[0]);
            Assert.NotSame(extensionsIn[1], extensionsOut[1]);

            // Extensions is order-preserving
            Assert.Equal(extensionsIn[0].Oid.Value, extensionsOut[0].Oid.Value);
            Assert.Equal(extensionsIn[0].RawData, extensionsOut[0].RawData);

            Assert.Equal(extensionsIn[1].Oid.Value, extensionsOut[1].Oid.Value);
            Assert.Equal(extensionsIn[1].RawData, extensionsOut[1].RawData);
        }