예제 #1
1
        private async Task<DataBlock> GetDataBlockInt(int block)
        {
            var db = dataBlocks[block];

            if (db != null)
                return db;

            if (card.ActiveSector != sector)
            {
                if (!await card.Reader.Login(sector, InternalKeyType.KeyA))
                {
                    // In some cases, Key A may not be present, so try logging in with Key B
                    if (!await card.Reader.Login(sector, InternalKeyType.KeyB))
                    {
                        throw new CardLoginException($"Unable to login in sector {sector} with key A or B");
                    }
                }


                var res = await card.Reader.Read(sector, block);
                if (!res.Item1)
                    throw new CardReadException($"Unable to read from sector {sector}, block {block}");

                db = new DataBlock(block, res.Item2, (block == TrailerBlockIndex));
                dataBlocks[block] = db;
            }

            return db;
        }
예제 #2
0
        private async Task FlushDataBlock(DataBlock dataBlock)
        {
            if (card.ActiveSector != sector)
            {
                var writeKey = GetWriteKey(dataBlock.Number);
                if (!await card.Reader.Login(sector, writeKey))
                    throw new CardLoginException($"Unable to login in sector {sector} with key {writeKey}");

                card.ActiveSector = sector;
            }

            if (!await card.Reader.Write(sector, dataBlock.Number, dataBlock.Data))
                throw new CardWriteException($"Unable to write in sector {sector}, block {dataBlock.Number}");
        }