示例#1
0
        internal AtrChecksumToken(AtrReadStream atr)
        {
            this.CalculatedChecksum = AtrChecksumToken.CalculateChecksum(atr.GetPreviousBytes().GetSubArray(1));
            this.CheckByte          = atr.GetNextByte();

            this.ChecksumValid = this.CheckByte == this.CalculatedChecksum;
        }
示例#2
0
        internal AtrChecksumToken(byte[] atrBytesWithoutChecksum)
        {
            this.CalculatedChecksum = AtrChecksumToken.CalculateChecksum(atrBytesWithoutChecksum.GetSubArray(1));
            this.CheckByte          = this.CalculatedChecksum;

            this.ChecksumValid = true;
        }
示例#3
0
        internal TokenizedAtr(Atr owner, byte[] atr)
        {
            this.owner = owner;
            AtrReadStream AtrStream = new AtrReadStream(atr);

            //Read preamble
            this.Preamble = new AtrPreambleToken(this, AtrStream);

            //read interface byte groups
            this.InterfaceByteGroups = new AtrInterfaceByteGroupTokenCollection(this);
            NextInterfaceBytesIndicator NextInterfaceBytesIndicator = this.Preamble.NextInterfaceBytesIndicator;

            while (NextInterfaceBytesIndicator != null)
            {
                AtrInterfaceByteGroupToken InterfaceByteGroup = new AtrInterfaceByteGroupToken(this, AtrStream, NextInterfaceBytesIndicator);
                this.InterfaceByteGroups.AppendGroup(InterfaceByteGroup);

                NextInterfaceBytesIndicator = NextInterfaceBytesIndicator.TdExists
                    ? new NextInterfaceBytesIndicator(AtrStream.GetNextByte(), false)
                    : null;
            }

            //Read and parse historical characters
            if (this.Preamble.NumberOfHistoricalCharacters > 0)
            {
                byte[] HistoricalCharacters = AtrStream.GetNextBytes(this.Preamble.NumberOfHistoricalCharacters);
                this.HistoricalCharacters = new AtrHistoricalCharactersToken(this, HistoricalCharacters);
            }
            else
            {
                this.HistoricalCharacters = new AtrHistoricalCharactersToken(this, new byte[0]);
            }

            //Read checksum if needed
            if (this.ChecksumRequired)
            {
                this.atrChecksum = new AtrChecksumToken(AtrStream);
            }

            //Read additional bytes
            int AdditionalBytes = AtrStream.GetRemainingLength();

            if (AdditionalBytes > 0)
            {
                this.ExtraBytes = new AtrExtraBytesToken(AtrStream, AdditionalBytes);
            }
        }
示例#4
0
        internal void NotifyChanged()
        {
            if (this.ChecksumRequired)
            {
                AtrWriteStream AtrStream = new AtrWriteStream();

                AtrStream.WriteBytes(this.Preamble.Bytes);
                this.InterfaceByteGroups.ForEach(_ => AtrStream.WriteBytes(_.Bytes));
                AtrStream.WriteBytes(this.HistoricalCharacters.Bytes);

                this.AtrChecksum = new AtrChecksumToken(AtrStream.ToByteArray());
            }
            else
            {
                this.AtrChecksum = null;
            }
            this.owner.NotifyChanged();
        }