コード例 #1
0
        public static Asn1Node Paste()
        {
            DataFormats.GetFormat(Asn1ClipboardData.asn1FormatName);
            Asn1Node    asn1Node1  = new Asn1Node();
            IDataObject dataObject = Clipboard.GetDataObject();

            byte[] data1 = (byte[])dataObject.GetData(Asn1ClipboardData.asn1FormatName);
            if (data1 != null)
            {
                MemoryStream memoryStream = new MemoryStream(data1);
                memoryStream.Position = 0L;
                asn1Node1.LoadData((Stream)memoryStream);
            }
            else
            {
                string   data2     = (string)dataObject.GetData(DataFormats.Text);
                Asn1Node asn1Node2 = new Asn1Node();
                if (Asn1Util.IsAsn1EncodedHexStr(data2))
                {
                    byte[] bytes = Asn1Util.HexStrToBytes(data2);
                    asn1Node1.LoadData(bytes);
                }
            }
            return(asn1Node1);
        }
コード例 #2
0
        /// <summary>
        /// Paste clipboard data as an Asn1Node. It try to get data from
        /// Asn1NodeDataFormat first, then try Text data format.
        /// </summary>
        /// <returns>Asn1Node</returns>
        public static Asn1Node Paste()
        {
            DataFormats.Format asn1Format   = DataFormats.GetFormat(asn1FormatName);
            Asn1Node           retval       = new Asn1Node();
            IDataObject        aRetrieveObj = Clipboard.GetDataObject();

            byte[] aData = (byte[])aRetrieveObj.GetData(asn1FormatName);
            if (aData != null)
            {
                MemoryStream ms = new MemoryStream(aData);
                ms.Position = 0;
                retval.LoadData(ms);
            }
            else
            {
                string   dataStr = (string)aRetrieveObj.GetData(DataFormats.Text);
                Asn1Node tmpNode = new Asn1Node();
                if (Asn1Util.IsAsn1EncodedHexStr(dataStr))
                {
                    byte[] data = Asn1Util.HexStrToBytes(dataStr);
                    retval.LoadData(data);
                }
            }
            return(retval);
        }
コード例 #3
0
 /// <summary>
 /// Load ASN.1 encoded data from Stream.
 /// </summary>
 /// <param name="stream">Stream data.</param>
 public void LoadData(Stream stream)
 {
     stream.Position = 0;
     if (!rootNode.LoadData(stream))
     {
         throw new ArgumentException("Failed to load data.");
     }
     rawData         = new byte[stream.Length];
     stream.Position = 0;
     stream.Read(rawData, 0, rawData.Length);
 }
コード例 #4
0
        public Asn1Node Clone()
        {
            MemoryStream memoryStream = new MemoryStream();

            this.SaveData((Stream)memoryStream);
            memoryStream.Position = 0L;
            Asn1Node asn1Node = new Asn1Node();

            asn1Node.LoadData((Stream)memoryStream);
            return(asn1Node);
        }
コード例 #5
0
ファイル: Asn1Util.cs プロジェクト: josecohenca/xmlconvertsql
 /// <summary>
 /// Check if the string is ASN.1 encoded hex string.
 /// </summary>
 /// <param name="dataStr">The string.</param>
 /// <returns>true:Yes, false:No.</returns>
 public static bool IsAsn1EncodedHexStr(string dataStr)
 {
     bool retval = false;
     try
     {
         byte[] data = HexStrToBytes(dataStr);
         if (data.Length > 0)
         {
             Asn1Node node = new Asn1Node();
             retval = node.LoadData(data);
         }
     }
     catch
     {
         retval = false;
     }
     return retval;
 }
コード例 #6
0
        /// <summary>
        /// Check if the string is ASN.1 encoded hex string.
        /// </summary>
        /// <param name="dataStr">The string.</param>
        /// <returns>true:Yes, false:No.</returns>
        public static bool IsAsn1EncodedHexStr(string dataStr)
        {
            bool retval = false;

            try
            {
                byte[] data = HexStrToBytes(dataStr);
                if (data.Length > 0)
                {
                    Asn1Node node = new Asn1Node();
                    retval = node.LoadData(data);
                }
            }
            catch
            {
                retval = false;
            }
            return(retval);
        }
コード例 #7
0
ファイル: Asn1Parser.cs プロジェクト: Vutik/asn1editor
        /// <summary>
        /// Load ASN.1 encoded data from Stream.
        /// </summary>
        /// <param name="stream">Stream data.</param>
        public void LoadData(Stream stream)
        {
            rootNodes.Clear();

            stream.Position = 0;

            while (stream.Position < stream.Length - 1)
            {
                Asn1Node rootNode = new Asn1Node(stream.Position);

                if (!rootNode.LoadData(stream))
                {
                    throw new Exception("Failed to load data.");
                }
                rootNodes.Add(rootNode);
            }
            rawData         = new byte[stream.Length];
            stream.Position = 0;
            stream.Read(rawData, 0, rawData.Length);
        }
コード例 #8
0
ファイル: Asn1Node.cs プロジェクト: josecohenca/xmlconvertsql
 /// <summary>
 /// Clone a new Asn1Node by current node.
 /// </summary>
 /// <returns>new node.</returns>
 public Asn1Node Clone()
 {
     MemoryStream ms = new MemoryStream();
     this.SaveData(ms);
     ms.Position = 0;
     Asn1Node node = new Asn1Node();
     node.LoadData(ms);
     return node;
 }
コード例 #9
0
 /// <summary>
 /// Paste clipboard data as an Asn1Node. It try to get data from 
 /// Asn1NodeDataFormat first, then try Text data format.
 /// </summary>
 /// <returns>Asn1Node</returns>
 public static Asn1Node Paste()
 {
     DataFormats.Format asn1Format = DataFormats.GetFormat(asn1FormatName);
     Asn1Node retval = new Asn1Node();
     IDataObject aRetrieveObj = Clipboard.GetDataObject();
     byte[] aData = (byte[]) aRetrieveObj.GetData(asn1FormatName);
     if (aData != null)
     {
         MemoryStream ms = new MemoryStream(aData);
         ms.Position = 0;
         retval.LoadData(ms);
     }
     else
     {
         string dataStr = (string) aRetrieveObj.GetData(DataFormats.Text);
         Asn1Node tmpNode = new Asn1Node();
         if (Asn1Util.IsAsn1EncodedHexStr(dataStr))
         {
             byte[] data = Asn1Util.HexStrToBytes(dataStr);
             retval.LoadData(data);
         }
     }
     return retval;
 }