@@ -5,7 +5,6 @@ import 'dart:io';
5
5
6
6
import 'package:flutter/foundation.dart' ;
7
7
import 'package:flutter/material.dart' ;
8
- import 'package:flutter_secure_storage/flutter_secure_storage.dart' ;
9
8
import 'package:logging/logging.dart' ;
10
9
import 'package:nextcloud/provisioning_api.dart' ;
11
10
import 'package:perfect_freehand/perfect_freehand.dart' ;
@@ -18,6 +17,7 @@ import 'package:saber/data/tools/highlighter.dart';
18
17
import 'package:saber/data/tools/pen.dart' ;
19
18
import 'package:shared_preferences/shared_preferences.dart' ;
20
19
import 'package:stow/stow.dart' ;
20
+ import 'package:stow_secure/stow_secure.dart' ;
21
21
22
22
typedef Quota = UserDetailsQuota ;
23
23
@@ -49,18 +49,18 @@ class Stows {
49
49
PlainPref <String ?>('customDataDir' , null , autoRead: _isOnMainIsolate);
50
50
51
51
final allowInsecureConnections =
52
- EncPref ('allowInsecureConnections' , false , autoRead: _isOnMainIsolate);
53
- final url = EncPref ('url' , '' , autoRead: _isOnMainIsolate);
54
- final username = EncPref ('username' , '' , autoRead: _isOnMainIsolate);
52
+ SecureStow ('allowInsecureConnections' , false , autoRead: _isOnMainIsolate);
53
+ final url = SecureStow ('url' , '' , autoRead: _isOnMainIsolate);
54
+ final username = SecureStow ('username' , '' , autoRead: _isOnMainIsolate);
55
55
56
56
/// the password used to login to Nextcloud
57
- final ncPassword = EncPref ('ncPassword' , '' , autoRead: _isOnMainIsolate);
57
+ final ncPassword = SecureStow ('ncPassword' , '' , autoRead: _isOnMainIsolate);
58
58
// TODO(adil192): maybe deprecate?
59
59
final ncPasswordIsAnAppPassword =
60
60
PlainPref ('ncPasswordIsAnAppPassword' , false , autoRead: _isOnMainIsolate);
61
61
62
62
/// the password used to encrypt/decrypt notes
63
- final encPassword = EncPref ('encPassword' , '' , autoRead: _isOnMainIsolate);
63
+ final encPassword = SecureStow ('encPassword' , '' , autoRead: _isOnMainIsolate);
64
64
65
65
/// Whether the user is logged in and has provided both passwords.
66
66
/// Please ensure that the relevant Prefs are loaded before using this.
@@ -69,8 +69,8 @@ class Stows {
69
69
ncPassword.value.isNotEmpty &&
70
70
encPassword.value.isNotEmpty;
71
71
72
- final key = EncPref ('key' , '' , autoRead: _isOnMainIsolate);
73
- final iv = EncPref ('iv' , '' , autoRead: _isOnMainIsolate);
72
+ final key = SecureStow ('key' , '' , autoRead: _isOnMainIsolate);
73
+ final iv = SecureStow ('iv' , '' , autoRead: _isOnMainIsolate);
74
74
75
75
final pfp = PlainPref <Uint8List ?>('pfp' , null , autoRead: _isOnMainIsolate);
76
76
final syncInBackground =
@@ -427,67 +427,6 @@ class PlainPref<T> extends IPref<T> {
427
427
}
428
428
}
429
429
430
- class EncPref <T > extends IPref <T > {
431
- FlutterSecureStorage ? _storage;
432
-
433
- EncPref (
434
- super .key,
435
- super .defaultValue, {
436
- super .codec,
437
- super .autoRead,
438
- }) {
439
- assert (T == String || T == typeOf <List <String >>() || T == bool );
440
- }
441
-
442
- @override
443
- Future protectedWrite (T value) async {
444
- _storage ?? = const FlutterSecureStorage ();
445
- if (T == String )
446
- return await _storage! .write (key: key, value: value as String );
447
- if (T == bool )
448
- return await _storage! .write (key: key, value: jsonEncode (value));
449
- return await _storage! .write (key: key, value: jsonEncode (value));
450
- }
451
-
452
- @override
453
- Future <T > protectedRead () async {
454
- if (! _isOnMainIsolate) return defaultValue;
455
-
456
- try {
457
- final String ? value = await _storage! .read (key: key);
458
- return _parseString (value) ?? defaultValue;
459
- } catch (e) {
460
- stows.log.severe ('Error loading $key : $e ' , e);
461
- return defaultValue;
462
- }
463
- }
464
-
465
- T ? _parseString (String ? value) {
466
- if (value == null || value.isEmpty) return null ;
467
-
468
- if (T == String ) {
469
- return value as T ;
470
- } else if (T == bool ) {
471
- return jsonDecode (value) as T ;
472
- } else {
473
- return List <String >.from (jsonDecode (value)) as T ;
474
- }
475
- }
476
-
477
- @override
478
- Future <void > delete () async {
479
- if (! _isOnMainIsolate) return ;
480
-
481
- _storage ?? = const FlutterSecureStorage ();
482
- await _storage! .delete (key: key);
483
- }
484
-
485
- @override
486
- String toString () {
487
- return 'EncPref<$T >($key , $value , $codec )' ;
488
- }
489
- }
490
-
491
430
/// An [IPref] that transforms the value of another [IPref] .
492
431
///
493
432
/// Only instantiate this once during the lifetime of the app
0 commit comments