Exemple #1
0
        private static List <TLVXML> SerList(TLVList list)
        {
            IEnumerator <TLV> e      = list.GetEnumerator();
            List <TLVXML>     serXML = new List <TLVXML>();

            while (e.MoveNext())
            {
                TLV    value  = e.Current;
                TLVXML tlvXML = new TLVXML()
                {
                    Tag = value.Tag.TagLable
                };
                if (value.Tag.IsConstructed)
                {
                    tlvXML.Children = SerList(value.Children);
                }
                else
                {
                    tlvXML.Value = value.Value;
                }

                serXML.Add(tlvXML);
            }
            return(serXML);
        }
Exemple #2
0
 public virtual void AddListToList(TLVList list, bool withDup = false, Func <TLV, bool> function = null)
 {
     foreach (TLV tlv in list.listToManage)
     {
         AddToList(tlv, withDup, function);
     }
 }
Exemple #3
0
        public static TLVList DeserializeChildrenWithNoLV(byte[] rawTlv, int pos)
        {
            TLVList children = new TLVList();

            for (int i = pos; i < rawTlv.Length;)
            {
                T t = T.Create(rawTlv, ref i);
                children.AddToList(TLV.Create(t.TagLable));
            }
            return(children);
        }
Exemple #4
0
        public static TLVList DeserializeChildrenWithNoV(byte[] rawTlv, int pos)
        {
            TLVList children = new TLVList();

            for (int i = pos; i < rawTlv.Length;)//dont increment i
            {
                TLV child = new TLV()
                {
                    Tag = new T()
                };
                pos       = child.Tag.Deserialize(rawTlv, pos);
                child.Val = new V(TLVMetaDataSourceSingleton.Instance.DataSource.GetFormatter(child.Tag.TagLable));
                //pos = child.Val.Length.deserialize(rawTlv, pos);
                pos = child.Val.Length.DeserializeNonMultiByte(rawTlv, pos);
                children.AddToListIncludeDuplicates(child);
                i = pos;
            }
            return(children);
        }
Exemple #5
0
        private static TLVList DeserList(List <TLVXML> serXML)
        {
            TLVList result = new TLVList();

            serXML.ForEach((x) =>
            {
                TLV tlvToAdd = TLV.Create(x.Tag);
                result.AddToList(tlvToAdd);
                if (x.Children.Count > 0)
                {
                    tlvToAdd.Children.AddListToList(DeserList(x.Children));
                }
                else
                if (x.Value != null)
                {
                    tlvToAdd.Value = x.Value;
                }
            });
            return(result);
        }
Exemple #6
0
        public override int Deserialize(byte[] rawTlv, int pos)
        {
            if (rawTlv.Length == 0)
            {
                return(0);
            }

            children = new TLVList();

            //some byte streams may have FF padding between tags ??
            while (rawTlv[pos] == 0xFF)
            {
                pos++;
            }

            Tag = new T();
            pos = Tag.Deserialize(rawTlv, pos);
            Val = new V(TLVMetaDataSourceSingleton.Instance.DataSource.GetFormatter(Tag.TagLable));
            pos = Val.Deserialize(rawTlv, pos);

            if (Tag.IsConstructed)
            {
                for (int i = 0; i < Value.Length;)
                {
                    TLV child = new TLV();
                    i = child.Deserialize(Value, i);
                    //TODO: Dont like this...had to change AddToList to allow duplicates, previously if a item in the list already existed its
                    //value was replaced, some cards may return blocks of 0x00 bytes
                    //in their read record byte streams, this is not valid TLV but we have to cater for it
                    //the TLV class sees a tag of 00 with length of 00 and so on, we add the 00 tags and allow duplicates so that when things
                    //like static data for authentication is calcaulted the dups are serialized back into the origional
                    //blocks of 0x00, since the card has included this invalid data in its signature!!
                    //this should change, probably include the 0x00 blocks as some sort of custom padding tag, and switch dups back off?
                    Children.AddToList(child, true);
                }
            }
            return(pos);
        }
Exemple #7
0
 private TLV(string tag, byte[] value)
 {
     children = new TLVList();
     Tag      = new T(tag);
     Val      = new V(TLVMetaDataSourceSingleton.Instance.DataSource.GetFormatter(Tag.TagLable), value);
 }
Exemple #8
0
 protected TLV()
 {
     children = new TLVList();
 }
Exemple #9
0
 public static string XmlSerialize(TLVList list)
 {
     return(XMLUtil <List <TLVXML> > .Serialize(SerList(list)));
 }