Beispiel #1
0
        /// <summary>
        /// Parse the data from the input buffer recursively and return the root as an
        /// object of a subclass of DerNode.
        /// </summary>
        ///
        /// <param name="inputBuf">position.</param>
        /// <param name="startIdx">The offset into the buffer.</param>
        /// <returns>An object of a subclass of DerNode.</returns>
        public static DerNode parse(ByteBuffer inputBuf, int startIdx)
        {
            if (inputBuf.limit() <= startIdx)
            {
                throw new DerDecodingException(
                          "DerNode.parse: The input length is too small");
            }
            int nodeType = ((int)inputBuf.get(startIdx)) & 0xff;
            // Don't increment idx. We're just peeking.

            DerNode newNode;

            if (nodeType == net.named_data.jndn.encoding.der.DerNodeType.Boolean)
            {
                newNode = new DerNode.DerBoolean();
            }
            else if (nodeType == net.named_data.jndn.encoding.der.DerNodeType.Integer)
            {
                newNode = new DerNode.DerInteger();
            }
            else if (nodeType == net.named_data.jndn.encoding.der.DerNodeType.BitString)
            {
                newNode = new DerNode.DerBitString();
            }
            else if (nodeType == net.named_data.jndn.encoding.der.DerNodeType.OctetString)
            {
                newNode = new DerNode.DerOctetString();
            }
            else if (nodeType == net.named_data.jndn.encoding.der.DerNodeType.Null)
            {
                newNode = new DerNode.DerNull();
            }
            else if (nodeType == net.named_data.jndn.encoding.der.DerNodeType.ObjectIdentifier)
            {
                newNode = new DerNode.DerOid();
            }
            else if (nodeType == net.named_data.jndn.encoding.der.DerNodeType.Sequence)
            {
                newNode = new DerNode.DerSequence();
            }
            else if (nodeType == net.named_data.jndn.encoding.der.DerNodeType.PrintableString)
            {
                newNode = new DerNode.DerPrintableString();
            }
            else if (nodeType == net.named_data.jndn.encoding.der.DerNodeType.GeneralizedTime)
            {
                newNode = new DerNode.DerGeneralizedTime();
            }
            else if ((nodeType & 0xe0) == net.named_data.jndn.encoding.der.DerNodeType.ExplicitlyTagged)
            {
                newNode = new DerNode.DerExplicitlyTagged(nodeType & 0x1f);
            }
            else
            {
                throw new DerDecodingException("Unimplemented DER type " + nodeType);
            }

            newNode.decode(inputBuf, startIdx);
            return(newNode);
        }
Beispiel #2
0
        /// <summary>
        /// Parse the data from the input buffer recursively and return the root as an
        /// object of a subclass of DerNode.
        /// </summary>
        ///
        /// <param name="inputBuf">position.</param>
        /// <param name="startIdx">The offset into the buffer.</param>
        /// <returns>An object of a subclass of DerNode.</returns>
        public static DerNode parse(ByteBuffer inputBuf, int startIdx)
        {
            int nodeType = ((int) inputBuf.get(startIdx)) & 0xff;
            // Don't increment idx. We're just peeking.

            DerNode newNode;
            if (nodeType == net.named_data.jndn.encoding.der.DerNodeType.Boolean)
                newNode = new DerNode.DerBoolean ();
            else if (nodeType == net.named_data.jndn.encoding.der.DerNodeType.Integer)
                newNode = new DerNode.DerInteger ();
            else if (nodeType == net.named_data.jndn.encoding.der.DerNodeType.BitString)
                newNode = new DerNode.DerBitString ();
            else if (nodeType == net.named_data.jndn.encoding.der.DerNodeType.OctetString)
                newNode = new DerNode.DerOctetString ();
            else if (nodeType == net.named_data.jndn.encoding.der.DerNodeType.Null)
                newNode = new DerNode.DerNull ();
            else if (nodeType == net.named_data.jndn.encoding.der.DerNodeType.ObjectIdentifier)
                newNode = new DerNode.DerOid ();
            else if (nodeType == net.named_data.jndn.encoding.der.DerNodeType.Sequence)
                newNode = new DerNode.DerSequence ();
            else if (nodeType == net.named_data.jndn.encoding.der.DerNodeType.PrintableString)
                newNode = new DerNode.DerPrintableString ();
            else if (nodeType == net.named_data.jndn.encoding.der.DerNodeType.GeneralizedTime)
                newNode = new DerNode.DerGeneralizedTime ();
            else
                throw new DerDecodingException("Unimplemented DER type " + nodeType);

            newNode.decode(inputBuf, startIdx);
            return newNode;
        }