From e7e342abb17318a1474a59b0152c7e4f6b28a566 Mon Sep 17 00:00:00 2001 From: Herbert Poul Date: Tue, 3 Aug 2021 11:26:19 +0200 Subject: [PATCH] move exceptions into their own package. --- lib/kdbx.dart | 9 ++------- lib/src/kdbx_entry.dart | 1 + lib/src/kdbx_exceptions.dart | 36 ++++++++++++++++++++++++++++++++++ lib/src/kdbx_file.dart | 1 + lib/src/kdbx_header.dart | 38 +----------------------------------- lib/src/kdbx_meta.dart | 1 + lib/src/kdbx_xml.dart | 1 + 7 files changed, 43 insertions(+), 44 deletions(-) create mode 100644 lib/src/kdbx_exceptions.dart diff --git a/lib/kdbx.dart b/lib/kdbx.dart index 0879bc5..32a1167 100644 --- a/lib/kdbx.dart +++ b/lib/kdbx.dart @@ -10,6 +10,7 @@ export 'src/kdbx_consts.dart'; export 'src/kdbx_custom_data.dart'; export 'src/kdbx_dao.dart' show KdbxDao; export 'src/kdbx_entry.dart' show KdbxEntry, KdbxKey, KdbxKeyCommon; +export 'src/kdbx_exceptions.dart'; export 'src/kdbx_file.dart'; export 'src/kdbx_format.dart' show @@ -23,13 +24,7 @@ export 'src/kdbx_format.dart' KeyFileCredentials, PasswordCredentials; export 'src/kdbx_group.dart' show KdbxGroup; -export 'src/kdbx_header.dart' - show - KdbxException, - KdbxInvalidKeyException, - KdbxCorruptedFileException, - KdbxUnsupportedException, - KdbxVersion; +export 'src/kdbx_header.dart' show KdbxVersion; export 'src/kdbx_meta.dart'; export 'src/kdbx_object.dart' show diff --git a/lib/src/kdbx_entry.dart b/lib/src/kdbx_entry.dart index be962ee..fcf474b 100644 --- a/lib/src/kdbx_entry.dart +++ b/lib/src/kdbx_entry.dart @@ -5,6 +5,7 @@ import 'package:kdbx/src/crypto/protected_value.dart'; import 'package:kdbx/src/internal/extension_utils.dart'; import 'package:kdbx/src/kdbx_binary.dart'; import 'package:kdbx/src/kdbx_consts.dart'; +import 'package:kdbx/src/kdbx_exceptions.dart'; import 'package:kdbx/src/kdbx_file.dart'; import 'package:kdbx/src/kdbx_format.dart'; import 'package:kdbx/src/kdbx_group.dart'; diff --git a/lib/src/kdbx_exceptions.dart b/lib/src/kdbx_exceptions.dart new file mode 100644 index 0000000..f50a996 --- /dev/null +++ b/lib/src/kdbx_exceptions.dart @@ -0,0 +1,36 @@ +class KdbxException implements Exception {} + +class KdbxInvalidKeyException implements KdbxException {} + +class KdbxCorruptedFileException implements KdbxException { + KdbxCorruptedFileException([this.message]); + + final String? message; + + @override + String toString() { + return 'KdbxCorruptedFileException{message: $message}'; + } +} + +class KdbxUnsupportedException implements KdbxException { + KdbxUnsupportedException(this.hint); + + final String hint; + + @override + String toString() { + return 'KdbxUnsupportedException{hint: $hint}'; + } +} + +class KdbxInvalidFileStructure implements KdbxException { + KdbxInvalidFileStructure(this.message); + + final String message; + + @override + String toString() { + return 'KdbxInvalidFileStructure{$message}'; + } +} diff --git a/lib/src/kdbx_file.dart b/lib/src/kdbx_file.dart index 078bcba..2a2475e 100644 --- a/lib/src/kdbx_file.dart +++ b/lib/src/kdbx_file.dart @@ -5,6 +5,7 @@ import 'package:collection/collection.dart'; import 'package:kdbx/src/crypto/protected_value.dart'; import 'package:kdbx/src/kdbx_consts.dart'; import 'package:kdbx/src/kdbx_dao.dart'; +import 'package:kdbx/src/kdbx_exceptions.dart'; import 'package:kdbx/src/kdbx_format.dart'; import 'package:kdbx/src/kdbx_group.dart'; import 'package:kdbx/src/kdbx_header.dart'; diff --git a/lib/src/kdbx_header.dart b/lib/src/kdbx_header.dart index 889623b..46f39f1 100644 --- a/lib/src/kdbx_header.dart +++ b/lib/src/kdbx_header.dart @@ -4,6 +4,7 @@ import 'package:crypto/crypto.dart' as crypto; import 'package:kdbx/src/crypto/key_encrypter_kdf.dart'; import 'package:kdbx/src/internal/consts.dart'; import 'package:kdbx/src/kdbx_binary.dart'; +import 'package:kdbx/src/kdbx_exceptions.dart'; import 'package:kdbx/src/kdbx_var_dictionary.dart'; import 'package:kdbx/src/utils/byte_utils.dart'; import 'package:logging/logging.dart'; @@ -557,43 +558,6 @@ class KdbxHeader { } } -class KdbxException implements Exception {} - -class KdbxInvalidKeyException implements KdbxException {} - -class KdbxCorruptedFileException implements KdbxException { - KdbxCorruptedFileException([this.message]); - - final String? message; - - @override - String toString() { - return 'KdbxCorruptedFileException{message: $message}'; - } -} - -class KdbxUnsupportedException implements KdbxException { - KdbxUnsupportedException(this.hint); - - final String hint; - - @override - String toString() { - return 'KdbxUnsupportedException{hint: $hint}'; - } -} - -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; diff --git a/lib/src/kdbx_meta.dart b/lib/src/kdbx_meta.dart index 07d475e..393c726 100644 --- a/lib/src/kdbx_meta.dart +++ b/lib/src/kdbx_meta.dart @@ -5,6 +5,7 @@ import 'package:collection/collection.dart'; import 'package:kdbx/src/internal/extension_utils.dart'; import 'package:kdbx/src/kdbx_binary.dart'; import 'package:kdbx/src/kdbx_custom_data.dart'; +import 'package:kdbx/src/kdbx_exceptions.dart'; import 'package:kdbx/src/kdbx_format.dart'; import 'package:kdbx/src/kdbx_header.dart'; import 'package:kdbx/src/kdbx_object.dart'; diff --git a/lib/src/kdbx_xml.dart b/lib/src/kdbx_xml.dart index 3e334fc..72ca036 100644 --- a/lib/src/kdbx_xml.dart +++ b/lib/src/kdbx_xml.dart @@ -4,6 +4,7 @@ import 'dart:typed_data'; import 'package:clock/clock.dart'; import 'package:collection/collection.dart' show IterableExtension; import 'package:kdbx/src/kdbx_consts.dart'; +import 'package:kdbx/src/kdbx_exceptions.dart'; import 'package:kdbx/src/kdbx_format.dart'; import 'package:kdbx/src/kdbx_header.dart'; import 'package:kdbx/src/kdbx_object.dart';