Exemplo n.º 1
0
        protected static long ResetBranchDataLength(Asn1Node node)
        {
            long num = 0;

            if (node.ChildNodeCount < 1L)
            {
                if (node.data != null)
                {
                    num += (long)node.data.Length;
                }
            }
            else
            {
                for (int index = 0; (long)index < node.ChildNodeCount; ++index)
                {
                    num += Asn1Node.ResetBranchDataLength(node.GetChildNode(index));
                }
            }
            node.dataLength = num;
            if (node.tag == (byte)3)
            {
                ++node.dataLength;
            }
            Asn1Node.ResetDataLengthFieldWidth(node);
            return(node.dataLength + 1L + node.lengthFieldBytes);
        }
Exemplo n.º 2
0
        public Asn1Node GetDescendantNodeByPath(string nodePath)
        {
            Asn1Node asn1Node = this;

            if (nodePath == null)
            {
                return(asn1Node);
            }
            nodePath = nodePath.TrimEnd().TrimStart();
            if (nodePath.Length < 1)
            {
                return(asn1Node);
            }
            string[] strArray = nodePath.Split('/');
            try
            {
                for (int index = 1; index < strArray.Length; ++index)
                {
                    asn1Node = asn1Node.GetChildNode(Convert.ToInt32(strArray[index]));
                }
            }
            catch
            {
                asn1Node = (Asn1Node)null;
            }
            return(asn1Node);
        }
Exemplo n.º 3
0
        public static long GetDescendantNodeCount(Asn1Node node)
        {
            long num = 0L + node.ChildNodeCount;

            for (int index = 0; (long)index < node.ChildNodeCount; ++index)
            {
                num += Asn1Node.GetDescendantNodeCount(node.GetChildNode(index));
            }
            return(num);
        }
Exemplo n.º 4
0
 protected void ResetChildNodePar(Asn1Node xNode, long subOffset)
 {
     if (xNode.tag == (byte)3)
     {
         ++subOffset;
     }
     for (int index = 0; (long)index < xNode.ChildNodeCount; ++index)
     {
         Asn1Node childNode = xNode.GetChildNode(index);
         childNode.parentNode = xNode;
         childNode.dataOffset = subOffset;
         childNode.deepness   = xNode.deepness + 1L;
         childNode.path       = xNode.path + (object)'/' + index.ToString();
         subOffset           += 1L + childNode.lengthFieldBytes;
         this.ResetChildNodePar(childNode, subOffset);
         subOffset += childNode.dataLength;
     }
 }
Exemplo n.º 5
0
        public static Asn1Node GetDecendantNodeByOid(string oid, Asn1Node startNode)
        {
            Asn1Node asn1Node = (Asn1Node)null;
            Oid      oid1     = new Oid();

            for (int index = 0; (long)index < startNode.ChildNodeCount; ++index)
            {
                Asn1Node childNode = startNode.GetChildNode(index);
                if (((int)childNode.tag & 31) == 6 && oid == oid1.Decode(childNode.Data))
                {
                    asn1Node = childNode;
                    break;
                }
                asn1Node = Asn1Node.GetDecendantNodeByOid(oid, childNode);
                if (asn1Node != null)
                {
                    break;
                }
            }
            return(asn1Node);
        }
Exemplo n.º 6
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;
		}
Exemplo n.º 7
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;
     }
 }
Exemplo n.º 8
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;
 }
Exemplo n.º 9
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;
		}