Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyrat committed Feb 20, 2024
1 parent 479cd78 commit b24b601
Show file tree
Hide file tree
Showing 19 changed files with 139 additions and 139 deletions.
3 changes: 1 addition & 2 deletions bin/kdbx.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ void main(List<String> arguments) {
}

class KdbxCommandRunner extends CommandRunner<void> {
KdbxCommandRunner(String executableName, String description)
: super(executableName, description) {
KdbxCommandRunner(super.executableName, super.description) {
argParser.addFlag('verbose', abbr: 'v');
addCommand(CatCommand());
addCommand(DumpXmlCommand());
Expand Down
2 changes: 1 addition & 1 deletion lib/src/crypto/protected_salt_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ProtectedSaltGenerator {
}

class ChachaProtectedSaltGenerator extends ProtectedSaltGenerator {
ChachaProtectedSaltGenerator._(StreamCipher state) : super._(state);
ChachaProtectedSaltGenerator._(super.state) : super._();

factory ChachaProtectedSaltGenerator.create(Uint8List key) {
final hash = sha512.convert(key);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/crypto/protected_value.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class PlainValue implements StringValue {
}

class ProtectedValue extends PlainValue {
ProtectedValue(String text) : super(text);
ProtectedValue(super.text);

factory ProtectedValue.fromString(String value) {
return ProtectedValue(value);
Expand Down
8 changes: 4 additions & 4 deletions lib/src/kdbx_custom_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ class KdbxObjectCustomData extends KdbxNode {
: _data = {},
super.create(KdbxXml.NODE_CUSTOM_DATA);

KdbxObjectCustomData.read(xml.XmlElement node)
KdbxObjectCustomData.read(super.node)
: _data = Map.fromEntries(
node.findElements(KdbxXml.NODE_CUSTOM_DATA_ITEM).map((el) {
final key = el.singleTextNode(KdbxXml.NODE_KEY);
final value = el.singleTextNode(KdbxXml.NODE_VALUE);
return MapEntry(key, value);
})),
super.read(node);
super.read();

final Map<String, String> _data;

Expand Down Expand Up @@ -59,7 +59,7 @@ class KdbxMetaCustomData extends KdbxNode {
: _data = {},
super.create(KdbxXml.NODE_CUSTOM_DATA);

KdbxMetaCustomData.read(xml.XmlElement node)
KdbxMetaCustomData.read(super.node)
: _data = Map.fromEntries(
node.findElements(KdbxXml.NODE_CUSTOM_DATA_ITEM).map((el) {
final key = el.singleTextNode(KdbxXml.NODE_KEY);
Expand All @@ -73,7 +73,7 @@ class KdbxMetaCustomData extends KdbxNode {
: null
));
})),
super.read(node);
super.read();

final Map<String, KdbxMetaCustomDataItem> _data;

Expand Down
3 changes: 1 addition & 2 deletions lib/src/kdbx_deleted_object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'package:clock/clock.dart';
import 'package:kdbx/src/kdbx_format.dart';
import 'package:kdbx/src/kdbx_object.dart';
import 'package:kdbx/src/kdbx_xml.dart';
import 'package:xml/xml.dart';

class KdbxDeletedObject extends KdbxNode implements KdbxNodeContext {
KdbxDeletedObject.create(this.ctx, KdbxUuid uuid, {DateTime? deletionTime})
Expand All @@ -11,7 +10,7 @@ class KdbxDeletedObject extends KdbxNode implements KdbxNodeContext {
this.deletionTime.set(deletionTime ?? clock.now().toUtc());
}

KdbxDeletedObject.read(XmlElement node, this.ctx) : super.read(node);
KdbxDeletedObject.read(super.node, this.ctx) : super.read();

static const NODE_NAME = KdbxXml.NODE_DELETED_OBJECT;

Expand Down
4 changes: 3 additions & 1 deletion lib/src/kdbx_entry.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import 'dart:collection';
import 'dart:convert';
import 'dart:typed_data';

import 'package:collection/collection.dart';
import 'package:kdbx/src/kee_vault_model/browser_entry_settings_v1.dart';
import 'package:kdbx/src/internal/extension_utils.dart';
import 'package:kdbx/src/kdbx_format.dart';
import 'package:kdbx/src/kdbx_object.dart';
import 'package:kdbx/src/kdbx_xml.dart';
import 'package:kdbx/src/kee_vault_model/browser_entry_settings_v1.dart';
import 'package:kdbx/src/utils/guid_service.dart';
import 'package:logging/logging.dart';
import 'package:path/path.dart' as path;
import 'package:quiver/check.dart';
import 'package:xml/xml.dart';

import '../kdbx.dart';

final _logger = Logger('kdbx.kdbx_entry');
Expand Down
4 changes: 2 additions & 2 deletions lib/src/kdbx_format.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ class KdbxBody extends KdbxNode {
}

KdbxBody.read(
xml.XmlElement node,
super.node,
this.meta,
this.rootGroup,
) : super.read(node);
) : super.read();

// final xml.XmlDocument xmlDocument;
final KdbxMeta meta;
Expand Down
4 changes: 2 additions & 2 deletions lib/src/kdbx_meta.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class KdbxMeta extends KdbxNode implements KdbxNodeContext {
historyMaxSize.set(Consts.DefaultHistoryMaxSize);
}

KdbxMeta.read(xml.XmlElement node, this.ctx)
KdbxMeta.read(super.node, this.ctx)
: customData = node
.singleElement(KdbxXml.NODE_CUSTOM_DATA)
?.let((e) => KdbxMetaCustomData.read(e)) ??
Expand Down Expand Up @@ -91,7 +91,7 @@ class KdbxMeta extends KdbxNode implements KdbxNodeContext {
.map((e) => MapEntry(e.uuid, e))
.let((that) => Map.fromEntries(that)) ??
{},
super.read(node);
super.read();

@override
final KdbxReadWriteContext ctx;
Expand Down
3 changes: 1 addition & 2 deletions lib/src/kdbx_times.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:kdbx/src/kdbx_object.dart';
import 'package:kdbx/src/kdbx_xml.dart';
import 'package:logging/logging.dart';
import 'package:quiver/iterables.dart';
import 'package:xml/xml.dart';

final _logger = Logger('kdbx_times');

Expand All @@ -19,7 +18,7 @@ class KdbxTimes extends KdbxNode implements KdbxNodeContext {
usageCount.set(0);
locationChanged.set(now);
}
KdbxTimes.read(XmlElement node, this.ctx) : super.read(node) {
KdbxTimes.read(super.node, this.ctx) : super.read() {
// backward compatibility - there was a bug setting/reading
// modification, lastAccess and expiryTime. Make sure they are defined.
final checkDates = {
Expand Down
20 changes: 10 additions & 10 deletions lib/src/kdbx_xml.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ extension on List<XmlNode> {
}

abstract class KdbxSubTextNode<T> extends KdbxSubNode<T?> {
KdbxSubTextNode(KdbxNode node, String name) : super(node, name);
KdbxSubTextNode(super.node, super.name);

void Function()? _onModify;

Expand Down Expand Up @@ -158,7 +158,7 @@ abstract class KdbxSubTextNode<T> extends KdbxSubNode<T?> {
}

class IntNode extends KdbxSubTextNode<int?> {
IntNode(KdbxNode node, String name) : super(node, name);
IntNode(super.node, super.name);

@override
int? decode(String value) => int.tryParse(value);
Expand All @@ -168,7 +168,7 @@ class IntNode extends KdbxSubTextNode<int?> {
}

class StringNode extends KdbxSubTextNode<String> {
StringNode(KdbxNode node, String name) : super(node, name);
StringNode(super.node, super.name);

@override
String decode(String value) => value;
Expand All @@ -178,7 +178,7 @@ class StringNode extends KdbxSubTextNode<String> {
}

class StringListNode extends KdbxSubTextNode<List<String>> {
StringListNode(KdbxNode node, String name) : super(node, name);
StringListNode(super.node, super.name);

@override
List<String> decode(String value) {
Expand All @@ -195,7 +195,7 @@ class StringListNode extends KdbxSubTextNode<List<String>> {
}

class Base64Node extends KdbxSubTextNode<ByteBuffer> {
Base64Node(KdbxNode node, String name) : super(node, name);
Base64Node(super.node, super.name);

@override
ByteBuffer decode(String value) => base64.decode(value).buffer;
Expand All @@ -205,7 +205,7 @@ class Base64Node extends KdbxSubTextNode<ByteBuffer> {
}

class UuidNode extends KdbxSubTextNode<KdbxUuid> {
UuidNode(KdbxNode node, String name) : super(node, name);
UuidNode(super.node, super.name);

@override
KdbxUuid decode(String value) => KdbxUuid(value);
Expand All @@ -215,7 +215,7 @@ class UuidNode extends KdbxSubTextNode<KdbxUuid> {
}

class IconNode extends KdbxSubTextNode<KdbxIcon> {
IconNode(KdbxNode node, String name) : super(node, name);
IconNode(super.node, super.name);

@override
KdbxIcon decode(String value) => KdbxIcon.values[int.tryParse(value) ?? 0];
Expand Down Expand Up @@ -243,7 +243,7 @@ class KdbxColor {

// Tolerates 6 digit hex strings but outputs more-compatible 7 char strings with leading #
class ColorNode extends KdbxSubTextNode<KdbxColor> {
ColorNode(KdbxNode node, String name) : super(node, name);
ColorNode(super.node, super.name);

@override
KdbxColor decode(String value) => KdbxColor.parse(value);
Expand All @@ -253,7 +253,7 @@ class ColorNode extends KdbxSubTextNode<KdbxColor> {
}

class NullableBooleanNode extends KdbxSubTextNode<bool?> {
NullableBooleanNode(KdbxNode node, String name) : super(node, name);
NullableBooleanNode(super.node, super.name);

@override
bool? decode(String value) {
Expand Down Expand Up @@ -284,7 +284,7 @@ class NullableBooleanNode extends KdbxSubTextNode<bool?> {
}

class DateTimeUtcNode extends KdbxSubTextNode<DateTime?> {
DateTimeUtcNode(KdbxNodeContext node, String name) : super(node, name);
DateTimeUtcNode(KdbxNodeContext super.node, super.name);

KdbxReadWriteContext get _ctx => (node as KdbxNodeContext).ctx;
static final minDate = DateTime.fromMillisecondsSinceEpoch(0, isUtc: true);
Expand Down
4 changes: 2 additions & 2 deletions lib/src/kee_vault_model/browser_entry_settings_v1.dart
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ class BrowserEntrySettingsV1 {
final List<Field> fields = [];
bool usernameFound = false;
bool passwordFound = false;
formFieldList.forEach((ff) {
for (final ff in formFieldList) {
if (ff.value == '{USERNAME}') {
usernameFound = true;
final mc = !((ff.fieldId?.isNotEmpty ?? false) ||
Expand Down Expand Up @@ -393,7 +393,7 @@ class BrowserEntrySettingsV1 {
}
fields.add(f);
}
});
}

if (!usernameFound) {
fields.add(Field(
Expand Down
32 changes: 16 additions & 16 deletions lib/src/kee_vault_model/entry_matcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ class EntryMatcher {
this.pageTitles = const [],
});

factory EntryMatcher.fromMap(Map<String, dynamic>? map) {
if (map == null) {
return EntryMatcher();
}

return EntryMatcher(
matchLogic: MatcherLogic.values
.firstWhereOrNull((v) => v.name == map['matchLogic']),
queries: (map['queries'] as List<dynamic>?)?.cast<String>() ?? [],
pageTitles: (map['pageTitles'] as List<dynamic>?)?.cast<String>() ?? [],
);
}

factory EntryMatcher.fromJson(String source) =>
EntryMatcher.fromMap(json.decode(source) as Map<String, dynamic>?);

EntryMatcher copyWith({
MatcherLogic? matchLogic,
List<String>? queries,
Expand All @@ -29,24 +45,8 @@ class EntryMatcher {
};
}

factory EntryMatcher.fromMap(Map<String, dynamic>? map) {
if (map == null) {
return EntryMatcher();
}

return EntryMatcher(
matchLogic: MatcherLogic.values
.firstWhereOrNull((v) => v.name == map['matchLogic']),
queries: (map['queries'] as List<dynamic>?)?.cast<String>() ?? [],
pageTitles: (map['pageTitles'] as List<dynamic>?)?.cast<String>() ?? [],
);
}

String toJson() => json.encode(toMap());

factory EntryMatcher.fromJson(String source) =>
EntryMatcher.fromMap(json.decode(source) as Map<String, dynamic>?);

@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
Expand Down
48 changes: 24 additions & 24 deletions lib/src/kee_vault_model/entry_matcher_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,30 @@ class EntryMatcherConfig {
this.actionOnNoMatch,
});

factory EntryMatcherConfig.fromMap(Map<String, dynamic>? map) {
if (map == null) {
return EntryMatcherConfig();
}

return EntryMatcherConfig(
matcherType: EntryMatcherType.values
.firstWhereOrNull((v) => v.name == map['matcherType']),
customMatcher: map['customMatcher'] != null
? EntryMatcher.fromMap(map['customMatcher'] as Map<String, dynamic>)
: null,
urlMatchMethod: MatchAccuracy.values
.firstWhereOrNull((v) => v.name == map['urlMatchMethod']),
weight: map['weight'] as int?,
actionOnMatch: MatchAction.values
.firstWhereOrNull((v) => v.name == map['actionOnMatch']),
actionOnNoMatch: MatchAction.values
.firstWhereOrNull((v) => v.name == map['actionOnNoMatch']),
);
}

factory EntryMatcherConfig.fromJson(String source) =>
EntryMatcherConfig.fromMap(json.decode(source) as Map<String, dynamic>);

EntryMatcherConfig.forDefaultUrlMatchBehaviour(MatchAccuracy ma)
: this(
matcherType: EntryMatcherType.Url,
Expand Down Expand Up @@ -50,32 +74,8 @@ class EntryMatcherConfig {
};
}

factory EntryMatcherConfig.fromMap(Map<String, dynamic>? map) {
if (map == null) {
return EntryMatcherConfig();
}

return EntryMatcherConfig(
matcherType: EntryMatcherType.values
.firstWhereOrNull((v) => v.name == map['matcherType']),
customMatcher: map['customMatcher'] != null
? EntryMatcher.fromMap(map['customMatcher'] as Map<String, dynamic>)
: null,
urlMatchMethod: MatchAccuracy.values
.firstWhereOrNull((v) => v.name == map['urlMatchMethod']),
weight: map['weight'] as int?,
actionOnMatch: MatchAction.values
.firstWhereOrNull((v) => v.name == map['actionOnMatch']),
actionOnNoMatch: MatchAction.values
.firstWhereOrNull((v) => v.name == map['actionOnNoMatch']),
);
}

String toJson() => json.encode(toMap());

factory EntryMatcherConfig.fromJson(String source) =>
EntryMatcherConfig.fromMap(json.decode(source) as Map<String, dynamic>);

@override
String toString() {
return 'EntryMatcherConfig(matcherType: $matcherType, customMatcher: $customMatcher, urlMatchMethod: $urlMatchMethod, weight: $weight, actionOnMatch: $actionOnMatch, actionOnNoMatch: $actionOnNoMatch)';
Expand Down
Loading

0 comments on commit b24b601

Please sign in to comment.