Herbert Poul
4 years ago
5 changed files with 76 additions and 28 deletions
@ -0,0 +1,41 @@
|
||||
import 'package:kdbx/src/crypto/protected_value.dart'; |
||||
import 'package:kdbx/src/internal/extension_utils.dart'; |
||||
import 'package:kdbx/src/kdbx_entry.dart'; |
||||
import 'package:kdbx/src/kdbx_group.dart'; |
||||
|
||||
class KdbxPrintUtils { |
||||
KdbxPrintUtils({ |
||||
this.forceDecrypt = false, |
||||
this.allFields = false, |
||||
}); |
||||
final bool forceDecrypt; |
||||
final bool allFields; |
||||
|
||||
String catGroupToString(KdbxGroup group) => |
||||
(StringBuffer()..let((that) => catGroup(that, group))).toString(); |
||||
|
||||
void catGroup(StringBuffer buf, KdbxGroup group, {int depth = 0}) { |
||||
final indent = ' ' * depth; |
||||
buf.writeln('$indent + ${group.name.get()} (${group.uuid})'); |
||||
for (final group in group.groups) { |
||||
catGroup(buf, group, depth: depth + 1); |
||||
} |
||||
final valueToSting = (StringValue value) => |
||||
forceDecrypt ? value?.getText() : value?.toString(); |
||||
|
||||
for (final entry in group.entries) { |
||||
final value = entry.getString(KdbxKey('Password')); |
||||
buf.writeln('$indent `- ${entry.debugLabel()}: ' |
||||
'${valueToSting(value)}'); |
||||
if (allFields) { |
||||
buf.writeln(entry.stringEntries |
||||
.map((field) => |
||||
'$indent ${field.key} = ${valueToSting(field.value)}') |
||||
.join('\n')); |
||||
} |
||||
buf.writeln(entry.binaryEntries |
||||
.map((b) => '$indent `- file: ${b.key} - ${b.value.value.length}') |
||||
.join('\n')); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue