Browse Source

fix analyzer warnings, made it possible to load credentials by byte stream.

remove-cryptography-dependency
Herbert Poul 5 years ago
parent
commit
ae0c37456e
  1. 1
      lib/src/internal/byte_utils.dart
  2. 24
      lib/src/kdbx_format.dart
  3. 3
      lib/src/kdbx_group.dart
  4. 1
      test/kdbx_test.dart

1
lib/src/internal/byte_utils.dart

@ -1,4 +1,3 @@
import 'dart:ffi';
import 'dart:io'; import 'dart:io';
import 'dart:math'; import 'dart:math';
import 'dart:typed_data'; import 'dart:typed_data';

24
lib/src/kdbx_format.dart

@ -20,11 +20,22 @@ import 'kdbx_object.dart';
final _logger = Logger('kdbx.format'); final _logger = Logger('kdbx.format');
class Credentials { abstract class Credentials {
Credentials(this._password); factory Credentials(ProtectedValue password) => PasswordCredentials(password);
Credentials._();
factory Credentials.fromHash(Uint8List hash) => HashCredentials(hash);
Uint8List getHash();
}
class PasswordCredentials implements Credentials {
PasswordCredentials(this._password);
final ProtectedValue _password; final ProtectedValue _password;
@override
Uint8List getHash() { Uint8List getHash() {
final output = convert.AccumulatorSink<crypto.Digest>(); final output = convert.AccumulatorSink<crypto.Digest>();
final input = crypto.sha256.startChunkedConversion(output); final input = crypto.sha256.startChunkedConversion(output);
@ -34,6 +45,15 @@ class Credentials {
} }
} }
class HashCredentials implements Credentials {
HashCredentials(this.hash);
final Uint8List hash;
@override
Uint8List getHash() => hash;
}
class KdbxFile { class KdbxFile {
KdbxFile(this.credentials, this.header, this.body) { KdbxFile(this.credentials, this.header, this.body) {
for (final obj in _allObjects) { for (final obj in _allObjects) {

3
lib/src/kdbx_group.dart

@ -1,5 +1,4 @@
import 'package:kdbx/kdbx.dart'; import 'package:kdbx/kdbx.dart';
import 'package:kdbx/src/internal/async_utils.dart';
import 'package:kdbx/src/kdbx_consts.dart'; import 'package:kdbx/src/kdbx_consts.dart';
import 'package:kdbx/src/kdbx_entry.dart'; import 'package:kdbx/src/kdbx_entry.dart';
import 'package:kdbx/src/kdbx_xml.dart'; import 'package:kdbx/src/kdbx_xml.dart';
@ -27,8 +26,6 @@ class KdbxGroup extends KdbxObject {
.forEach(_entries.add); .forEach(_entries.add);
} }
final StreamSubscriptions _subscriptions = StreamSubscriptions();
@override @override
XmlElement toXml() { XmlElement toXml() {
final el = super.toXml(); final el = super.toXml();

1
test/kdbx_test.dart

@ -4,7 +4,6 @@ import 'dart:typed_data';
import 'package:kdbx/kdbx.dart'; import 'package:kdbx/kdbx.dart';
import 'package:kdbx/src/crypto/protected_salt_generator.dart'; import 'package:kdbx/src/crypto/protected_salt_generator.dart';
import 'package:kdbx/src/crypto/protected_value.dart'; import 'package:kdbx/src/crypto/protected_value.dart';
import 'package:kdbx/src/internal/byte_utils.dart';
import 'package:kdbx/src/kdbx_format.dart'; import 'package:kdbx/src/kdbx_format.dart';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
import 'package:logging_appenders/logging_appenders.dart'; import 'package:logging_appenders/logging_appenders.dart';

Loading…
Cancel
Save