feat: add native KDBX scaffolding and in-memory KeePass API
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { BinaryReader } from "./binary";
|
||||
import type { KdbxHeader } from "./types";
|
||||
|
||||
const KDBX_SIGNATURE_1 = 0x9aa2d903;
|
||||
const KDBX_SIGNATURE_2 = 0xb54bfb67;
|
||||
|
||||
export function parseKdbxHeader(buffer: Uint8Array): { header: KdbxHeader; offset: number } {
|
||||
const reader = new BinaryReader(buffer);
|
||||
const signature1 = reader.readUint32LE();
|
||||
const signature2 = reader.readUint32LE();
|
||||
|
||||
if (signature1 !== KDBX_SIGNATURE_1 || signature2 !== KDBX_SIGNATURE_2) {
|
||||
throw new Error("Invalid KDBX signature");
|
||||
}
|
||||
|
||||
const versionMinor = reader.readUint16LE();
|
||||
const versionMajor = reader.readUint16LE();
|
||||
const version = { major: versionMajor, minor: versionMinor };
|
||||
|
||||
return {
|
||||
header: { version },
|
||||
offset: buffer.length - reader.remaining(),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user