コード例 #1
0
		public void DumpNodeToStream(TagValueNode node) 
		{
			binWriter.Write(node.TagOctets_);
			binWriter.Write(node.LengthOctets_);

			if (node.IsLeaf()) 
			{
				binWriter.Write(node.ValueOctets_);
			}
			else 
			{
				foreach (TagValueNode nod in node.Nodes) 
				{
					DumpNodeToStream(nod);
				}
			}
		}
コード例 #2
0
		/// <summary>
		/// <para>
		/// This method traverses TagValue tree and expands all explicit and implicit tags and 
		/// turns them into simple tags.
		/// </para>
		/// <para>
		/// This is preparation before binary dump. There are no length octets - but now 
		/// when all value octets are expanded they can be easily calculated on the fly.</para>
		/// </summary>
		/// <param name="node">a node representing a TagValue tree</param>
		/// <returns>expanded corresponding tree</returns>
		public static TagValueNode Expand(TagValueNode node) 
		{

			if (!node.Tag.IsSimple())  { node = SimplifyTag(node); }

			if (node.IsLeaf()) 
			{
				node.innerLen = node.ValueOctets.Length;
			}
			else 
			{
				int valueLength = 0;
				for(int i=0; i<node.Nodes.Count; i++) 
				{
					node.Nodes[i] = Expand(node.Nodes[i] as TagValueNode);
					valueLength += (node.Nodes[i] as TagValueNode).outerLen;
				}
				node.innerLen = valueLength;
			}
			
			/// FinishUpNode...
			/// begin
			node.LengthOctets = DERMethods.MakeLengthOctets(node.innerLen);
			node.TagOctets    = DERMethods.MakeTagOctets(node.Tag as SimpleASN1TAG);
			node.outerLen = node.innerLen + node.LengthOctets.Length + node.TagOctets.Length;
			/// end 

			return node;
		}