mirror of
https://github.com/mitchell/selfpass.git
synced 2025-12-14 21:27:22 +00:00
Add generatePassword; refactor GestureDetectors to CupertinoButton;
refactor hidden classes fields; refactor repositories to one library
This commit is contained in:
parent
67744527cc
commit
5a42345c08
11 changed files with 293 additions and 204 deletions
|
|
@ -1,3 +1,5 @@
|
|||
part of 'repositories.dart';
|
||||
|
||||
class ConfigBase {
|
||||
static const keyPrivateKey = "private_key";
|
||||
static const keyConnectionConfig = "connection_config";
|
||||
|
|
@ -11,8 +13,6 @@ class ConfigBase {
|
|||
return _password;
|
||||
}
|
||||
|
||||
set password(String password) => _password = password;
|
||||
|
||||
void checkIfPasswordMatched() {
|
||||
if (passwordMatched) return;
|
||||
throw Exception('password not matched yet');
|
||||
|
|
|
|||
|
|
@ -1,13 +1,4 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'config_base.dart';
|
||||
|
||||
import '../types/abstracts.dart';
|
||||
import '../types/connection_config.dart';
|
||||
|
||||
import '../utils/crypto.dart' as crypto;
|
||||
part of 'repositories.dart';
|
||||
|
||||
class EncryptedSharedPreferences extends ConfigBase implements ConfigRepo {
|
||||
@override
|
||||
|
|
@ -19,7 +10,7 @@ class EncryptedSharedPreferences extends ConfigBase implements ConfigRepo {
|
|||
|
||||
if (cipherText == null) return null;
|
||||
|
||||
final configJson = crypto.decrypt(cipherText, password);
|
||||
final configJson = crypto.decrypt(cipherText, _password);
|
||||
|
||||
return ConnectionConfig.fromJson(json.decode(configJson));
|
||||
}
|
||||
|
|
@ -44,7 +35,7 @@ class EncryptedSharedPreferences extends ConfigBase implements ConfigRepo {
|
|||
password,
|
||||
);
|
||||
|
||||
if (passwordMatched) this.password = password;
|
||||
if (passwordMatched) _password = password;
|
||||
|
||||
return passwordMatched;
|
||||
}
|
||||
|
|
@ -66,7 +57,7 @@ class EncryptedSharedPreferences extends ConfigBase implements ConfigRepo {
|
|||
final prefs = await SharedPreferences.getInstance();
|
||||
final cipherText = prefs.getString(ConfigBase.keyPrivateKey);
|
||||
|
||||
return crypto.decrypt(cipherText, password);
|
||||
return crypto.decrypt(cipherText, _password);
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
@ -79,7 +70,7 @@ class EncryptedSharedPreferences extends ConfigBase implements ConfigRepo {
|
|||
|
||||
prefs.setString(
|
||||
ConfigBase.keyConnectionConfig,
|
||||
crypto.encrypt(configJson, password),
|
||||
crypto.encrypt(configJson, _password),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -87,7 +78,7 @@ class EncryptedSharedPreferences extends ConfigBase implements ConfigRepo {
|
|||
Future<void> setPassword(String password) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
|
||||
this.password = password;
|
||||
_password = password;
|
||||
passwordMatched = true;
|
||||
|
||||
prefs.setString(ConfigBase.keyPassword, crypto.hashPassword(password));
|
||||
|
|
@ -97,6 +88,6 @@ class EncryptedSharedPreferences extends ConfigBase implements ConfigRepo {
|
|||
Future<void> setPrivateKey(String key) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
|
||||
prefs.setString(ConfigBase.keyPrivateKey, crypto.encrypt(key, password));
|
||||
prefs.setString(ConfigBase.keyPrivateKey, crypto.encrypt(key, _password));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,4 @@
|
|||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:grpc/grpc.dart';
|
||||
import 'package:selfpass_protobuf/credentials.pbgrpc.dart' as grpc;
|
||||
import 'package:selfpass_protobuf/credentials.pb.dart' as protobuf;
|
||||
|
||||
import '../types/abstracts.dart';
|
||||
import '../types/connection_config.dart';
|
||||
import '../types/credential.dart';
|
||||
part of 'repositories.dart';
|
||||
|
||||
class GRPCCredentialsClient implements CredentialsRepo {
|
||||
static GRPCCredentialsClient _instance;
|
||||
|
|
|
|||
20
client/lib/repositories/repositories.dart
Normal file
20
client/lib/repositories/repositories.dart
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
library repositories;
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:grpc/grpc.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:selfpass_protobuf/credentials.pbgrpc.dart' as grpc;
|
||||
import 'package:selfpass_protobuf/credentials.pb.dart' as protobuf;
|
||||
|
||||
import '../types/abstracts.dart';
|
||||
import '../types/connection_config.dart';
|
||||
import '../types/credential.dart';
|
||||
|
||||
import '../utils/crypto.dart' as crypto;
|
||||
|
||||
part 'config_base.dart';
|
||||
part 'encrypted_shared_preferences.dart';
|
||||
part 'grpc_credentials_client.dart';
|
||||
Loading…
Add table
Add a link
Reference in a new issue