mirror of
https://github.com/mitchell/selfpass.git
synced 2025-12-16 22:07:22 +00:00
Add automatic background lock to home screen; refactor repo names
This commit is contained in:
parent
27215e6596
commit
474f0c056b
10 changed files with 74 additions and 44 deletions
|
|
@ -11,11 +11,11 @@ import '../types/abstracts.dart';
|
|||
import '../types/connection_config.dart';
|
||||
import '../types/credential.dart';
|
||||
|
||||
class CredentialsClient implements CredentialsRepo {
|
||||
static CredentialsClient _cached;
|
||||
class GRPCCredentialsClient implements CredentialsRepo {
|
||||
static GRPCCredentialsClient _cached;
|
||||
grpc.CredentialServiceClient _client;
|
||||
|
||||
CredentialsClient(ConnectionConfig config) {
|
||||
GRPCCredentialsClient(ConnectionConfig config) {
|
||||
final caCert = utf8.encode(config.caCertificate);
|
||||
final cert = utf8.encode(config.certificate);
|
||||
final privateCert = utf8.encode(config.privateCertificate);
|
||||
|
|
@ -33,8 +33,8 @@ class CredentialsClient implements CredentialsRepo {
|
|||
));
|
||||
}
|
||||
|
||||
factory CredentialsClient.cached({ConnectionConfig config}) =>
|
||||
_cached == null ? _cached = CredentialsClient(config) : _cached;
|
||||
factory GRPCCredentialsClient.cached({ConnectionConfig config}) =>
|
||||
config == null ? _cached : _cached = GRPCCredentialsClient(config);
|
||||
|
||||
Stream<Metadata> getAllMetadata(String sourceHost) {
|
||||
final request = grpc.GetAllMetadataRequest();
|
||||
|
|
@ -7,11 +7,13 @@ import '../types/connection_config.dart';
|
|||
|
||||
import '../utils/crypto.dart' as crypto;
|
||||
|
||||
class Config implements ConfigRepo {
|
||||
class SecureStorageConfig implements ConfigRepo {
|
||||
static const _keyPrivateKey = "private_key";
|
||||
static const _keyConnectionConfig = "connection_config";
|
||||
static const _keyPassword = "password";
|
||||
final FlutterSecureStorage _storage = FlutterSecureStorage();
|
||||
|
||||
final _storage = FlutterSecureStorage();
|
||||
|
||||
bool _passwordMatched = false;
|
||||
String _password;
|
||||
|
||||
|
|
@ -32,13 +34,15 @@ class Config implements ConfigRepo {
|
|||
|
||||
Future<void> setPassword(String password) {
|
||||
_checkIfPasswordMatched();
|
||||
|
||||
_password = password;
|
||||
|
||||
return _storage.write(
|
||||
key: _keyPassword, value: crypto.hashPassword(password));
|
||||
}
|
||||
|
||||
Future<bool> get passwordSet async {
|
||||
var passHash = await _storage.read(key: _keyPassword);
|
||||
Future<bool> get passwordIsSet async {
|
||||
final passHash = await _storage.read(key: _keyPassword);
|
||||
|
||||
if (passHash != null) {
|
||||
return true;
|
||||
|
|
@ -53,9 +57,7 @@ class Config implements ConfigRepo {
|
|||
_passwordMatched = crypto.matchHashedPassword(
|
||||
await _storage.read(key: _keyPassword), password);
|
||||
|
||||
if (_passwordMatched) {
|
||||
_password = password;
|
||||
}
|
||||
if (_passwordMatched) _password = password;
|
||||
|
||||
return _passwordMatched;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue