UNPKG

@hazae41/kdbx

Version:

Rust-like KeePass (KDBX 4) file format for TypeScript

47 lines (46 loc) 1.41 kB
// deno-lint-ignore-file no-namespace import { Unknown } from "@hazae41/binary"; export class TLV { type; value; constructor(type, value) { this.type = type; this.value = value; } sizeOrThrow() { return 1 + 4 + this.value.sizeOrThrow(); } writeOrThrow(cursor) { cursor.writeUint8OrThrow(this.type); cursor.writeUint32OrThrow(this.value.sizeOrThrow(), true); this.value.writeOrThrow(cursor); } cloneOrThrow() { return new TLV(this.type, this.value.cloneOrThrow()); } readIntoOrThrow(readable) { return new TLV(this.type, this.value.readIntoOrThrow(readable)); } } (function (TLV) { let Empty; (function (Empty) { Empty.type = 0x00; function sizeOrThrow() { return 1 + 4; } Empty.sizeOrThrow = sizeOrThrow; function writeOrThrow(cursor) { cursor.writeUint8OrThrow(Empty.type); cursor.writeUint32OrThrow(0, true); } Empty.writeOrThrow = writeOrThrow; })(Empty = TLV.Empty || (TLV.Empty = {})); function readOrThrow(cursor) { const type = cursor.readUint8OrThrow(); const length = cursor.readUint32OrThrow(true); const bytes = new Unknown(cursor.readOrThrow(length)); return new TLV(type, bytes); } TLV.readOrThrow = readOrThrow; })(TLV || (TLV = {}));