TF-886 Store encryptionKey in Hive database

This commit is contained in:
dab246
2022-09-07 10:35:12 +07:00
committed by Dat H. Pham
parent f1e512148d
commit 6018cd383a
11 changed files with 209 additions and 21 deletions
@@ -0,0 +1,18 @@
import 'package:tmail_ui_user/features/caching/encryption_key_cache_client.dart';
import 'package:tmail_ui_user/features/login/data/model/encryption_key_cache.dart';
class EncryptionKeyCacheManager {
final EncryptionKeyCacheClient _encryptionKeyCacheClient;
EncryptionKeyCacheManager(this._encryptionKeyCacheClient);
Future<void> storeEncryptionKey(EncryptionKeyCache encryptionKeyCache) {
return _encryptionKeyCacheClient.insertItem(
EncryptionKeyCache.keyCacheValue,
encryptionKeyCache);
}
Future<EncryptionKeyCache?> getEncryptionKeyStored() {
return _encryptionKeyCacheClient.getItem(EncryptionKeyCache.keyCacheValue);
}
}
@@ -0,0 +1,19 @@
import 'package:equatable/equatable.dart';
import 'package:hive/hive.dart';
import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart';
part 'encryption_key_cache.g.dart';
@HiveType(typeId: CachingConstants.ENCRYPTION_KEY_HIVE_CACHE_IDENTIFY)
class EncryptionKeyCache extends HiveObject with EquatableMixin {
static const String keyCacheValue = 'hiveEncryptionKey';
@HiveField(0)
final String value;
EncryptionKeyCache(this.value);
@override
List<Object?> get props => [value];
}
@@ -1,5 +1,4 @@
class LoginConstant {
static const String keyBaseUrl = 'KEY_BASE_URL';
static const String keyHiveEncrypt = 'KEY_HIVE_ENCRYPT';
}