Ei kuvausta
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IAsn1Node.cs 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. //+-------------------------------------------------------------------------------+
  2. //| Copyright (c) 2003 Liping Dai. All rights reserved. |
  3. //| Web: www.lipingshare.com |
  4. //| Email: lipingshare@yahoo.com |
  5. //| |
  6. //| Copyright and Permission Details: |
  7. //| ================================= |
  8. //| Permission is hereby granted, free of charge, to any person obtaining a copy |
  9. //| of this software and associated documentation files (the "Software"), to deal |
  10. //| in the Software without restriction, including without limitation the rights |
  11. //| to use, copy, modify, merge, publish, distribute, and/or sell copies of the |
  12. //| Software, subject to the following conditions: |
  13. //| |
  14. //| 1. Redistributions of source code must retain the above copyright notice, this|
  15. //| list of conditions and the following disclaimer. |
  16. //| |
  17. //| 2. Redistributions in binary form must reproduce the above copyright notice, |
  18. //| this list of conditions and the following disclaimer in the documentation |
  19. //| and/or other materials provided with the distribution. |
  20. //| |
  21. //| THE SOFTWARE PRODUCT IS PROVIDED �AS IS� WITHOUT WARRANTY OF ANY KIND, |
  22. //| EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
  23. //| WARRANTIES OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR |
  24. //| A PARTICULAR PURPOSE. |
  25. //+-------------------------------------------------------------------------------+
  26. using System.IO;
  27. namespace LipingShare.LCLib.Asn1Processor
  28. {
  29. /// <summary>
  30. /// IAsn1Node interface.
  31. /// </summary>
  32. internal interface IAsn1Node
  33. {
  34. /// <summary>
  35. /// Load data from Stream.
  36. /// </summary>
  37. /// <param name="xdata"></param>
  38. /// <returns>true:Succeed; false:failed.</returns>
  39. bool LoadData(Stream xdata);
  40. /// <summary>
  41. /// Save node data into Stream.
  42. /// </summary>
  43. /// <param name="xdata">Stream.</param>
  44. /// <returns>true:Succeed; false:failed.</returns>
  45. bool SaveData(Stream xdata);
  46. /// <summary>
  47. /// Get parent node.
  48. /// </summary>
  49. Asn1Node ParentNode { get; }
  50. /// <summary>
  51. /// Add child node at the end of children list.
  52. /// </summary>
  53. /// <param name="xdata">Asn1Node</param>
  54. void AddChild(Asn1Node xdata);
  55. /// <summary>
  56. /// Insert a node in the children list before the pointed index.
  57. /// </summary>
  58. /// <param name="xdata">Asn1Node</param>
  59. /// <param name="index">0 based index.</param>
  60. int InsertChild(Asn1Node xdata, int index);
  61. /// <summary>
  62. /// Insert a node in the children list before the pointed node.
  63. /// </summary>
  64. /// <param name="xdata">Asn1Node that will be instered in the children list.</param>
  65. /// <param name="indexNode">Index node.</param>
  66. /// <returns>New node index.</returns>
  67. int InsertChild(Asn1Node xdata, Asn1Node indexNode);
  68. /// <summary>
  69. /// Insert a node in the children list after the pointed index.
  70. /// </summary>
  71. /// <param name="xdata">Asn1Node</param>
  72. /// <param name="index">0 based index.</param>
  73. /// <returns>New node index.</returns>
  74. int InsertChildAfter(Asn1Node xdata, int index);
  75. /// <summary>
  76. /// Insert a node in the children list after the pointed node.
  77. /// </summary>
  78. /// <param name="xdata">Asn1Node that will be instered in the children list.</param>
  79. /// <param name="indexNode">Index node.</param>
  80. /// <returns>New node index.</returns>
  81. int InsertChildAfter(Asn1Node xdata, Asn1Node indexNode);
  82. /// <summary>
  83. /// Remove a child from children node list by index.
  84. /// </summary>
  85. /// <param name="index">0 based index.</param>
  86. /// <returns>The Asn1Node just removed from the list.</returns>
  87. Asn1Node RemoveChild(int index);
  88. /// <summary>
  89. /// Remove the child from children node list.
  90. /// </summary>
  91. /// <param name="node">The node needs to be removed.</param>
  92. /// <returns></returns>
  93. Asn1Node RemoveChild(Asn1Node node);
  94. /// <summary>
  95. /// Get child node count.
  96. /// </summary>
  97. long ChildNodeCount { get; }
  98. /// <summary>
  99. /// Retrieve child node by index.
  100. /// </summary>
  101. /// <param name="index">0 based index.</param>
  102. /// <returns>0 based index.</returns>
  103. Asn1Node GetChildNode(int index);
  104. /// <summary>
  105. /// Get descendant node by node path.
  106. /// </summary>
  107. /// <param name="nodePath">relative node path that refer to current node.</param>
  108. /// <returns></returns>
  109. Asn1Node GetDescendantNodeByPath(string nodePath);
  110. /// <summary>
  111. /// Get/Set tag value.
  112. /// </summary>
  113. byte Tag { get; set; }
  114. byte MaskedTag { get; }
  115. /// <summary>
  116. /// Get tag name.
  117. /// </summary>
  118. string TagName { get; }
  119. /// <summary>
  120. /// Get data length. Not included the unused bits byte for BITSTRING.
  121. /// </summary>
  122. long DataLength { get; }
  123. /// <summary>
  124. /// Get the length field bytes.
  125. /// </summary>
  126. long LengthFieldBytes { get; }
  127. /// <summary>
  128. /// Get data offset.
  129. /// </summary>
  130. long DataOffset { get; }
  131. /// <summary>
  132. /// Get unused bits for BITSTRING.
  133. /// </summary>
  134. byte UnusedBits { get; }
  135. /// <summary>
  136. /// Get/Set node data by byte[], the data length field content and all the
  137. /// node in the parent chain will be adjusted.
  138. /// </summary>
  139. byte[] Data { get; set; }
  140. /// <summary>
  141. /// Get/Set parseEncapsulatedData. This property will be inherited by the
  142. /// child nodes when loading data.
  143. /// </summary>
  144. bool ParseEncapsulatedData { get; set; }
  145. /// <summary>
  146. /// Get the deepness of the node.
  147. /// </summary>
  148. long Deepness { get; }
  149. /// <summary>
  150. /// Get the path string of the node.
  151. /// </summary>
  152. string Path { get; }
  153. /// <summary>
  154. /// Get the node and all the descendents text description.
  155. /// </summary>
  156. /// <param name="startNode">starting node.</param>
  157. /// <param name="lineLen">line length.</param>
  158. /// <returns></returns>
  159. string GetText(Asn1Node startNode, int lineLen);
  160. /// <summary>
  161. /// Retrieve the node description.
  162. /// </summary>
  163. /// <param name="pureHexMode">true:Return hex string only;
  164. /// false:Convert to more readable string depending on the node tag.</param>
  165. /// <returns>string</returns>
  166. string GetDataStr(bool pureHexMode);
  167. /// <summary>
  168. /// Get node label string.
  169. /// </summary>
  170. /// <param name="mask">
  171. /// <code>
  172. /// SHOW_OFFSET
  173. /// SHOW_DATA
  174. /// USE_HEX_OFFSET
  175. /// SHOW_TAG_NUMBER
  176. /// SHOW_PATH</code>
  177. /// </param>
  178. /// <returns>string</returns>
  179. string GetLabel(uint mask);
  180. /// <summary>
  181. /// Clone a new Asn1Node by current node.
  182. /// </summary>
  183. /// <returns>new node.</returns>
  184. Asn1Node Clone();
  185. /// <summary>
  186. /// Clear data and children list.
  187. /// </summary>
  188. void ClearAll();
  189. }
  190. }