Skip to content

Commit

Permalink
Add few utility functions to local_secret.dart
Browse files Browse the repository at this point in the history
  • Loading branch information
inetic committed Feb 20, 2024
1 parent 35601ac commit 8354ec2
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions bindings/dart/lib/local_secret.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ sealed class LocalSecret {
sealed class SetLocalSecret {
Object? encode();

LocalSecret toLocalSecret();

@override
String toString();
}
Expand All @@ -24,6 +26,11 @@ class LocalPassword implements LocalSecret, SetLocalSecret {
int get length => string.length;
bool get isEmpty => string.isEmpty;

@override
LocalSecret toLocalSecret() {
return this;
}

@override
Object? encode() => {'password': string};

Expand Down Expand Up @@ -63,6 +70,14 @@ class LocalSecretKeyAndSalt implements SetLocalSecret {

LocalSecretKeyAndSalt(this.key, this.salt);

static LocalSecretKeyAndSalt random() =>
LocalSecretKeyAndSalt(LocalSecretKey.random(), PasswordSalt.random());

@override
LocalSecret toLocalSecret() {
return key;
}

@override
Object? encode() => {
'key_and_salt': {'key': key.bytes, 'salt': salt.bytes}
Expand Down

0 comments on commit 8354ec2

Please sign in to comment.