Skip to content

Commit

Permalink
chore: adressed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Desu Sai Venkat committed Oct 4, 2023
1 parent 294f4ab commit 7a25cea
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Sources/Classes/RSDBPersistentManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,17 @@ - (void)createDB:(RSDBEncryption * __nullable)dbEncryption {
- (BOOL)isEncryptionNeeded:(RSDBEncryption * __nullable)dbEncryption {
if (dbEncryption == nil)
return NO;
if (dbEncryption.enable && [dbEncryption.key length] > 0)
if (dbEncryption.enable && [self doesEncryptionKeyExists:dbEncryption])
return YES;
return NO;
}

- (BOOL)doesEncryptionKeyExists:(RSDBEncryption * __nullable)dbEncryption {
if (dbEncryption == nil || dbEncryption.key == nil || [dbEncryption.key length] == 0)
return NO;
return YES;
}

- (BOOL) isSQLCipherAvailable {
BOOL isSQLCipherAvailable = NO;
@try {
Expand Down Expand Up @@ -160,17 +166,17 @@ - (void)handleWhenEncryptedDBExists:(RSDBEncryption * _Nullable)dbEncryption isE
return;
}

// when encryption is disabled and no key is provided
// when encryption is not needed and no key is provided
// delete encrypted database; then open unencrypted database
// all previous events will be deleted
if (dbEncryption == nil || dbEncryption.key == nil) {
if (![self doesEncryptionKeyExists:dbEncryption]) {
[RSLogger logError:@"RSDBPersistentManager: createDB: No key is provided. Deleting encrypted DB and creating a new unencrypted DB"];
[RSUtils removeFile:ENCRYPTED_DB_NAME];
[self openUnencryptedDB];
return;
}

// when encryption is disabled and a key is provided
// when encryption is not needed and a key is provided
int code = [self openEncryptedDB:dbEncryption.key];
switch (code) {
// when key is correct
Expand Down

0 comments on commit 7a25cea

Please sign in to comment.