Exemple #1
0
        /// <summary>
        /// Save node data into Stream.
        /// </summary>
        /// <param name="xdata">Stream.</param>
        /// <returns>true:Succeed; false:failed.</returns>
        public bool SaveData(Stream xdata)
        {
            bool retval    = true;
            long nodeCount = ChildNodeCount;

            xdata.WriteByte(tag);
            int tmpLen = Asn1Util.DERLengthEncode(xdata, (ulong)dataLength);

            if ((tag) == Asn1Tag.BIT_STRING)
            {
                xdata.WriteByte(unusedBits);
            }
            if (nodeCount == 0)
            {
                if (data != null)
                {
                    xdata.Write(data, 0, data.Length);
                }
            }
            else
            {
                Asn1Node tempNode;
                int      i;
                for (i = 0; i < nodeCount; i++)
                {
                    tempNode = GetChildNode(i);
                    retval   = tempNode.SaveData(xdata);
                }
            }
            return(retval);
        }
Exemple #2
0
        /// <summary>
        /// Encode the node data length field and set lengthFieldBytes and dataLength.
        /// </summary>
        /// <param name="node">The node needs to be reset.</param>
        protected static void ResetDataLengthFieldWidth(Asn1Node node)
        {
            MemoryStream tempStream = new MemoryStream();

            Asn1Util.DERLengthEncode(tempStream, (ulong)node.dataLength);
            node.lengthFieldBytes = tempStream.Length;
            tempStream.Close();
        }