예제 #1
0
        public void ProcessTlvStream()
        {
            var expectedTlv = new[] {
                new Tlv {
                    Tag   = 0xe0u,
                    Value = new byte[] { 0x12 },
                },
                new Tlv {
                    Tag   = 0xe1u,
                    Value = new byte[] { 0x23, 0x34 },
                },
            };

            var d = new byte[] { 0xe0, 0x01, 0x12, 0xe1, 0x02, 0x23, 0x34 };

            var actualTlv = new List <Tlv>();
            var ms        = new MemoryStream(d);

            TlvEncoding.ProcessTlvStream(ms,
                                         (tag, data) => {
                actualTlv.Add(new Tlv {
                    Tag   = tag,
                    Value = data,
                });
            });

            AssertTlvArrayEqual(expectedTlv, actualTlv.ToArray());
        }
예제 #2
0
        public void ReadTagSuccessNonEmv(byte[] input, uint?expectedTag, int expectedLength)
        {
            var ms = new MemoryStream(input);
            var t  = TlvEncoding.ReadNextTag(ms, false);

            Assert.AreEqual(expectedTag, t);
            Assert.AreEqual(expectedLength, ms.Position);
        }
예제 #3
0
        public void ReadLengthFails5Bytes()
        {
            var ms = new MemoryStream(new byte[] { 0x85, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF });

            Assert.ThrowsException <TlvException>(() => {
                TlvEncoding.ReadLength(ms);
            });
        }
예제 #4
0
        public void ProcessTlvStreamZeroLengthTag()
        {
            var d = new byte[] { 0xe0, 0x00 };

            var ms = new MemoryStream(d);

            TlvEncoding.ProcessTlvStream(ms, (tag, data) => { });
        }
예제 #5
0
        public void WriteTagInvalid(uint tag)
        {
            var ms = new MemoryStream();

            Assert.ThrowsException <TlvException>(() => {
                TlvEncoding.WriteTag(ms, tag);
            });
        }
예제 #6
0
        public void ReadLengthFailsUnexpectedEnd(byte[] input)
        {
            var ms = new MemoryStream(input);

            Assert.ThrowsException <TlvException>(() => {
                TlvEncoding.ReadLength(ms);
            });
        }
예제 #7
0
        //[DataRow(new byte[] { 0x84, 0xAB, 0xCD, 0xEF, 0x01, 0x01 }, 0xABCDEF01, 5, DisplayName = "1000 0100 1010 1011 1100 1101 1110 1111 0000 0001")]
        public void ReadLengthSuccess(byte[] input, int?expectedLength, int expectedPosition)
        {
            var ms = new MemoryStream(input);
            var t  = TlvEncoding.ReadLength(ms);

            Assert.AreEqual(expectedLength, t);
            Assert.AreEqual(expectedPosition, ms.Position);
        }
예제 #8
0
        public void ReadTagFails5Bytes()
        {
            var ms = new MemoryStream(new byte[] { 0x1F, 0x80, 0x80, 0x80, 0x00 });

            Assert.ThrowsException <TlvException>(() => {
                TlvEncoding.ReadNextTag(ms, false);
            });
        }
예제 #9
0
        public void ReadTagFailsUnexpectedEnd(byte[] input)
        {
            var ms = new MemoryStream(input);

            Assert.ThrowsException <TlvException>(() => {
                TlvEncoding.ReadNextTag(ms, false);
            }); // last octet is indicating a subsequent octet, but no more data
        }
예제 #10
0
        public void WriteTlv(byte[] expected, uint tag, byte[] tagValue)
        {
            var ms = new MemoryStream();

            TlvEncoding.WriteTlv(ms, tag, tagValue);

            ms.Position = 0;
            var buf = new byte[ms.Length];

            ms.Read(buf, 0, buf.Length);
            AssertByteArrayEqual(expected, buf);
        }
예제 #11
0
        public void WriteTagSuccess(uint tag, byte[] expectedOutput)
        {
            var ms = new MemoryStream();

            TlvEncoding.WriteTag(ms, tag);

            ms.Position = 0;
            var buf = new byte[ms.Length];

            ms.Read(buf, 0, buf.Length);
            AssertByteArrayEqual(expectedOutput, buf);
        }