generateAndSaveSecureKeyIfNotExist method

Future<void> generateAndSaveSecureKeyIfNotExist()

This method reads the secure key from the secure storage. If the key does not exist, it generates a new key and saves it to the secure storage. If the key already exists, this method does nothing.

Throws a DatabaseServiceException if an error occurs while reading or writing the secure key.

Implementation

Future<void> generateAndSaveSecureKeyIfNotExist() async {
  try {
    final secureStorageKey = await _secureStorage.read(key: _secureKey);
    if (secureStorageKey == null) {
      await _writeSecureKey();
    }
  } catch (e) {
    throw DatabaseBridgeException(error: e);
  }
}