From 3570757faefd59994bbbcb7c2f7182d90f54f613 Mon Sep 17 00:00:00 2001 From: Herbert Poul Date: Tue, 3 Aug 2021 11:21:01 +0200 Subject: [PATCH] Throw KdbxInvalidFileStructure for invalid files --- CHANGELOG.md | 4 ++++ lib/src/kdbx_header.dart | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 789bfa9..46d857f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.1.1 + +- Throw KdbxInvalidFileStructure for invalid files. + ## 2.1.0 - Implement permanently removing entries and groups. diff --git a/lib/src/kdbx_header.dart b/lib/src/kdbx_header.dart index 1b3d58f..889623b 100644 --- a/lib/src/kdbx_header.dart +++ b/lib/src/kdbx_header.dart @@ -385,7 +385,7 @@ class KdbxHeader { final sig1 = reader.readUint32(); final sig2 = reader.readUint32(); if (!(sig1 == Consts.FileMagic && sig2 == Consts.Sig2Kdbx)) { - throw UnsupportedError( + throw KdbxInvalidFileStructure( 'Unsupported file structure. ${ByteUtils.toHex(sig1)}, ' '${ByteUtils.toHex(sig2)}'); } @@ -583,6 +583,17 @@ class KdbxUnsupportedException implements KdbxException { } } +class KdbxInvalidFileStructure implements KdbxException { + KdbxInvalidFileStructure(this.message); + + final String message; + + @override + String toString() { + return 'KdbxInvalidFileStructure{$message}'; + } +} + class HashedBlockReader { static const BLOCK_SIZE = 1024 * 1024; static const HASH_SIZE = 32;