Compare commits

..
Author SHA1 Message Date
Gwendal Roué 0fd36d4075 Merge pull request #1906 from sqlcipher/grdb8-sqlcipher5
[GRDB8] Fixes EncryptionTests for SQLCipher 5 -- changePassphrase within barrierWithoutTransaction
2026-12-03 15:58:49 +01:00
Micah Moore 0a2d5322f3 Adjusts README.md and DocC comments related to changePassphrase. 2026-12-03 09:13:17 -05:00
Micah Moore 76c46029e1 Fixes EncryptionTests for SQLCipher 5 -- changePassphrase within barrierWithoutTransaction
* Uses barrierWriteWithoutTransaction within EncryptionTests.testDatabaseQueueWithPassphraseToDatabaseQueueWithNewPassphrase and EncryptionTests.testDatabaseQueueWithDataPassphraseToDatabaseQueueWithNewDataPassphrase to avoid error when using SQLCipher 5 when trying to rekey a database inside a transaction: "sqlite3_rekey_v2: rekey can't be run inside a transaction". This change aligns with the other changePassphrase calls in EncryptionTests.
* Adjusts README.md to callout change passphrase must be performed outside of a transaction and adjusts change passphrase sample code.
* Adds "Must be run outside of a transaction" to Database.changePassphrase comments.
2026-12-03 09:13:17 -05:00
3 changed files with 8 additions and 4 deletions

No files matched your search

+2 -2
View File
@@ -4620,10 +4620,10 @@ See [SQLCipher 4.0.0 Release](https://www.zetetic.net/blog/2018/11/30/sqlcipher-
**You can change the passphrase** of an already encrypted database.
When you use a [database queue](https://swiftpackageindex.com/groue/GRDB.swift/documentation/grdb/databasequeue), open the database with the old passphrase, and then apply the new passphrase:
When you use a [database queue](https://swiftpackageindex.com/groue/GRDB.swift/documentation/grdb/databasequeue), open the database with the old passphrase, and then apply the new passphrase outside of a transaction:
```swift
try dbQueue.write { db in
try dbQueue.barrierWriteWithoutTransaction { db in
try db.changePassphrase("newSecret")
}
```
@@ -123,6 +123,8 @@ extension Database {
}
/// Changes the passphrase used by an SQLCipher encrypted database.
///
/// This method must be called outside of a transaction.
public func changePassphrase(_ passphrase: String) throws {
guard var data = passphrase.data(using: .utf8) else {
throw DatabaseError(message: "invalid passphrase")
@@ -134,6 +136,8 @@ extension Database {
}
/// Changes the passphrase used by an SQLCipher encrypted database.
///
/// This method must be called outside of a transaction.
public func changePassphrase(_ passphrase: Data) throws {
// FIXME: sqlite3_rekey is discouraged.
//
@@ -164,7 +164,7 @@ let testBundle = Bundle(for: GRDBTestCase.self)
try dbQueue.inDatabase { db in
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM data")!, 1)
}
try dbQueue.write { db in
try dbQueue.barrierWriteWithoutTransaction { db in
try db.changePassphrase("newSecret")
}
try dbQueue.inDatabase { db in
@@ -212,7 +212,7 @@ let testBundle = Bundle(for: GRDBTestCase.self)
try dbQueue.inDatabase { db in
XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM data")!, 1)
}
try dbQueue.write { db in
try dbQueue.barrierWriteWithoutTransaction { db in
try db.changePassphrase(finalPassphrase)
}
try dbQueue.inDatabase { db in