Exemple #1
0
 public SmartTag(List <byte> tagname, int dataLen, List <byte> tagValue, string tagDescript, SmartTag parent = null)
 {
     Tagname     = tagname;
     DataLen     = dataLen;
     TagValue    = tagValue;
     Description = tagDescript;
     Parent      = parent;
 }
Exemple #2
0
        internal List <SmartTag> parsetlv(byte[] data, SmartTag parent = null)
        {
            List <SmartTag> tags  = new List <SmartTag>();
            int             index = 0;

            while (index < data.Length)
            {
                var temptag  = new List <byte>();
                var tagValue = new List <byte>();
                var tagLen   = 0;

                //Get the tag name
                temptag.Add(data[index]);
                if ((data[index] & EmvConstants.SeeSubsequentBytes) == EmvConstants.SeeSubsequentBytes)
                {
                    index++;
                    temptag.Add(data[index]);
                }
                Console.WriteLine("EmvTag " + StringTools.ByteArrayToHexString(temptag.ToArray()));
                index++;

                // Get the length of the data to follow

                if ((data[index] & 0x80) == 0x80)
                {
                    int bytesForLenght = data[index] % 0x80;
                    index++;
                    for (int i = 0; i < bytesForLenght; i++)
                    {
                        tagLen += data[index];
                        index++;
                    }
                }
                else
                {
                    tagLen = data[index];
                    index++;
                }

                // Get the value of the tag
                for (int i = 0; i < tagLen; i++)
                {
                    try
                    {
                        tagValue.Add(data[index]);
                        index++;
                    }
                    catch (Exception)
                    {
                        i = tagLen;
                    }
                }
                string   tagDesc  = EmvConstants.getTagDescription(StringTools.ByteArrayToHexString(temptag.ToArray()).ToLower());
                SmartTag smarttag = new SmartTag(temptag, tagLen, tagValue, tagDesc, parent);

                tags.Add(smarttag);
                if (smarttag.IsConstructed)
                {
                    smarttag.Children = parsetlv(smarttag.TagValue.ToArray(), smarttag);
                }
                TagList.Add(smarttag);
            }
            return(tags);
        }