File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,10 @@ extension Connection {
26
26
27
27
public func key( key: String ) throws {
28
28
try check ( sqlite3_key ( handle, key, Int32 ( key. utf8. count) ) )
29
+ try execute (
30
+ " CREATE TABLE \" __SQLCipher.swift__ \" ( \" cipher key check \" ); \n " +
31
+ " DROP TABLE \" __SQLCipher.swift__ \" ; "
32
+ )
29
33
}
30
34
31
35
public func rekey( key: String ) throws {
Original file line number Diff line number Diff line change @@ -15,12 +15,34 @@ class CipherTests: XCTestCase {
15
15
}
16
16
17
17
func test_key( ) {
18
- XCTAssertEqual ( 1 , try ! db. scalar ( " SELECT count(*) FROM foo " ) as! Int64 )
18
+ XCTAssertEqual ( 1 , db. scalar ( " SELECT count(*) FROM foo " ) as? Int64 )
19
19
}
20
20
21
21
func test_rekey( ) {
22
22
try ! db. rekey ( " goodbye " )
23
- XCTAssertEqual ( 1 , try ! db. scalar ( " SELECT count(*) FROM foo " ) as! Int64 )
23
+ XCTAssertEqual ( 1 , db. scalar ( " SELECT count(*) FROM foo " ) as? Int64 )
24
+ }
25
+
26
+ func test_keyFailure( ) {
27
+ let path = " \( NSTemporaryDirectory ( ) ) /db.sqlite3 "
28
+ _ = try ? NSFileManager . defaultManager ( ) . removeItemAtPath ( path)
29
+
30
+ let connA = try ! Connection ( path)
31
+ defer { try ! NSFileManager . defaultManager ( ) . removeItemAtPath ( path) }
32
+
33
+ try ! connA. key ( " hello " )
34
+
35
+ let connB = try ! Connection ( path)
36
+
37
+ var rc : Int32 ?
38
+ do {
39
+ try connB. key ( " world " )
40
+ } catch Result . Error( _, let code, _) {
41
+ rc = code
42
+ } catch {
43
+ XCTFail ( )
44
+ }
45
+ XCTAssertEqual ( SQLITE_NOTADB, rc)
24
46
}
25
47
26
48
}
You can’t perform that action at this time.
0 commit comments