Exemple #1
0
 internal void AddRemovedTag(TlvData tagData)
 {
     removedTags[tagData.GetTag()] = tagData;
 }
Exemple #2
0
        public static EmvData ParseTagData(string tagData, bool verbose)
        {
            tagData = tagData.ToUpper();

            EmvData rvalue = new EmvData();

            for (int i = 0; i < tagData.Length;)
            {
                try {
                    string tagName = tagData.Substring(i, 2);
                    i = i + 2;
                    if ((Convert.ToInt32(tagName, 16) & 0x1F) == 0x1F)
                    {
                        tagName += tagData.Substring(i, 2);
                        i        = i + 2;
                    }

                    string lengthStr = tagData.Substring(i, 2);
                    i = i + 2;
                    int length = Convert.ToInt32(lengthStr, 16);
                    if (length > 127)
                    {
                        int bytesLength = length - 128;
                        lengthStr = tagData.Substring(i, bytesLength * 2);
                        i         = i + (bytesLength * 2);
                        length    = Convert.ToInt32(lengthStr, 16);
                    }
                    length *= 2;

                    string value = tagData.Substring(i, length);
                    i = i + length;

                    if (!blackList.ContainsKey(tagName))
                    {
                        TlvData approvedTag = new TlvData(tagName, lengthStr, value, knownTags[tagName]);
                        if (tagName.Equals("5F28") && !value.Equals("840"))
                        {
                            rvalue.SetStandInStatus(false, "Card is not domestically issued");
                        }
                        else if (tagName.Equals("95"))
                        {
                            byte[] valueBuffer = StringUtils.BytesFromHex(value);
                            byte[] maskBuffer  = StringUtils.BytesFromHex("FC50FC2000");

                            for (int idx = 0; idx < valueBuffer.Length; idx++)
                            {
                                if ((valueBuffer[idx] & maskBuffer[idx]) != 0x00)
                                {
                                    rvalue.SetStandInStatus(false, string.Format("Invalid TVR status in byte {0} of tag 95", idx + 1));
                                }
                            }
                        }
                        else if (tagName.Equals("9B"))
                        {
                            byte[] valueBuffer = StringUtils.BytesFromHex(value);
                            byte[] maskBuffer  = StringUtils.BytesFromHex("E800");

                            for (int idx = 0; idx < valueBuffer.Length; idx++)
                            {
                                if ((valueBuffer[idx] & maskBuffer[idx]) != maskBuffer[idx])
                                {
                                    rvalue.SetStandInStatus(false, string.Format("Invalid TSI status in byte {0} of tag 9B", idx + 1));
                                }
                            }
                        }
                        rvalue.AddTag(approvedTag);
                    }
                    else
                    {
                        rvalue.AddRemovedTag(tagName, lengthStr, value, blackList[tagName]);
                    }
                }
                catch (FormatException) { }
                catch (IndexOutOfRangeException) { }
            }
            if (verbose)
            {
                Console.WriteLine("Accepted Tags:");
                foreach (string tagName in rvalue.GetAcceptedTags().Keys)
                {
                    TlvData tag          = rvalue.GetTag(tagName);
                    bool    appendBinary = dataTypes.ContainsKey(tagName);
                    Console.WriteLine(string.Format("TAG: {0} - {1}", tagName, tag.GetDescription()));
                    Console.WriteLine(string.Format("{0}: {1}{2}\r\n", tag.GetLength(), tag.GetValue(), appendBinary ? string.Format(" [{0}]", tag.GetBinaryValue()) : ""));
                }
                Console.WriteLine("Removed Tags:");
                foreach (string tagName in rvalue.GetRemovedTags().Keys)
                {
                    TlvData tag = rvalue.GetRemovedTags()[tagName];
                    Console.WriteLine(string.Format("TAG: {0} - {1}", tagName, tag.GetDescription()));
                    Console.WriteLine(string.Format("{0}: {1}\r\n", tag.GetLength(), tag.GetValue()));
                }
            }
            return(rvalue);
        }
Exemple #3
0
 internal void AddTag(TlvData tagData)
 {
     tlvData[tagData.GetTag()] = tagData;
 }