@hazae41/kdbx
Version:
Rust-like KeePass (KDBX 4) file format for TypeScript
66 lines (62 loc) • 2.09 kB
JavaScript
;
var binary = require('@hazae41/binary');
var cursor = require('@hazae41/cursor');
var index = require('../../../libs/tlv/index.cjs');
class Vector {
bytes;
value;
constructor(bytes, value) {
this.bytes = bytes;
this.value = value;
}
sizeOrThrow() {
return this.bytes.sizeOrThrow();
}
writeOrThrow(cursor) {
this.bytes.writeOrThrow(cursor);
}
cloneOrThrow() {
return binary.Readable.readFromBytesOrThrow(Vector, binary.Writable.writeToBytesOrThrow(this));
}
}
(function (Vector) {
function initOrThrow(indexed) {
const entries = new Array();
for (const key of Object.keys(indexed)) {
const index$1 = Number(key);
const array = indexed[index$1];
if (array == null)
continue;
for (const value of array)
entries.push(new index.TLV(index$1, value));
continue;
}
const sized = entries.reduce((x, r) => x + r.sizeOrThrow(), 0) + index.TLV.Empty.sizeOrThrow();
const bytes = new binary.Opaque(new Uint8Array(sized));
const cursor$1 = new cursor.Cursor(bytes.bytes);
for (const entry of entries)
entry.writeOrThrow(cursor$1);
index.TLV.Empty.writeOrThrow(cursor$1);
return new Vector(bytes, indexed);
}
Vector.initOrThrow = initOrThrow;
function readOrThrow(cursor) {
const start = cursor.offset;
const entries = new Array();
const indexed = {};
while (true) {
const tlv = index.TLV.readOrThrow(cursor);
if (tlv.type === 0)
break;
entries.push(tlv);
indexed[tlv.type] ??= [];
indexed[tlv.type].push(tlv.value);
continue;
}
const bytes = new binary.Opaque(cursor.bytes.subarray(start, cursor.offset));
return new Vector(bytes, indexed);
}
Vector.readOrThrow = readOrThrow;
})(Vector || (Vector = {}));
exports.Vector = Vector;
//# sourceMappingURL=index.cjs.map