Skip to content

Commit

Permalink
Drivers: Remove caching functionality from readNDEF (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
icedevml authored Apr 17, 2024
1 parent a071e36 commit 3fdab27
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 19 deletions.
2 changes: 1 addition & 1 deletion drivers/nfc_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async function execHaloCmdRN(nfcManager, command, options) {

if (command.name === "read_ndef") {
let wrappedTransceive = async (payload) => Buffer.from(await nfcManager.isoDepHandler.transceive([...payload]));
return await readNDEF(wrappedTransceive, {allowCache: true});
return await readNDEF(wrappedTransceive);
} else {
return await execHaloCmd(command, {
method: 'nfc-manager',
Expand Down
4 changes: 2 additions & 2 deletions drivers/pcsc.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async function getVersion(reader) {
if (versionRes.slice(-2).compare(Buffer.from([0x90, 0x00])) !== 0) {
// GET_FV_VERSION command not supported, fallback to NDEF
let wrappedTransceive = async (payload) => await transceive(reader, payload, {noCheck: true});
let url = await readNDEF(wrappedTransceive, {allowCache: true});
let url = await readNDEF(wrappedTransceive);

if (!url.qs.v) {
return '01.C1.000001.00000000';
Expand Down Expand Up @@ -198,7 +198,7 @@ async function execHaloCmdPCSC(command, reader) {
} else if (command.name === "read_ndef") {
// PCSC-specific NDEF reader command
let wrappedTransceive = async (payload) => await transceive(reader, payload, {noCheck: true});
return await readNDEF(wrappedTransceive, {allowCache: true});
return await readNDEF(wrappedTransceive);
} else if (command.name === "full_gen_key") {
await selectCore(reader);

Expand Down
18 changes: 2 additions & 16 deletions drivers/read_ndef.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@ const Buffer = require('buffer/').Buffer;
const queryString = require('query-string');
const {HaloLogicError} = require("../halo/exceptions");

let cachedResult = null;

async function readNDEF(transceive, options) {
options = options || {};

if (options.allowCache && cachedResult) {
return cachedResult;
}

async function readNDEF(transceive) {
let resSelect = await transceive(Buffer.from("00A4040007D276000085010100", "hex"));

if (resSelect.compare(Buffer.from([0x90, 0x00])) !== 0) {
Expand Down Expand Up @@ -85,16 +77,10 @@ async function readNDEF(transceive, options) {
fullBuf = fullBuf.slice(4 + skipLen, 4 + skipLen + lengthData);
let parsed = queryString.parseUrl(fullBuf.toString());

let out = {
return {
url: parsed.url,
qs: {...parsed.query}
};

if (options.allowCache) {
cachedResult = out;
}

return out;
}

module.exports = {readNDEF};

0 comments on commit 3fdab27

Please sign in to comment.