@capacitor-community/sqlite 4.6.1-2 → 4.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -258,6 +258,32 @@ enum CapacitorSQLiteError: Error {
258
258
  }
259
259
  }
260
260
 
261
+ // MARK: - CheckEncryptionSecret
262
+
263
+ @objc public func checkEncryptionSecret(passphrase: String) throws -> NSNumber {
264
+ if isInit {
265
+ if isEncryption {
266
+ do {
267
+ // close all connections
268
+ try closeAllConnections()
269
+ // check encryption secret
270
+ let res: NSNumber = try UtilsSecret
271
+ .checkEncryptionSecret(prefix: prefixKeychain,
272
+ passphrase: passphrase)
273
+ return res
274
+ } catch UtilsSecretError.checkEncryptionSecret(let message) {
275
+ throw CapacitorSQLiteError.failed(message: message)
276
+ } catch let error {
277
+ throw CapacitorSQLiteError.failed(message: "\(error)")
278
+ }
279
+ } else {
280
+ throw CapacitorSQLiteError.failed(message: "No Encryption set in capacitor.config")
281
+ }
282
+ } else {
283
+ throw CapacitorSQLiteError.failed(message: initMessage)
284
+ }
285
+ }
286
+
261
287
  // MARK: - getNCDatabasePath
262
288
 
263
289
  @objc public func getNCDatabasePath(_ folderPath: String, dbName: String ) throws -> String {
@@ -45,4 +45,5 @@ CAP_PLUGIN(CapacitorSQLitePlugin, "CapacitorSQLite",
45
45
  CAP_PLUGIN_METHOD(changeEncryptionSecret, CAPPluginReturnPromise);
46
46
  CAP_PLUGIN_METHOD(clearEncryptionSecret, CAPPluginReturnPromise);
47
47
  CAP_PLUGIN_METHOD(getFromHTTPRequest, CAPPluginReturnPromise);
48
+ CAP_PLUGIN_METHOD(checkEncryptionSecret, CAPPluginReturnPromise);
48
49
  )
@@ -143,6 +143,37 @@ public class CapacitorSQLitePlugin: CAPPlugin {
143
143
  }
144
144
  }
145
145
 
146
+ // MARK: - CheckEncryptionSecret
147
+
148
+ @objc func checkEncryptionSecret(_ call: CAPPluginCall) {
149
+
150
+ guard let passphrase = call.options["passphrase"] as? String else {
151
+ retHandler.rResult(
152
+ call: call,
153
+ message: "CheckEncryptionSecret: Must provide a passphrase")
154
+ return
155
+ }
156
+ do {
157
+ let res = try implementation?
158
+ .checkEncryptionSecret(passphrase: passphrase)
159
+ var bRes: Bool = false
160
+ if res == 1 {
161
+ bRes = true
162
+ }
163
+ retHandler.rResult(call: call, ret: bRes)
164
+ return
165
+ } catch CapacitorSQLiteError.failed(let message) {
166
+ let msg = "CheckEncryptionSecret: \(message)"
167
+ retHandler.rResult(call: call, message: msg)
168
+ return
169
+ } catch let error {
170
+ retHandler.rResult(
171
+ call: call,
172
+ message: "CheckEncryptionSecret: \(error)")
173
+ return
174
+ }
175
+ }
176
+
146
177
  // MARK: - CreateConnection
147
178
 
148
179
  @objc func createConnection(_ call: CAPPluginCall) {
@@ -15,6 +15,7 @@ enum UtilsSecretError: Error {
15
15
  case setEncryptionSecret(message: String)
16
16
  case changeEncryptionSecret(message: String)
17
17
  case clearEncryptionSecret(message: String)
18
+ case checkEncryptionSecret(message: String)
18
19
  }
19
20
 
20
21
  let oldAccount: String = "CapacitorSQLitePlugin"
@@ -259,4 +260,29 @@ class UtilsSecret {
259
260
  }
260
261
 
261
262
  }
263
+
264
+ // MARK: - CheckEncryptionSecret
265
+
266
+ class func checkEncryptionSecret(prefix: String, passphrase: String) throws -> NSNumber {
267
+ var ret: NSNumber = 0
268
+ if prefix.isEmpty {
269
+ let msg: String = "keychain prefix must not be empty"
270
+ throw UtilsSecretError.checkEncryptionSecret(message: msg)
271
+ }
272
+ if passphrase.isEmpty {
273
+ let msg: String = "passphrase must not be empty"
274
+ throw UtilsSecretError.checkEncryptionSecret(message: msg)
275
+ }
276
+ // get encrypted passphrase
277
+ let account = "\(prefix)_\(oldAccount)"
278
+ let storedPassPhrase = getPassphrase(account: account)
279
+ if storedPassPhrase.isEmpty {
280
+ let msg: String = "no passphrase stored in keychain"
281
+ throw UtilsSecretError.checkEncryptionSecret(message: msg)
282
+ }
283
+ if storedPassPhrase == passphrase {
284
+ ret = 1
285
+ }
286
+ return ret
287
+ }
262
288
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor-community/sqlite",
3
- "version": "4.6.1-2",
3
+ "version": "4.6.1",
4
4
  "description": "Community plugin for native & electron SQLite databases",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",