Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XCode9-beta: Implicit declaration of function 'sqlite3_key'

I am having an issue with EncryptedStore SQLCipher wrapper to encrypt core data.
I've added C-flags for this as:

Debug = -DSQLITE_HAS_CODEC -DSQLITE_TEMP_STORE=2 -DSQLITE_THREADSAFE -DSQLCIPHER_CRYPTO_CC
Release = -DSQLITE_HAS_CODEC -DNDEBUG -DSQLITE_OS_UNIX=1 -DSQLITE_TEMP_STORE=2 -DSQLITE_THREADSAFE -DSQLCIPHER_CRYPTO_CC

And used it as:

func encryptedCoordinator() -> NSPersistentStoreCoordinator {
  var coordinator:NSPersistentStoreCoordinator?
  let ops:[String : Any] =    [NSMigratePersistentStoresAutomaticallyOption:(true),                                              NSInferMappingModelAutomaticallyOption:(true), EncryptedStorePassphraseKey:sqlCipherKey, EncryptedStoreDatabaseLocation:self.sqliteFileURL()]

  do {
      coordinator = try EncryptedStore.make(options: ops, managedObjectModel: self.managedObjectModel, error: ())
    }catch {
      fatalError("Error opening encrypted DB: \(error)")
    }
    return coordinator!
  }

It is working fine in XCode8, but it's giving error in XCode9-beta.
Error line:

- (BOOL)changeDatabasePassphrase:(NSString *)passphrase error:(NSError *__autoreleasing*)error {
  BOOL result;
  int status;
  if ([passphrase length] > 0) {
    // Password provided, use it to key the DB
    const char *string = [passphrase UTF8String];
    status = sqlite3_rekey(database, string, (int)strlen(string));//ERROR line
    string = NULL;
    passphrase = nil;
  } else {
    // No password
    status = SQLITE_OK;
  }
  result = status == SQLITE_OK;
  if (result) {
    result = [self checkDatabaseStatusWithError:error];
  }
return result && (*error == nil);
}

Function is declared in EncryptedStroe/sqlite3.h as:

SQLITE_API int sqlite3_rekey(
sqlite3 *db,                   /* Database to be rekeyed */
  const void *pKey, int nKey     /* The new key */
);
SQLITE_API int sqlite3_rekey_v2(
  sqlite3 *db,                   /* Database to be rekeyed */
  const char *zDbName,           /* Name of the database */
  const void *pKey, int nKey     /* The new key */
);
like image 305
D4ttatraya Avatar asked Jun 18 '26 04:06

D4ttatraya


2 Answers

I think the problem is the import EncryptedStore.m file does: #import <sqlite3.h>

It uses <> so the system sqlite library is imported, which doesn't include these functions. By changing <> with "" everything compiles fine.

like image 171
Ignacio Delgado Avatar answered Jun 23 '26 06:06

Ignacio Delgado


Found another solution here.

Mainly changing the Header Search Paths.
Try changing it from $(PROJECT_DIR)/sqlcipher/src
to $(PROJECT_DIR)/sqlcipher
(i.e. remove the /src from the path)." Did the trick for me.

like image 42
CharlieReed Avatar answered Jun 23 '26 05:06

CharlieReed