Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix AID length + bugfix reading beyond block 255 + add readClass option #55

Merged
merged 3 commits into from
Dec 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/Reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ class Reader extends EventEmitter {

}

async read(blockNumber, length, blockSize = 4, packetSize = 16) {
async read(blockNumber, length, blockSize = 4, packetSize = 16, readClass = 0xff) {

if (!this.card) {
throw new ReadError(CARD_NOT_CONNECTED);
Expand All @@ -505,7 +505,7 @@ class Reader extends EventEmitter {

// console.log(i, block, size);

commands.push(this.read(block, size, blockSize, packetSize));
commands.push(this.read(block, size, blockSize, packetSize, readClass));

}

Expand All @@ -519,10 +519,10 @@ class Reader extends EventEmitter {

// APDU CMD: Read Binary Blocks
const packet = new Buffer([
0xff, // Class
readClass, // Class
0xb0, // Ins
0x00, // P1
blockNumber, // P2: Block Number
(blockNumber >> 8) & 0xFF, // P1
blockNumber & 0xFF, // P2: Block Number
length // Le: Number of Bytes to Read (Maximum 16 bytes)
]);

Expand Down Expand Up @@ -734,17 +734,19 @@ class Reader extends EventEmitter {
}

// APDU CMD: Select Apdu
const aid = Buffer.from(this._parsedAid);
const packetHeader = Buffer.from([
0x00, // Class
0xa4, // INS
0x04, // P1
0x00, // P2
0x05 // Le
aid.length, // Lc
]);
const packetFooter = Buffer.from([
0x00, // Le
]);

const aid = Buffer.from(this._parsedAid);

const packet = Buffer.concat([packetHeader, aid]);
const packet = Buffer.concat([packetHeader, aid, packetFooter]);

try {

Expand Down