Example #1
0
        public string ConvertToString(byte[] data)
        {
            switch (Format)
            {
            //case DataFormats.UNKNOWN:
            //case DataFormats.VARIABLE_UNKNOWN:
            case DataFormats._BINARY:
            case DataFormats._BINARY_16:
                //case DataFormats._BINARY_MULTIPLE_OF_4:
                //case DataFormats.H:
                //case DataFormats.A:
                return(Formatting.ByteArrayToHexString(data));

            case DataFormats._CN:
            case DataFormats._DATE_YYMMDD:
            case DataFormats._TIME_HHMMSS:
            case DataFormats._NUMERIC:
                return(Formatting.BcdToString(data));

            case DataFormats._ALPHA:
            case DataFormats._ALPHA_NUMERIC:
            case DataFormats._ALPHA_NUMERIC_SPECIAL:
            case DataFormats._ALPHA_NUMERIC_SPACE:
                return(Formatting.ByteArrayToASCIIString(data));

            default:
                throw new Exception("Unknown DataFormat:" + Format);
            }
        }
Example #2
0
        private String unpackKeyData(byte[] data)
        {
            StringBuilder sb = new StringBuilder();

            TLVList tlvList = new TLVList();

            tlvList.Deserialize(data);
            sb.AppendLine("Card Data");
            try
            {
                String oidVersion = Formatting.ByteArrayToASCIIString(tlvList.Get("66").Children.Get("73").Children.Get("06").Value);
                String version    = Formatting.ByteArrayToASCIIString(tlvList.Get("66").Children.Get("73").Children.Get("60").Children.Get("06").Value);
                String tag3       = Formatting.ByteArrayToASCIIString(tlvList.Get("66").Children.Get("73").Children.Get("63").Children.Get("06").Value);
                String scpVersion = Formatting.ByteArrayToASCIIString(tlvList.Get("66").Children.Get("73").Children.Get("64").Children.Get("06").Value);
                String tag5       = Formatting.ByteArrayToASCIIString(tlvList.Get("66").Children.Get("73").Children.Get("65").Children.Get("06").Value);
                String tag6       = Formatting.ByteArrayToASCIIString(tlvList.Get("66").Children.Get("73").Children.Get("66").Children.Get("06").Value);

                sb.AppendLine("OID Version:" + oidVersion);
                sb.AppendLine("Version:" + version);
                sb.AppendLine("Tag3:" + tag3);
                sb.AppendLine("SCP Version:" + scpVersion);
                sb.AppendLine("Tag5:" + tag5);
                sb.AppendLine("Tag6:" + tag6);
            }
            catch (Exception ex)
            {
                sb.AppendLine("Error Parsing Data:" + ex.Message);
            }

            return(sb.ToString());
        }
Example #3
0
        private static SignalsEnum EntryPointPIN(KernelDatabase database, KernelRequest kernel1Request, CardQ cardQManager)
        {
            CARDHOLDER_VERIFICATION_METHOD_CVM_RESULTS_9F34_KRN cvr = new CARDHOLDER_VERIFICATION_METHOD_CVM_RESULTS_9F34_KRN(database);
            TERMINAL_VERIFICATION_RESULTS_95_KRN tvr = new TERMINAL_VERIFICATION_RESULTS_95_KRN(database);

            //store the pin
            database.AddToList(kernel1Request.InputData.Get(EMVTagsEnum.TRANSACTION_PERSONAL_IDENTIFICATION_NUMBER_PIN_DATA_99_KRN.Tag));
            string pin = Formatting.ByteArrayToASCIIString(database.Get(EMVTagsEnum.TRANSACTION_PERSONAL_IDENTIFICATION_NUMBER_PIN_DATA_99_KRN.Tag).Value);

            //online pin
            if (cvr.Value.GetCVMPerformed() == CVMCode.EncipheredPINVerifiedOnline)
            {
                PinProcessing.VerifyOnlinePin(pin, tvr, cvr);
                return(SignalsEnum.WAITING_FOR_CVM_PROCESSING);
            }

            //offline pin
            if (cvr.Value.GetCVMPerformed() == CVMCode.EncipheredPINVerificationPerformedByICC ||
                cvr.Value.GetCVMPerformed() == CVMCode.EncipheredPINVerificationPerformedByICCAndSignature_Paper ||
                cvr.Value.GetCVMPerformed() == CVMCode.PlaintextPINVerificationPerformedByICC ||
                cvr.Value.GetCVMPerformed() == CVMCode.PlaintextPINVerificationPerformedByICCAndSignature_Paper)
            {
                EMVGetDataRequest request = new EMVGetDataRequest(Formatting.HexStringToByteArray(EMVTagsEnum.PERSONAL_IDENTIFICATION_NUMBER_PIN_TRY_COUNTER_9F17_KRN.Tag));
                cardQManager.EnqueueToInput(new CardRequest(request, CardinterfaceServiceRequestEnum.ADPU));
                return(SignalsEnum.WAITING_FOR_GET_PIN_TRY_COUNTER);
            }

            throw new EMVProtocolException("Invalid cvr in State_5a_WaitingForGetPinReponse");
        }
        private static SignalsEnum EntryPointRA(KernelDatabase database, CardResponse cardResponse, KernelQ qManager, CardQ cardQManager, Stopwatch sw)
        {
            CARDHOLDER_VERIFICATION_METHOD_CVM_RESULTS_9F34_KRN cvr = new CARDHOLDER_VERIFICATION_METHOD_CVM_RESULTS_9F34_KRN(database);

            EMVGetDataResponse response = (EMVGetDataResponse)cardResponse.ApduResponse;

            if (!response.Succeeded)
            {
                cvr.Value.CVMResult = 0x01;//failed
                cvr.UpdateDB();
                return(SignalsEnum.WAITING_FOR_CVM_PROCESSING);
            }

            //store the pin try counter value
            database.AddToList(response.GetResponseTag());
            int pinTryCounter = Formatting.ConvertToInt16(database.Get(EMVTagsEnum.PERSONAL_IDENTIFICATION_NUMBER_PIN_TRY_COUNTER_9F17_KRN).Value);

            TERMINAL_VERIFICATION_RESULTS_95_KRN tvr = new TERMINAL_VERIFICATION_RESULTS_95_KRN(database);

            if (cvr.Value.GetCVMPerformed() == CVMCode.EncipheredPINVerificationPerformedByICC ||
                cvr.Value.GetCVMPerformed() == CVMCode.EncipheredPINVerificationPerformedByICCAndSignature_Paper)
            {
                string pin = Formatting.ByteArrayToASCIIString(database.Get(EMVTagsEnum.TRANSACTION_PERSONAL_IDENTIFICATION_NUMBER_PIN_DATA_99_KRN.Tag).Value);
                if (!PinProcessing.VerifyOfflinePin(pin, pinTryCounter, tvr, cvr))
                {
                    return(SignalsEnum.WAITING_FOR_CVM_PROCESSING);
                }
                //fire off get challenge command
                EMVGetChallengeRequest request = new EMVGetChallengeRequest();
                cardQManager.EnqueueToInput(new CardRequest(request, CardinterfaceServiceRequestEnum.ADPU));
                return(SignalsEnum.WAITING_FOR_GET_CHALLENGE);
            }

            if (cvr.Value.GetCVMPerformed() == CVMCode.PlaintextPINVerificationPerformedByICC ||
                cvr.Value.GetCVMPerformed() == CVMCode.PlaintextPINVerificationPerformedByICCAndSignature_Paper)
            {
                string pin = Formatting.ByteArrayToASCIIString(database.Get(EMVTagsEnum.TRANSACTION_PERSONAL_IDENTIFICATION_NUMBER_PIN_DATA_99_KRN.Tag).Value);
                if (!PinProcessing.VerifyOfflinePin(pin, pinTryCounter, tvr, cvr))
                {
                    return(SignalsEnum.WAITING_FOR_CVM_PROCESSING);
                }

                byte[] pinData = PinProcessing.BuildPlainTextPinBlock(pin);

                //fire off verify for plain text pin
                EMVVerifyRequest request = new EMVVerifyRequest(VerifyCommandDataQualifier.Plaintext_PIN, pinData);
                cardQManager.EnqueueToInput(new CardRequest(request, CardinterfaceServiceRequestEnum.ADPU));

                return(SignalsEnum.WAITING_FOR_VERIFY);
            }

            throw new EMVProtocolException("Invalid cvr in State_5b_WaitingForGetPinTryCounter");
        }
Example #5
0
        public static string Serialize(T input)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(T));
            MemoryStream  stream     = new MemoryStream();
            string        result;

            using (stream)
            {
                serializer.Serialize(stream, input);
                result = Formatting.ByteArrayToASCIIString(stream.ToArray());
            }
            return(result);
        }
Example #6
0
        private static SignalsEnum EntryPointRA(KernelDatabase database, CardResponse cardResponse, KernelQ qManager, CardQ cardQManager, PublicKeyCertificateManager pkcm, EMVSelectApplicationResponse emvSelectApplicationResponse, Stopwatch sw)
        {
            CARDHOLDER_VERIFICATION_METHOD_CVM_RESULTS_9F34_KRN cvr = new CARDHOLDER_VERIFICATION_METHOD_CVM_RESULTS_9F34_KRN(database);

            EMVGetChallengeResponse response = (EMVGetChallengeResponse)cardResponse.ApduResponse;

            if (!response.Succeeded)
            {
                cvr.Value.CVMResult = 0x01;//failed
                cvr.UpdateDB();
                return(SignalsEnum.WAITING_FOR_CVM_PROCESSING);
            }

            //store the challenge
            byte[] pinChallenge = response.ResponseData;

            if (cvr.Value.GetCVMPerformed() == CVMCode.EncipheredPINVerificationPerformedByICC ||
                cvr.Value.GetCVMPerformed() == CVMCode.EncipheredPINVerificationPerformedByICCAndSignature_Paper)
            {
                string  aid                 = emvSelectApplicationResponse.GetDFName();
                string  rid                 = aid.Substring(0, 10);
                RIDEnum ridEnum             = (RIDEnum)Enum.Parse(typeof(RIDEnum), rid);
                CAPublicKeyCertificate capk = pkcm.GetCAPK(ridEnum, database.Get(EMVTagsEnum.CERTIFICATION_AUTHORITY_PUBLIC_KEY_INDEX_8F_KRN).Value[0]);
                if (capk == null)
                {
                    cvr.Value.CVMResult = 0x01;//failed
                    cvr.UpdateDB();
                    return(SignalsEnum.WAITING_FOR_CVM_PROCESSING);
                }

                string pin      = Formatting.ByteArrayToASCIIString(database.Get(EMVTagsEnum.TRANSACTION_PERSONAL_IDENTIFICATION_NUMBER_PIN_DATA_99_KRN.Tag).Value);
                byte[] pinBlock = PinProcessing.BuildPlainTextPinBlock(pin);

                //encrypt the pin
                byte[] encipheredPin = PinProcessing.BuildPinVerifyData(database, capk, pinBlock, pinChallenge);
                if (encipheredPin == null)
                {
                    cvr.Value.CVMResult = 0x01;//failed
                    cvr.UpdateDB();
                    return(SignalsEnum.WAITING_FOR_CVM_PROCESSING);
                }

                //fire off verify for enciphered pin
                EMVVerifyRequest request = new EMVVerifyRequest(VerifyCommandDataQualifier.Enciphered_PIN, encipheredPin);
                cardQManager.EnqueueToInput(new CardRequest(request, CardinterfaceServiceRequestEnum.ADPU));
            }


            //verify message for plain text pin fired in waiting for pin response
            return(SignalsEnum.WAITING_FOR_VERIFY);
        }
Example #7
0
        private static byte[] Receive(TCPClientStream stream)
        {
            byte chrSTX = 0x02; // Start of Text
            byte chrETX = 0x03; // End of Text

            byte[] rxBuffer       = new Byte[4096];
            int    countBytesRead = stream.Read(rxBuffer);

            byte[] lengthBytesReceived = new byte[2];
            Array.Copy(rxBuffer, 0, lengthBytesReceived, 0, lengthBytesReceived.Length);

            int bytesInRxPacket = Formatting.ConvertToInt16(lengthBytesReceived);

            if (bytesInRxPacket + 2 != countBytesRead)
            {
                throw new TCPIPManagerException("Did not receive all expected bytes");
            }

            byte[] result = new byte[bytesInRxPacket];
            Array.Copy(rxBuffer, 2, result, 0, result.Length);

            bool hasSTX = false;
            bool hasETX = false;

            if (result.First() == chrSTX)
            {
                byte[] strippedSTX = new byte[result.Length - 1];
                Array.Copy(result, 1, strippedSTX, 0, strippedSTX.Length);
                result = strippedSTX;
                hasSTX = true;
            }
            int lastPos = Array.FindIndex(result, 0, (x) => x == chrETX);

            if (lastPos != -1)
            {
                int    lengthToCopy = result.Length - (result.Length - lastPos);
                byte[] strippedETX  = new byte[lengthToCopy];
                Array.Copy(result, 0, strippedETX, 0, strippedETX.Length);
                result = strippedETX;
                hasETX = true;
            }

            Logger.Log("Received:[" + countBytesRead + "]" +
                       (hasSTX == true? "[" + Formatting.ByteArrayToHexString(new byte[] { chrSTX }) + "]": "[No STX]") +
                       "[" + Formatting.ByteArrayToASCIIString(result) + "]" +
                       (hasETX == true ? "[" + Formatting.ByteArrayToHexString(new byte[] { chrETX }) + "]": "[No ETX]"));

            return(result);
        }
        private static Optional <Tuple <TerminalSupportedKernelAidTransactionTypeCombination, CardKernelAidCombination> > AskCardHolderToSelect(List <Tuple <TerminalSupportedKernelAidTransactionTypeCombination, CardKernelAidCombination> > candidateList, IUICallbackProvider uiProvider)
        {
            List <String> candidatesStrings = candidateList.Select(x => Formatting.ByteArrayToASCIIString(x.Item2.ApplicationLabel.Value) + ":" + Formatting.ByteArrayToHexString(x.Item2.AdfNameTag.Value)).ToList();
            String        selected          = uiProvider.DisplayApplicationList(candidatesStrings);

            if (!string.IsNullOrEmpty(selected))
            {
                Tuple <TerminalSupportedKernelAidTransactionTypeCombination, CardKernelAidCombination> selectedTuple =
                    candidateList.Where(x => Formatting.ByteArrayToHexString(x.Item2.AdfNameTag.Value) == selected).First();
                return(Optional <Tuple <TerminalSupportedKernelAidTransactionTypeCombination, CardKernelAidCombination> > .Create(selectedTuple));
            }
            else
            {
                return(Optional <Tuple <TerminalSupportedKernelAidTransactionTypeCombination, CardKernelAidCombination> > .CreateEmpty());
            }
        }
Example #9
0
            public override byte[] Serialize()
            {
                FormatCode     = 0x42;
                FieldSeperator = 0x5E;
                string output = Formatting.ByteArrayToASCIIString(new byte[] { FormatCode })
                                + PAN +
                                Formatting.ByteArrayToASCIIString(new byte[] { FieldSeperator }) +
                                Name +
                                Formatting.ByteArrayToASCIIString(new byte[] { FieldSeperator }) +
                                ExpirationDate +
                                ServiceCode +
                                Formatting.ByteArrayToASCIIString(DiscretionaryData);

                Value = Formatting.ASCIIStringToByteArray(output);
                return(base.Serialize());
            }
Example #10
0
            public override int Deserialize(byte[] rawTlv, int pos)
            {
                FieldSeperator = 0x5E;

                pos = base.Deserialize(rawTlv, pos);

                string input = Formatting.ByteArrayToASCIIString(Value);

                string[] inputs = input.Split(new string[] { Formatting.ByteArrayToASCIIString(new byte[] { FieldSeperator }) }, StringSplitOptions.None);
                PAN               = inputs[0].Substring(1);
                Name              = inputs[1];
                ExpirationDate    = inputs[2].Substring(0, 4);
                ServiceCode       = inputs[2].Substring(4, 3);
                DiscretionaryData = Formatting.ASCIIStringToByteArray(inputs[2].Substring(7, inputs[2].Length - 7));

                return(pos);
            }
Example #11
0
        private static void Transmit(TCPClientStream stream, byte[] txBytes)
        {
            byte chrSTX = 0x02; // Start of Text
            byte chrETX = 0x03; // End of Text
            //byte[] LRC;

            short length = (short)(txBytes.Length + 2);

            byte[] lengthBytes = new byte[] { (byte)(length / 256), (byte)(length % 256) };

            byte[] txBytesTCP = Formatting.ConcatArrays(lengthBytes, new byte[] { chrSTX }, txBytes, new byte[] { chrETX });

            Logger.Log("Sending: [" + Formatting.ConvertToInt16(lengthBytes) + "]" +
                       "[" + Formatting.ByteArrayToHexString(new byte[] { chrSTX }) + "]" +
                       "[" + Formatting.ByteArrayToASCIIString(txBytes) + "]" +
                       "[" + Formatting.ByteArrayToHexString(new byte[] { chrETX }) + "]");

            stream.Write(txBytesTCP);
        }
Example #12
0
        public static T Deserialize(string xml)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(T));
            MemoryStream  stream     = new MemoryStream();
            StreamWriter  writer     = new StreamWriter(stream);

            writer.Write(xml);
            writer.Flush();
            stream.Position = 0;
            using (stream)
            {
                Logger.Log(Formatting.ByteArrayToASCIIString(stream.ToArray()));
                return((T)serializer.Deserialize(stream));
            }

            //available in .net standard 2.0
            //    using (XmlReader schemaReader = XmlReader.Create("schema.xsd"))
            //    {
            //        XmlSchemaSet schemaSet = new XmlSchemaSet();

            //        //add the schema to the schema set
            //        schemaSet.Add(XmlSchema.Read(schemaReader,
            //        new ValidationEventHandler(
            //            delegate (Object sender, ValidationEventArgs e)
            //            {
            //            }
            //        )));

            //        //Load and validate against the programmatic schema set
            //        XmlDocument xmlDocument = new XmlDocument();
            //        xmlDocument.Schemas = schemaSet;
            //        xmlDocument.Load("something.xml");

            //        xmlDocument.Validate(new ValidationEventHandler(
            //            delegate (Object sender, ValidationEventArgs e)
            //            {
            //    //Report or respond to the error/warning
            //}
            //        ));
            //    }
        }
Example #13
0
 public override string ToString()
 {
     if (Children.Count == 0)
     {
         return(string.Format("[{0,-50}][{1}:{2}] V:[{3}]", FidMeta.Description, Id, SubId, Formatting.ByteArrayToASCIIString(Value)));
     }
     else
     {
         return(string.Format("[{0,-50}][{1}] V:[Child Count={2}]", "Parent", Id, Children.Count));
     }
 }
Example #14
0
        /*
         * 14.6
         */
        private static SignalsEnum EntryPointRA(Kernel2Database database, CardResponse cardResponse, KernelQ qManager, CardQ cardQManager, TornTransactionLogManager tornTransactionLogManager, Stopwatch sw, PublicKeyCertificateManager publicKeyCertificateManager)
        {
            #region 14.9
            if (!cardResponse.ApduResponse.Succeeded)
            #endregion
            {
                #region 14.10
                CommonRoutines.UpdateErrorIndication(database, cardResponse, L1Enum.NOT_SET, L2Enum.STATUS_BYTES, L3Enum.NOT_SET);
                return(DoInvalidResponse(database, qManager));

                #endregion
            }

            #region 14.11
            bool parsingResult = false;
            if (cardResponse.ApduResponse.ResponseData.Length > 0 && cardResponse.ApduResponse.ResponseData[0] == 0x77)
            {
                EMVComputeCryptographicChecksumResponse response = cardResponse.ApduResponse as EMVComputeCryptographicChecksumResponse;
                parsingResult = database.ParseAndStoreCardResponse(response.ResponseData);
            }
            else
            {
                parsingResult = false;
            }
            #endregion

            #region 14.12
            if (!parsingResult)
            #endregion
            {
                #region 14.13
                CommonRoutines.UpdateErrorIndication(database, cardResponse, L1Enum.NOT_SET, L2Enum.PARSING_ERROR, L3Enum.NOT_SET);
                return(DoInvalidResponse(database, qManager));

                #endregion
            }

            #region 14.12.1
            CommonRoutines.PostUIOnly(database, qManager, KernelMessageidentifierEnum.CLEAR_DISPLAY, KernelStatusEnum.CARD_READ_SUCCESSFULLY, true);
            #endregion

            #region 14.14
            if (database.IsEmpty(EMVTagsEnum.APPLICATION_TRANSACTION_COUNTER_ATC_9F36_KRN.Tag) ||
                database.IsEmpty(EMVTagsEnum.POS_CARDHOLDER_INTERACTION_INFORMATION_DF4B_KRN2.Tag))
            #endregion
            {
                #region 14.17
                CommonRoutines.UpdateErrorIndication(database, cardResponse, L1Enum.NOT_SET, L2Enum.CARD_DATA_MISSING, L3Enum.NOT_SET);
                return(DoInvalidResponse(database, qManager));

                #endregion
            }

            long nUN = 0;
            #region 14.15
            if (database.IsNotEmpty(EMVTagsEnum.CVC3_TRACK2_9F61_KRN2.Tag))
            #endregion
            {
                #region 14.16
                if (database.IsNotEmpty(EMVTagsEnum.TRACK_1_DATA_56_KRN2.Tag) &&
                    (database.IsNotPresent(EMVTagsEnum.CVC3_TRACK1_9F60_KRN2.Tag) ||
                     database.IsEmpty(EMVTagsEnum.CVC3_TRACK1_9F60_KRN2.Tag)))
                #endregion
                {
                    #region 14.17
                    CommonRoutines.UpdateErrorIndication(database, cardResponse, L1Enum.NOT_SET, L2Enum.CARD_DATA_MISSING, L3Enum.NOT_SET);
                    return(DoInvalidResponse(database, qManager));

                    #endregion
                }

                #region 14.20
                byte pcii = database.Get(EMVTagsEnum.POS_CARDHOLDER_INTERACTION_INFORMATION_DF4B_KRN2).Value[1];
                #endregion
                if ((pcii & 0x10) == 0x10)   //OD-CVM verification successful
                {
                    #region 14.24
                    nUN = (nUN + 5) % 10;
                    #endregion
                }
                else
                {
                    #region 14.21
                    long aa   = Formatting.BcdToLong(database.Get(EMVTagsEnum.AMOUNT_AUTHORISED_NUMERIC_9F02_KRN).Value);
                    long rctl = database.ReaderContactlessTransactionLismit;
                    if (aa > rctl)
                    #endregion
                    {
                        #region 14.21.1
                        CommonRoutines.UpdateErrorIndication(database, cardResponse, L1Enum.NOT_SET, L2Enum.CARD_DATA_ERROR, L3Enum.NOT_SET);
                        return(DoInvalidResponse(database, qManager));

                        #endregion
                    }
                    else
                    {
                        #region 14.25
                        nUN = (int)Formatting.ConvertToInt32(database.Get(EMVTagsEnum.UNPREDICTABLE_NUMBER_9F37_KRN).Value);
                        #endregion
                    }
                }

                #region 14.25.1
                database.FailedMSCntr = 0;
                #endregion

                #region 14.26
                TRACK_2_DATA_9F6B_KRN2 t2d = new TRACK_2_DATA_9F6B_KRN2(database);
                ushort t2 = Formatting.ConvertToInt16(database.Get(EMVTagsEnum.NATC_TRACK2_9F67_KRN2).Value);

                TLV       PCVC3_TRACK2_9F65_KRN2       = database.Get(EMVTagsEnum.PCVC3_TRACK2_9F65_KRN2);
                MagBitmap bitmapPCVC3_TRACK2_9F65_KRN2 = new MagBitmap(PCVC3_TRACK2_9F65_KRN2.Value);

                TLV    CVC3_TRACK2_9F61_KRN2 = database.Get(EMVTagsEnum.CVC3_TRACK2_9F61_KRN2);
                ushort cvc3T2AsShort         = Formatting.ConvertToInt16(CVC3_TRACK2_9F61_KRN2.Value.Reverse().ToArray());

                string q2LeastSigDigits = Convert.ToString(cvc3T2AsShort);
                q2LeastSigDigits            = q2LeastSigDigits.Substring(q2LeastSigDigits.Length - bitmapPCVC3_TRACK2_9F65_KRN2.NonZeroCount);
                t2d.Value.DiscretionaryData = Formatting.StringToBcd(bitmapPCVC3_TRACK2_9F65_KRN2.ReplaceValues(Formatting.BcdToString(t2d.Value.DiscretionaryData), q2LeastSigDigits, bitmapPCVC3_TRACK2_9F65_KRN2.NonZeroCount, true), false);

                TLV       PUNATC_TRACK2_9F66_KRN2       = database.Get(EMVTagsEnum.PUNATC_TRACK2_9F66_KRN2);
                MagBitmap bitmapPUNATC_TRACK2_9F66_KRN2 = new MagBitmap(PUNATC_TRACK2_9F66_KRN2.Value);
                uint      unpredInt    = Formatting.ConvertToInt32(database.Get(EMVTagsEnum.UNPREDICTABLE_NUMBER_NUMERIC_9F6A_KRN2).Value.Reverse().ToArray());
                string    unpredString = Convert.ToString(unpredInt);
                unpredString = unpredString.Substring(unpredString.Length - database.NUN);
                t2d.Value.DiscretionaryData = Formatting.StringToBcd(bitmapPUNATC_TRACK2_9F66_KRN2.ReplaceValues(Formatting.BcdToString(t2d.Value.DiscretionaryData), unpredString, database.NUN, true), false);

                if (t2 != 0)
                {
                    TLV    APPLICATION_TRANSACTION_COUNTER_ATC_9F36_KRN = database.Get(EMVTagsEnum.APPLICATION_TRANSACTION_COUNTER_ATC_9F36_KRN);
                    uint   atcAsShort = Formatting.ConvertToInt32(APPLICATION_TRANSACTION_COUNTER_ATC_9F36_KRN.Value.Reverse().ToArray());
                    string atcAsShortLeastSigDigits = Convert.ToString(atcAsShort);
                    atcAsShortLeastSigDigits    = atcAsShortLeastSigDigits.PadLeft(t2, '0').Substring(atcAsShortLeastSigDigits.Length - t2);
                    t2d.Value.DiscretionaryData = Formatting.StringToBcd(bitmapPUNATC_TRACK2_9F66_KRN2.ReplaceValues(Formatting.BcdToString(t2d.Value.DiscretionaryData), atcAsShortLeastSigDigits, t2, false), false);
                }
                #endregion

                #region 14.27
                StringBuilder dd = new StringBuilder(Formatting.BcdToString(t2d.Value.DiscretionaryData));
                dd[dd.Length - 1]           = Convert.ToString(nUN)[0];
                t2d.Value.DiscretionaryData = Formatting.StringToBcd(dd.ToString(), false);
                #endregion

                t2d.Serialize(); //reserialize in case the length of discretionary data changed
                t2d.UpdateDB();

                #region 14.28
                if (database.IsNotEmpty(EMVTagsEnum.TRACK_1_DATA_56_KRN2.Tag))
                #endregion
                {
                    #region 14.29
                    TRACK_1_DATA_56_KRN2 t1d = new TRACK_1_DATA_56_KRN2(database);
                    ushort t1 = Formatting.ConvertToInt16(database.Get(EMVTagsEnum.NATC_TRACK1_9F64_KRN2).Value);

                    TLV       PCVC3_TRACK1_9F62_KRN2       = database.Get(EMVTagsEnum.PCVC3_TRACK1_9F62_KRN2);
                    MagBitmap bitmapPCVC3_TRACK1_9F62_KRN2 = new MagBitmap(PCVC3_TRACK1_9F62_KRN2.Value);

                    TLV    CVC3_TRACK1_9F60_KRN2 = database.Get(EMVTagsEnum.CVC3_TRACK1_9F60_KRN2);
                    ushort cvc3T1AsShort         = Formatting.ConvertToInt16(CVC3_TRACK1_9F60_KRN2.Value.Reverse().ToArray());

                    string q1LeastSigDigits = Convert.ToString(cvc3T1AsShort);
                    q1LeastSigDigits            = q1LeastSigDigits.Substring(q1LeastSigDigits.Length - bitmapPCVC3_TRACK1_9F62_KRN2.NonZeroCount);
                    t1d.Value.DiscretionaryData = Formatting.ASCIIStringToByteArray(bitmapPCVC3_TRACK1_9F62_KRN2.ReplaceValues(Formatting.ByteArrayToASCIIString(t1d.Value.DiscretionaryData), q1LeastSigDigits, bitmapPCVC3_TRACK1_9F62_KRN2.NonZeroCount, true));

                    TLV       PUNATC_TRACK1_9F63_KRN2       = database.Get(EMVTagsEnum.PUNATC_TRACK1_9F63_KRN2);
                    MagBitmap bitmapPUNATC_TRACK1_9F63_KRN2 = new MagBitmap(PUNATC_TRACK1_9F63_KRN2.Value);
                    t1d.Value.DiscretionaryData = Formatting.ASCIIStringToByteArray(bitmapPUNATC_TRACK1_9F63_KRN2.ReplaceValues(Formatting.ByteArrayToASCIIString(t1d.Value.DiscretionaryData), unpredString, database.NUN, true));

                    if (t2 != 0)
                    {
                        TLV    APPLICATION_TRANSACTION_COUNTER_ATC_9F36_KRN = database.Get(EMVTagsEnum.APPLICATION_TRANSACTION_COUNTER_ATC_9F36_KRN);
                        uint   atcAsShort = Formatting.ConvertToInt32(APPLICATION_TRANSACTION_COUNTER_ATC_9F36_KRN.Value.Reverse().ToArray());
                        string atcAsShortLeastSigDigits = Convert.ToString(atcAsShort);
                        atcAsShortLeastSigDigits    = atcAsShortLeastSigDigits.PadLeft(t2, '0').Substring(atcAsShortLeastSigDigits.Length - t1);
                        t2d.Value.DiscretionaryData = Formatting.ASCIIStringToByteArray(bitmapPUNATC_TRACK1_9F63_KRN2.ReplaceValues(Formatting.ByteArrayToASCIIString(t1d.Value.DiscretionaryData), atcAsShortLeastSigDigits, t1, false));
                    }
                    #endregion

                    #region 14.30
                    StringBuilder dd1 = new StringBuilder(Formatting.ByteArrayToASCIIString(t1d.Value.DiscretionaryData));
                    dd1[dd1.Length - 1]         = Convert.ToString(nUN)[0];
                    t1d.Value.DiscretionaryData = Formatting.ASCIIStringToByteArray(dd1.ToString());
                    #endregion

                    t1d.Serialize(); //reserialize in case the length of discretionary data changed
                    t1d.UpdateDB();
                }

                #region 14.32
                Kernel2OutcomeStatusEnum k2OutcomeStatus = Kernel2OutcomeStatusEnum.ONLINE_REQUEST;
                KernelCVMEnum            cvmEnum         = KernelCVMEnum.N_A;
                bool receipt = false;

                pcii = database.Get(EMVTagsEnum.POS_CARDHOLDER_INTERACTION_INFORMATION_DF4B_KRN2).Value[1];
                if ((pcii & 0x10) == 0x10)   //OD-CVM verification successful
                #endregion
                {
                    #region 14.34
                    cvmEnum = KernelCVMEnum.CONFIRMATION_CODE_VERIFIED;
                    long aa   = Formatting.BcdToLong(database.Get(EMVTagsEnum.AMOUNT_AUTHORISED_NUMERIC_9F02_KRN).Value);
                    long rctl = database.ReaderContactlessTransactionLismit;
                    if (aa > rctl)
                    {
                        receipt = true;
                    }
                    #endregion
                }
                else
                {
                    #region 14.33
                    cvmEnum = KernelCVMEnum.NO_CVM;
                    #endregion
                }
                CommonRoutines.CreateMSDiscretionaryDataRecord(database);
                CommonRoutines.CreateMSDataRecord(database);
                return(CommonRoutines.PostOutcomeOnly(database, qManager, k2OutcomeStatus, cvmEnum, receipt));
            }
            else
            {
                #region 14.19.1
                if (((int)Formatting.ConvertToInt32(database.Get(EMVTagsEnum.POS_CARDHOLDER_INTERACTION_INFORMATION_DF4B_KRN2).Value) & 0x00030F) != 0x000000)
                #endregion
                {
                    KernelMessageidentifierEnum k2MessageIdentifier = KernelMessageidentifierEnum.DECLINED;
                    KernelStatusEnum            k2Status            = KernelStatusEnum.READY_TO_READ;
                    byte[] holdTime = new byte[] { 0x00, 0x00, 0x00 };

                    #region 14.22
                    PHONE_MESSAGE_TABLE_DF8131_KRN2 pmt = (PHONE_MESSAGE_TABLE_DF8131_KRN2)database.GetDefault(EMVTagsEnum.PHONE_MESSAGE_TABLE_DF8131_KRN2);
                    foreach (PhoneMessageTableEntry_DF8131 entry in pmt.Value.Entries)
                    {
                        int pcii     = (int)Formatting.ConvertToInt32(database.Get(EMVTagsEnum.POS_CARDHOLDER_INTERACTION_INFORMATION_DF4B_KRN2).Value);
                        int pciMask  = (int)Formatting.ConvertToInt32(entry.PCIIMask);
                        int pciValue = (int)Formatting.ConvertToInt32(entry.PCIIValue);
                        if ((pciMask & pcii) == pciValue)
                        {
                            k2MessageIdentifier = entry.MessageIdentifier;
                            k2Status            = entry.Status;
                            holdTime            = database.GetDefault(EMVTagsEnum.MESSAGE_HOLD_TIME_DF812D_KRN2).Value;
                            break;
                        }
                    }
                    #endregion

                    #region 14.21.1
                    int waitTime = ((2 ^ database.FailedMSCntr) * 300);
                    Task.Delay(TimeSpan.FromMilliseconds(waitTime)).Wait();
                    #endregion

                    #region 14.21.2
                    database.FailedMSCntr = Math.Min(database.FailedMSCntr + 1, 5);
                    #endregion

                    #region 14.23
                    CommonRoutines.CreateMSDiscretionaryDataRecord(database);
                    CommonRoutines.CreateMSDataRecord(database);

                    return(CommonRoutines.PostOutcome(database, qManager,
                                                      k2MessageIdentifier,
                                                      k2Status,
                                                      holdTime,
                                                      Kernel2OutcomeStatusEnum.END_APPLICATION,
                                                      Kernel2StartEnum.B,
                                                      false,
                                                      KernelMessageidentifierEnum.N_A,
                                                      L1Enum.NOT_SET,
                                                      null,
                                                      L2Enum.NOT_SET,
                                                      L3Enum.NOT_SET));

                    #endregion
                }
                else
                {
                    #region 14.19.2.1
                    int waitTime = ((2 ^ database.FailedMSCntr) * 300);
                    Task.Delay(TimeSpan.FromMilliseconds(waitTime)).Wait();
                    #endregion
                    #region 14.19.2.2
                    database.FailedMSCntr = Math.Min(database.FailedMSCntr + 1, 5);
                    #endregion

                    #region 14.19.3
                    CommonRoutines.CreateMSDiscretionaryDataRecord(database);
                    CommonRoutines.CreateMSDataRecord(database);

                    return(CommonRoutines.PostOutcome(database, qManager,
                                                      KernelMessageidentifierEnum.DECLINED,
                                                      KernelStatusEnum.NOT_READY,
                                                      database.GetDefault(EMVTagsEnum.MESSAGE_HOLD_TIME_DF812D_KRN2).Value,
                                                      Kernel2OutcomeStatusEnum.END_APPLICATION,
                                                      Kernel2StartEnum.N_A,
                                                      true,
                                                      KernelMessageidentifierEnum.N_A,
                                                      L1Enum.NOT_SET,
                                                      null,
                                                      L2Enum.NOT_SET,
                                                      L3Enum.NOT_SET));

                    #endregion
                }
            }
        }
Example #15
0
        public ApproverResponseBase DoAuth(ApproverRequestBase requestIn)
        {
            bool isMagStripe;
            EMVApproverRequest request = ((EMVApproverRequest)requestIn);
            TLV cryptogram             = request.EMV_Data.Children.Get(EMVTagsEnum.CRYPTOGRAM_INFORMATION_DATA_9F27_KRN.Tag);

            if (cryptogram != null)
            {
                isMagStripe = false;
            }
            else
            {
                isMagStripe = true;
            }

            TransactionTypeEnum tt = (TransactionTypeEnum)Formatting.GetEnum(typeof(TransactionTypeEnum), request.EMV_Data.Children.Get(EMVTagsEnum.TRANSACTION_TYPE_9C_KRN.Tag).Value[0]);

            TransactionBase np;

            switch (tt)
            {
            case TransactionTypeEnum.PurchaseGoodsAndServices:
                np = new F00_NormalPurchase();
                break;

            case TransactionTypeEnum.PurchaseWithCashback:
                np = new F08_PurchaseWithCashBack();
                break;

            case TransactionTypeEnum.Refund:
                np = new F12_MerchandiseReturnAdjustment();
                break;

            default:
                throw new Exception("Unimplemented TransactionTypeEnum:" + tt);
            }

            np.SetHeaderValues(SPDHTransactionCode.NormalPurchase, SPDHMessageType.FinancialTransaction, SPDHMessageSubType.Online, DateTime.Now, "300047", "");

            np.Fids.Add(new FID_B_Amount1(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.AMOUNT_AUTHORISED_NUMERIC_9F02_KRN.Tag).Value)));

            FIDBase fb_6 = new FIDBase('6', ' ', new byte[0]);

            np.Fids.Add(fb_6);

            if (tt == TransactionTypeEnum.PurchaseWithCashback || tt == TransactionTypeEnum.Refund)
            {
                np.Fids.Add(new FID_C_Amount2(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.AMOUNT_OTHER_NUMERIC_9F03_KRN.Tag).Value)));
            }
            if (isMagStripe)
            {
                np.Fids.Add(new FID_q_Track2_Customer(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.TRACK_2_DATA_9F6B_KRN2.Tag).Value)));
                fb_6.Children.Add(new FID_6_I_TransactionCurrencyCode(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.TRANSACTION_CURRENCY_CODE_5F2A_KRN.Tag).Value)));
                fb_6.Children.Add(new FID_6_E_POSEntryMode(Formatting.ConvertToHexAscii(new byte[] { 0x91 })));
            }
            else
            {
                np.Fids.Add(new FID_q_Track2_Customer(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.TRACK_2_EQUIVALENT_DATA_57_KRN.Tag).Value)));
                fb_6.Children.Add(new FID_6_I_TransactionCurrencyCode(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.TRANSACTION_CURRENCY_CODE_5F2A_KRN.Tag).Value)));
                //fb_6.Children.Add(new FID_6_E_POSEntryMode(Formatting.ConvertToHexAscii(new byte[] { 0x07 })));
                fb_6.Children.Add(new FID_6_E_POSEntryMode(Formatting.ASCIIStringToByteArray("051")));
            }

            if (!isMagStripe)
            {
                List <byte[]> fidBytes        = new List <byte[]>();
                byte[]        smartCardScheme = new byte[] { 0x30, 0x31 };

                fidBytes.Add(smartCardScheme);
                fidBytes.Add(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.CRYPTOGRAM_INFORMATION_DATA_9F27_KRN.Tag).Value));
                fidBytes.Add(Formatting.ASCIIStringToByteArray(Formatting.ByteArrayToHexString(request.EMV_Data.Children.Get(EMVTagsEnum.TERMINAL_COUNTRY_CODE_9F1A_KRN.Tag).Value).Substring(1)));
                fidBytes.Add(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.TRANSACTION_DATE_9A_KRN.Tag).Value));
                fidBytes.Add(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.APPLICATION_CRYPTOGRAM_9F26_KRN.Tag).Value));
                fidBytes.Add(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.APPLICATION_INTERCHANGE_PROFILE_82_KRN.Tag).Value));
                fidBytes.Add(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.APPLICATION_TRANSACTION_COUNTER_ATC_9F36_KRN.Tag).Value));
                fidBytes.Add(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.UNPREDICTABLE_NUMBER_9F37_KRN.Tag).Value));
                fidBytes.Add(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.TERMINAL_VERIFICATION_RESULTS_95_KRN.Tag).Value));
                fidBytes.Add(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.TRANSACTION_TYPE_9C_KRN.Tag).Value));
                fidBytes.Add(Formatting.ASCIIStringToByteArray(Formatting.ByteArrayToHexString(request.EMV_Data.Children.Get(EMVTagsEnum.TRANSACTION_CURRENCY_CODE_5F2A_KRN.Tag).Value).Substring(1)));
                fidBytes.Add(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.AMOUNT_AUTHORISED_NUMERIC_9F02_KRN.Tag).Value));
                fidBytes.Add(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.ISSUER_APPLICATION_DATA_9F10_KRN.Tag).Value));

                fb_6.Children.Add(new FID_6_O_EMVRequestData(fidBytes.SelectMany(x => x).ToArray()));

                fidBytes = new List <byte[]>();
                fidBytes.Add(smartCardScheme);
                fidBytes.Add(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.APPLICATION_PRIMARY_ACCOUNT_NUMBER_PAN_SEQUENCE_NUMBER_5F34_KRN.Tag).Value));
                fidBytes.Add(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.TERMINAL_TYPE_9F35_KRN.Tag).Value));
                fidBytes.Add(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.CARDHOLDER_VERIFICATION_METHOD_CVM_RESULTS_9F34_KRN.Tag).Value));
                fidBytes.Add(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.APPLICATION_VERSION_NUMBER_TERMINAL_9F09_KRN.Tag).Value));
                fidBytes.Add(Formatting.ConvertToHexAscii(request.EMV_Data.Children.Get(EMVTagsEnum.DEDICATED_FILE_DF_NAME_84_KRN.Tag).Value));

                fb_6.Children.Add(new FID_6_P_EMVAdditionalRequestData(fidBytes.SelectMany(x => x).ToArray()));
            }

            Logger.Log(np.ToPrintString());

            bool check = np.Validate();

            byte[] received;

            using (request.TCPClientStream)
            {
                request.TCPClientStream.Connect(host, port);
                received = TCPIPManager.SendTransaction(request.TCPClientStream, np.Serialize());
            }

            int             pos = 0;
            TransactionBase fb;

            switch (tt)
            {
            case TransactionTypeEnum.PurchaseGoodsAndServices:
                fb = new F00_NormalPurchase();
                break;

            case TransactionTypeEnum.PurchaseWithCashback:
                fb = new F08_PurchaseWithCashBack();
                break;

            case TransactionTypeEnum.Refund:
                fb = new F12_MerchandiseReturnAdjustment();
                break;

            default:
                throw new Exception("Unimplemented TransactionTypeEnum:" + tt);
            }
            pos = fb.Deserialize(received, pos);

            Logger.Log(fb.ToPrintString());

            FIDBase responseMessageFid = fb.FindFid(FidMetaList.ResponseDisplay).Get();
            string  responseMessage    = Formatting.ByteArrayToASCIIString(responseMessageFid.Value);
            bool    responseCode;
            int     responseCodeAsNumber = Convert.ToInt32(Formatting.ByteArrayToASCIIString(fb.Header.GetValue(HeaderEntryEnum.ResponseCode)));

            if (responseCodeAsNumber >= 0 && responseCodeAsNumber <= 10)
            {
                responseCode = true;
            }
            else
            {
                responseCode = false;
            }

            FIDBase responseMessage6QFid    = fb.FindFid(FidMetaList.EMVResponseData).Get();
            string  responseMessage6Q       = Formatting.ByteArrayToASCIIString(responseMessage6QFid.Value);
            string  smartCardSchemeResponse = responseMessage6Q.Substring(0, 2);
            string  authResponseCode        = "";
            string  issuerAuthData;

            if (smartCardSchemeResponse == "00") //schem 1
            {
                issuerAuthData = responseMessage6Q.Substring(2);
            }
            else //01 == schem 2
            {
                authResponseCode = responseMessage6Q.Substring(2, 2);
                issuerAuthData   = responseMessage6Q.Substring(4);
            }

            TLV authcodeTLV = null;

            if (!String.IsNullOrEmpty(authResponseCode))
            {
                authcodeTLV = TLV.Create(EMVTagsEnum.AUTHORISATION_RESPONSE_CODE_8A_KRN.Tag, Formatting.ASCIIStringToByteArray(authResponseCode));
            }

            TLV issuerAuthDataTLV = TLV.Create(EMVTagsEnum.ISSUER_AUTHENTICATION_DATA_91_KRN.Tag, Formatting.HexStringToByteArray(issuerAuthData));

            return(new EMVApproverResponse()
            {
                IsApproved = responseCode,
                ResponseMessage = responseMessage,
                AuthCode_8A = authcodeTLV,
                IssuerAuthData_91 = issuerAuthDataTLV
            });
        }
Example #16
0
        public bool Validate(byte[] data)
        {
            switch (Format)
            {
            //case DataFormats.UNKNOWN:
            //    throw new Exception("Unknown DataFormat:" + Format);
            //case DataFormats.VARIABLE_UNKNOWN:
            //    throw new Exception("Unknown DataFormat:" + Format);

            case DataFormats._CN:
            case DataFormats._DATE_YYMMDD:
            case DataFormats._TIME_HHMMSS:
            case DataFormats._NUMERIC:
                string valueNumeric = Formatting.BcdToString(data);
                for (int i = 0; i < valueNumeric.Length; i++)
                {
                    if (!Char.IsNumber(valueNumeric, i))
                    {
                        return(false);
                    }
                }
                return(true);

            case DataFormats._BINARY:
                return(true);

            //case DataFormats._BINARY_MULTIPLE_OF_4:
            //    if (data.Length % 4 != 0)
            //        return false;
            //    else
            //        return true;

            case DataFormats._ALPHA:
                string valueAlpha = Formatting.ByteArrayToASCIIString(data);
                for (int i = 0; i < valueAlpha.Length; i++)
                {
                    if (!Char.IsLetter(valueAlpha, i))
                    {
                        return(false);
                    }
                }
                return(true);

            case DataFormats._ALPHA_NUMERIC:
                string valueAlphaNumeric = Formatting.ByteArrayToASCIIString(data);
                for (int i = 0; i < valueAlphaNumeric.Length; i++)
                {
                    if (!Char.IsLetter(valueAlphaNumeric, i) && !Char.IsNumber(valueAlphaNumeric, i))
                    {
                        return(false);
                    }
                }
                return(true);

            case DataFormats._ALPHA_NUMERIC_SPECIAL:
                string valueAlphaNumericSpecial = Formatting.ByteArrayToASCIIString(data);
                for (int i = 0; i < valueAlphaNumericSpecial.Length; i++)
                {
                    if (!Char.IsLetter(valueAlphaNumericSpecial, i) &&
                        !Char.IsNumber(valueAlphaNumericSpecial, i) &&
                        !Char.IsWhiteSpace(valueAlphaNumericSpecial, i) &&
                        !Char.IsPunctuation(valueAlphaNumericSpecial, i) &&
                        !Char.IsControl(valueAlphaNumericSpecial, i) &&
                        !Char.IsSymbol(valueAlphaNumericSpecial, i))
                    {
                        return(false);
                    }
                }
                return(true);

            case DataFormats._ALPHA_NUMERIC_SPACE:
                string valueAlphaNumericSpace = Formatting.ByteArrayToASCIIString(data);
                for (int i = 0; i < valueAlphaNumericSpace.Length; i++)
                {
                    if (!Char.IsLetter(valueAlphaNumericSpace, i) &&
                        !Char.IsNumber(valueAlphaNumericSpace, i) &&
                        !Char.IsWhiteSpace(valueAlphaNumericSpace, i))
                    {
                        return(false);
                    }
                }
                return(true);

            //case DataFormats.H:
            //    throw new Exception("Unknown DataFormat:" + Format);
            //case DataFormats.A:
            //    throw new Exception("Unknown DataFormat:" + Format);

            default:
                throw new Exception("Unknown DataFormat:" + Format);
            }
        }
Example #17
0
        public string ToPrintString(ref int depth)
        {
            StringBuilder sbTab = new StringBuilder();

            for (int j = 0; j <= depth; j++)
            {
                sbTab.Append("\t");
            }

            if (Children.Count == 0)
            {
                return(sbTab + string.Format("[{0,-50}][{1}:{2}] V:[{3}]", FidMeta.Description, Id, SubId, Formatting.ByteArrayToASCIIString(Value)));
            }
            else
            {
                StringBuilder childs = new StringBuilder();
                foreach (FIDBase child in Children)
                {
                    childs.AppendLine(sbTab + child.ToPrintString(ref depth));
                }
                return(childs.ToString());
            }
        }
Example #18
0
 public override string ToString()
 {
     return(string.Format("[{0,-50}] V:[{1}]", Name, Formatting.ByteArrayToASCIIString(Value)));
 }