Exemple #1
0
        /// <summary>
        /// Get node by OID.
        /// </summary>
        /// <param name="oid">OID.</param>
        /// <param name="startNode">Starting node.</param>
        /// <returns>Null or Asn1Node.</returns>
        static public Asn1Node GetDecendantNodeByOid(string oid, Asn1Node startNode)
        {
            Asn1Node retval = null;
            Oid      xoid   = new Oid();

            for (int i = 0; i < startNode.ChildNodeCount; i++)
            {
                Asn1Node childNode = startNode.GetChildNode(i);
                int      tmpTag    = childNode.tag & Asn1Tag.TAG_MASK;
                if (tmpTag == Asn1Tag.OBJECT_IDENTIFIER)
                {
                    if (oid == xoid.Decode(childNode.Data))
                    {
                        retval = childNode;
                        break;
                    }
                }
                retval = GetDecendantNodeByOid(oid, childNode);
                if (retval != null)
                {
                    break;
                }
            }
            return(retval);
        }
Exemple #2
0
        /// <summary>
        /// Get descendant node by node path.
        /// </summary>
        /// <param name="nodePath">relative node path that refer to current node.</param>
        /// <returns></returns>
        public Asn1Node GetDescendantNodeByPath(string nodePath)
        {
            Asn1Node retval = this;

            if (nodePath == null)
            {
                return(retval);
            }
            nodePath = nodePath.TrimEnd().TrimStart();
            if (nodePath.Length < 1)
            {
                return(retval);
            }
            string[] route = nodePath.Split('/');
            try
            {
                for (int i = 1; i < route.Length; i++)
                {
                    retval = retval.GetChildNode(Convert.ToInt32(route[i]));
                }
            }
            catch
            {
                retval = null;
            }
            return(retval);
        }
Exemple #3
0
        /// <summary>
        /// Recursively set all the node data length.
        /// </summary>
        /// <param name="node"></param>
        /// <returns>node data length.</returns>
        protected static long ResetBranchDataLength(Asn1Node node)
        {
            long retval          = 0;
            long childDataLength = 0;

            if (node.ChildNodeCount < 1)
            {
                if (node.data != null)
                {
                    childDataLength += node.data.Length;
                }
            }
            else
            {
                for (int i = 0; i < node.ChildNodeCount; i++)
                {
                    childDataLength += ResetBranchDataLength(node.GetChildNode(i));
                }
            }
            node.dataLength = childDataLength;
            if (node.tag == Asn1Tag.BIT_STRING)
            {
                node.dataLength += BitStringUnusedFiledLength;
            }
            ResetDataLengthFieldWidth(node);
            retval = node.dataLength + TagLength + node.lengthFieldBytes;
            return(retval);
        }
Exemple #4
0
        /// <summary>
        /// Retrieve all the node count in the node subtree.
        /// </summary>
        /// <param name="node">starting node.</param>
        /// <returns>long integer node count in the node subtree.</returns>
        public static long GetDescendantNodeCount(Asn1Node node)
        {
            long count = 0;

            count += node.ChildNodeCount;
            for (int i = 0; i < node.ChildNodeCount; i++)
            {
                count += GetDescendantNodeCount(node.GetChildNode(i));
            }
            return(count);
        }
Exemple #5
0
        /// <summary>
        /// Recursively set all the child parameters, except dataLength.
        /// dataLength is set by ResetBranchDataLength.
        /// </summary>
        /// <param name="xNode">Starting node.</param>
        /// <param name="subOffset">Starting node offset.</param>
        protected void ResetChildNodePar(Asn1Node xNode, long subOffset)
        {
            int i;

            if (xNode.tag == Asn1Tag.BIT_STRING)
            {
                subOffset++;
            }
            Asn1Node tempNode;

            for (i = 0; i < xNode.ChildNodeCount; i++)
            {
                tempNode            = xNode.GetChildNode(i);
                tempNode.parentNode = xNode;
                tempNode.dataOffset = subOffset;
                tempNode.deepness   = xNode.deepness + 1;
                tempNode.path       = xNode.path + '/' + i.ToString();
                subOffset          += TagLength + tempNode.lengthFieldBytes;
                ResetChildNodePar(tempNode, subOffset);
                subOffset += tempNode.dataLength;
            }
        }