/// <summary>
        /// Encode the object into DER syntax tree.
        /// </summary>
        ///
        /// <returns>The encoded DER syntax tree.</returns>
        public DerNode toDer()
        {
            net.named_data.jndn.encoding.der.DerNode.DerSequence root = new net.named_data.jndn.encoding.der.DerNode.DerSequence();

            net.named_data.jndn.encoding.der.DerNode.DerOid         extensionId    = new net.named_data.jndn.encoding.der.DerNode.DerOid(extensionId_);
            net.named_data.jndn.encoding.der.DerNode.DerBoolean     isCritical     = new net.named_data.jndn.encoding.der.DerNode.DerBoolean(isCritical_);
            net.named_data.jndn.encoding.der.DerNode.DerOctetString extensionValue = new net.named_data.jndn.encoding.der.DerNode.DerOctetString(
                extensionValue_.buf());

            root.addChild(extensionId);
            root.addChild(isCritical);
            root.addChild(extensionValue);

            root.getSize();

            return(root);
        }
        /// <summary>
        /// Encode the object into DER syntax tree.
        /// </summary>
        ///
        /// <returns>The encoded DER syntax tree.</returns>
        public DerNode toDer()
        {
            net.named_data.jndn.encoding.der.DerNode.DerSequence  root = new net.named_data.jndn.encoding.der.DerNode.DerSequence ();

            net.named_data.jndn.encoding.der.DerNode.DerOid  extensionId = new net.named_data.jndn.encoding.der.DerNode.DerOid (extensionId_);
            net.named_data.jndn.encoding.der.DerNode.DerBoolean  isCritical = new net.named_data.jndn.encoding.der.DerNode.DerBoolean (isCritical_);
            net.named_data.jndn.encoding.der.DerNode.DerOctetString  extensionValue = new net.named_data.jndn.encoding.der.DerNode.DerOctetString (
                    extensionValue_.buf());

            root.addChild(extensionId);
            root.addChild(isCritical);
            root.addChild(extensionValue);

            root.getSize();

            return root;
        }
        public void testExtension()
        {
            // Now add an extension.
            String name       = "/hello/kitty";
            int    trustClass = 0;
            int    trustLevel = 300;

            net.named_data.jndn.encoding.der.DerNode.DerSequence    extValueRoot       = new net.named_data.jndn.encoding.der.DerNode.DerSequence();
            net.named_data.jndn.encoding.der.DerNode.DerOctetString extValueName       = new net.named_data.jndn.encoding.der.DerNode.DerOctetString(new Blob(name).buf());
            net.named_data.jndn.encoding.der.DerNode.DerInteger     extValueTrustClass = new net.named_data.jndn.encoding.der.DerNode.DerInteger(trustClass);
            net.named_data.jndn.encoding.der.DerNode.DerInteger     extValueTrustLevel = new net.named_data.jndn.encoding.der.DerNode.DerInteger(trustLevel);

            extValueRoot.addChild(extValueName);
            extValueRoot.addChild(extValueTrustClass);
            extValueRoot.addChild(extValueTrustLevel);

            Blob extValueData = extValueRoot.encode();

            String oidString  = "1.3.6.1.5.32.1";
            bool   isCritical = true;
            CertificateExtension certExtension = new CertificateExtension(
                oidString, isCritical, extValueData);

            toyCert.encode();
            Certificate cert = new Certificate(toyCert);

            cert.addExtension(certExtension);

            cert.encode();
            Blob certData  = cert.getContent();
            Data plainData = new Data();

            plainData.setContent(certData);
            // The constructor Certificate(Data) calls decode().
            Certificate decodedCert = new Certificate(plainData);

            Assert.AssertEquals("Wrong number of certificate extensions after decoding",
                                1, decodedCert.getExtensionList().Count);

            CertificateExtension decodedExtension = (CertificateExtension)decodedCert
                                                    .getExtensionList()[0];

            Assert.AssertEquals("Certificate extension has the wrong OID after decoding",
                                oidString, "" + decodedExtension.getOid());
            Assert.AssertEquals(
                "Certificate extension has the wrong isCritical value after decoding",
                isCritical, decodedExtension.getIsCritical());

            // Decode and check the extension value.
            DerNode parsedExtValue = net.named_data.jndn.encoding.der.DerNode.parse(decodedExtension.getValue()
                                                                                    .buf());
            IList decodedExtValueRoot = parsedExtValue.getChildren();

            Assert.AssertEquals(
                "Wrong number of certificate extension value items after decoding",
                3, decodedExtValueRoot.Count);

            net.named_data.jndn.encoding.der.DerNode.DerOctetString decodedName       = (net.named_data.jndn.encoding.der.DerNode.DerOctetString)decodedExtValueRoot[0];
            net.named_data.jndn.encoding.der.DerNode.DerInteger     decodedTrustClass = (net.named_data.jndn.encoding.der.DerNode.DerInteger)decodedExtValueRoot[1];
            net.named_data.jndn.encoding.der.DerNode.DerInteger     decodedTrustLevel = (net.named_data.jndn.encoding.der.DerNode.DerInteger)decodedExtValueRoot[2];
            Assert.AssertEquals("Wrong extension value name after decoding", name, ""
                                + decodedName.toVal());
            Assert.AssertEquals("Wrong extension value trust class after decoding",
                                trustClass, (int)(Int32)decodedTrustClass.toVal());
            Assert.AssertEquals("Wrong extension value trust level after decoding",
                                trustLevel, (int)(Int32)decodedTrustLevel.toVal());
        }
        public void testExtension()
        {
            // Now add an extension.
            String name = "/hello/kitty";
            int trustClass = 0;
            int trustLevel = 300;

            net.named_data.jndn.encoding.der.DerNode.DerSequence  extValueRoot = new net.named_data.jndn.encoding.der.DerNode.DerSequence ();
            net.named_data.jndn.encoding.der.DerNode.DerOctetString  extValueName = new net.named_data.jndn.encoding.der.DerNode.DerOctetString (new Blob(name).buf());
            net.named_data.jndn.encoding.der.DerNode.DerInteger  extValueTrustClass = new net.named_data.jndn.encoding.der.DerNode.DerInteger (trustClass);
            net.named_data.jndn.encoding.der.DerNode.DerInteger  extValueTrustLevel = new net.named_data.jndn.encoding.der.DerNode.DerInteger (trustLevel);

            extValueRoot.addChild(extValueName);
            extValueRoot.addChild(extValueTrustClass);
            extValueRoot.addChild(extValueTrustLevel);

            Blob extValueData = extValueRoot.encode();

            String oidString = "1.3.6.1.5.32.1";
            bool isCritical = true;
            CertificateExtension certExtension = new CertificateExtension(
                    oidString, isCritical, extValueData);
            toyCert.encode();
            Certificate cert = new Certificate(toyCert);
            cert.addExtension(certExtension);

            cert.encode();
            Blob certData = cert.getContent();
            Data plainData = new Data();
            plainData.setContent(certData);
            // The constructor Certificate(Data) calls decode().
            Certificate decodedCert = new Certificate(plainData);
            Assert.AssertEquals("Wrong number of certificate extensions after decoding",
                    1, decodedCert.getExtensionList().Count);

            CertificateExtension decodedExtension = (CertificateExtension) decodedCert
                            .getExtensionList()[0];
            Assert.AssertEquals("Certificate extension has the wrong OID after decoding",
                    oidString, "" + decodedExtension.getOid());
            Assert.AssertEquals(
                    "Certificate extension has the wrong isCritical value after decoding",
                    isCritical, decodedExtension.getIsCritical());

            // Decode and check the extension value.
            DerNode parsedExtValue = net.named_data.jndn.encoding.der.DerNode.parse(decodedExtension.getValue()
                    .buf());
            IList decodedExtValueRoot = parsedExtValue.getChildren();
            Assert.AssertEquals(
                    "Wrong number of certificate extension value items after decoding",
                    3, decodedExtValueRoot.Count);

            net.named_data.jndn.encoding.der.DerNode.DerOctetString  decodedName = (net.named_data.jndn.encoding.der.DerNode.DerOctetString ) decodedExtValueRoot[0];
            net.named_data.jndn.encoding.der.DerNode.DerInteger  decodedTrustClass = (net.named_data.jndn.encoding.der.DerNode.DerInteger ) decodedExtValueRoot[1];
            net.named_data.jndn.encoding.der.DerNode.DerInteger  decodedTrustLevel = (net.named_data.jndn.encoding.der.DerNode.DerInteger ) decodedExtValueRoot[2];
            Assert.AssertEquals("Wrong extension value name after decoding", name, ""
                    + decodedName.toVal());
            Assert.AssertEquals("Wrong extension value trust class after decoding",
                    trustClass, (int) (Int32) decodedTrustClass.toVal());
            Assert.AssertEquals("Wrong extension value trust level after decoding",
                    trustLevel, (int) (Int32) decodedTrustLevel.toVal());
        }