UNPKG

@codianz/emv-tools

Version:
79 lines 2.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.rapdu = exports.RAPDU = void 0; const data_chunk_1 = require("./data_chunk"); const data_chunk_holder_1 = require("./data_chunk_holder"); const tlv_1 = require("./tlv"); var RAPDU; (function (RAPDU) { class status_word extends data_chunk_holder_1.data_chunk_holder { constructor(data) { super(data); } static create_from_data_chunk(src) { do { if (!src.valid) break; if (src.size < 2) break; return new status_word(src.get_range(0, 2)); } while (false); return new status_word(); } get sw1sw2() { return (this.sw1 << 8) | this.sw2; } get sw1() { if (!this.valid) throw new Error("invalid status_word"); const _0 = this.data_chunk.get_byte(0); if (_0 === undefined) throw new Error("invalid status_word"); return _0; } get sw2() { if (!this.valid) throw new Error("invalid status_word"); const _0 = this.data_chunk.get_byte(1); if (_0 === undefined) throw new Error("invalid status_word"); return _0; } get is_ok() { return this.sw1sw2 == 0x9000; } } RAPDU.status_word = status_word; })(RAPDU = exports.RAPDU || (exports.RAPDU = {})); /** namespace RAPDU */ class rapdu { constructor(data, status_word) { this.m_data_chunk = data !== null && data !== void 0 ? data : new data_chunk_1.data_chunk(); this.m_status_word = status_word !== null && status_word !== void 0 ? status_word : new RAPDU.status_word(); } static create_from_data_chunk(src) { do { if (!src.valid) break; if (src.size < 2) break; const data = src.get_range(0, src.size - 2); const sw = src.get_range(src.size - 2, 2); return new rapdu(data, RAPDU.status_word.create_from_data_chunk(sw)); } while (false); return new rapdu(); } get valid() { return this.m_data_chunk.valid && this.m_status_word.valid; } get data_chunk() { return this.m_data_chunk; } get status_word() { return this.m_status_word; } get_tlv() { return tlv_1.tlv.create_from_data_chunk(this.m_data_chunk); } } exports.rapdu = rapdu; //# sourceMappingURL=rapdu.js.map