@capacitor-community/sqlite 4.6.2-1 → 4.6.2-2

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.
@@ -606,6 +606,34 @@ enum CapacitorSQLiteError: Error {
606
606
  }
607
607
  }
608
608
 
609
+ // MARK: - IsDatabaseEncrypted
610
+
611
+ @objc public func isDatabaseEncrypted(_ dbName: String) throws -> NSNumber {
612
+ if isInit {
613
+ let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
614
+ let isFileExists: Bool = UtilsFile
615
+ .isFileExist(databaseLocation: databaseLocation,
616
+ fileName: mDbName + "SQLite.db")
617
+ if isFileExists {
618
+ let state: State = UtilsSQLCipher
619
+ .getDatabaseState(databaseLocation: databaseLocation,
620
+ databaseName: mDbName + "SQLite.db",
621
+ account: account)
622
+ if state.rawValue == "ENCRYPTEDGLOBALSECRET" || state.rawValue == "ENCRYPTEDSECRET" {
623
+ return 1;
624
+ }
625
+ if state.rawValue == "UNENCRYPTED" {
626
+ return 0;
627
+ }
628
+ throw CapacitorSQLiteError.failed(message: "Database unknown")
629
+ } else {
630
+ throw CapacitorSQLiteError.failed(message: "Database does not exist")
631
+ }
632
+ } else {
633
+ throw CapacitorSQLiteError.failed(message: initMessage)
634
+ }
635
+ }
636
+
609
637
  // MARK: - IsNCDatabase
610
638
 
611
639
  @objc public func isNCDatabase(_ databasePath: String) throws -> NSNumber {
@@ -46,4 +46,7 @@ CAP_PLUGIN(CapacitorSQLitePlugin, "CapacitorSQLite",
46
46
  CAP_PLUGIN_METHOD(clearEncryptionSecret, CAPPluginReturnPromise);
47
47
  CAP_PLUGIN_METHOD(getFromHTTPRequest, CAPPluginReturnPromise);
48
48
  CAP_PLUGIN_METHOD(checkEncryptionSecret, CAPPluginReturnPromise);
49
+ CAP_PLUGIN_METHOD(isInConfigEncryption, CAPPluginReturnPromise);
50
+ CAP_PLUGIN_METHOD(isInConfigBiometricAuth, CAPPluginReturnPromise);
51
+ CAP_PLUGIN_METHOD(isDatabaseEncrypted, CAPPluginReturnPromise);
49
52
  )
@@ -41,6 +41,56 @@ public class CapacitorSQLitePlugin: CAPPlugin {
41
41
  }
42
42
  }
43
43
 
44
+ // MARK: - IsInConfigEncryption
45
+
46
+ @objc func isInConfigEncryption(_ call: CAPPluginCall) {
47
+ var bRes: Bool = false
48
+ if self.config?.iosIsEncryption == 1 {
49
+ bRes = true
50
+ }
51
+
52
+ retHandler.rResult(call: call, ret: bRes)
53
+ }
54
+
55
+ // MARK: - IsInConfigBiometricAuth
56
+
57
+ @objc func isInConfigBiometricAuth(_ call: CAPPluginCall) {
58
+ var bRes: Bool = false
59
+ if self.config?.biometricAuth == 1 {
60
+ bRes = true
61
+ }
62
+
63
+ retHandler.rResult(call: call, ret: bRes)
64
+ }
65
+ // MARK: - IsDatabaseEncrypted
66
+
67
+ @objc func isDatabaseEncrypted(_ call: CAPPluginCall) {
68
+ guard let dbName = call.options["database"] as? String else {
69
+ retHandler.rResult(
70
+ call: call, ret: false,
71
+ message: "isDatabaseEncrypted: Must provide a database name")
72
+ return
73
+ }
74
+ do {
75
+ let res = try implementation?.isDatabaseEncrypted(dbName)
76
+ var bRes: Bool = false
77
+ if res == 1 {
78
+ bRes = true
79
+ }
80
+ retHandler.rResult(call: call, ret: bRes)
81
+ } catch CapacitorSQLiteError.failed(let message) {
82
+ let msg = "isDatabaseEncrypted: \(message)"
83
+ retHandler.rResult(call: call, message: msg)
84
+ return
85
+ } catch let error {
86
+ retHandler.rResult(
87
+ call: call,
88
+ message: "isDatabaseEncrypted: \(error)")
89
+ return
90
+ }
91
+
92
+ }
93
+
44
94
  // MARK: - IsSecretStored
45
95
 
46
96
  @objc func isSecretStored(_ call: CAPPluginCall) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor-community/sqlite",
3
- "version": "4.6.2-1",
3
+ "version": "4.6.2-2",
4
4
  "description": "Community plugin for native & electron SQLite databases",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -158,6 +158,25 @@ export interface CapacitorSQLitePlugin {
158
158
  * @since 3.0.0-beta.5
159
159
  */
160
160
  isDBOpen(options: capSQLiteOptions): Promise<capSQLiteResult>;
161
+ /**
162
+ * Check if a SQLite database is encrypted
163
+ * @param options: capSQLiteOptions
164
+ * @returns Promise<capSQLiteResult>
165
+ * @since 4.6.2-2
166
+ */
167
+ isDatabaseEncrypted(options: capSQLiteOptions): Promise<capSQLiteResult>;
168
+ /**
169
+ * Check encryption value in capacitor.config
170
+ * @returns Promise<capSQLiteResult>
171
+ * @since 4.6.2-2
172
+ */
173
+ isInConfigEncryption(): Promise<capSQLiteResult>;
174
+ /**
175
+ * Check encryption value in capacitor.config
176
+ * @returns Promise<capSQLiteResult>
177
+ * @since 4.6.2-2
178
+ */
179
+ isInConfigBiometricAuth(): Promise<capSQLiteResult>;
161
180
  /**
162
181
  * Check if a SQLite database exists without connection
163
182
  * @param options: capSQLiteOptions
@@ -1054,6 +1073,25 @@ export interface ISQLiteConnection {
1054
1073
  * @since 4.1.1
1055
1074
  */
1056
1075
  getFromHTTPRequest(url?: string, overwrite?: boolean): Promise<void>;
1076
+ /**
1077
+ * Check if a SQLite database is encrypted
1078
+ * @param options: capSQLiteOptions
1079
+ * @returns Promise<capSQLiteResult>
1080
+ * @since 4.6.2-2
1081
+ */
1082
+ isDatabaseEncrypted(database: string): Promise<capSQLiteResult>;
1083
+ /**
1084
+ * Check encryption value in capacitor.config
1085
+ * @returns Promise<capSQLiteResult>
1086
+ * @since 4.6.2-2
1087
+ */
1088
+ isInConfigEncryption(): Promise<capSQLiteResult>;
1089
+ /**
1090
+ * Check encryption value in capacitor.config
1091
+ * @returns Promise<capSQLiteResult>
1092
+ * @since 4.6.2-2
1093
+ */
1094
+ isInConfigBiometricAuth(): Promise<capSQLiteResult>;
1057
1095
  /**
1058
1096
  * Check if a database exists
1059
1097
  * @param database
@@ -1418,6 +1456,31 @@ export class SQLiteConnection implements ISQLiteConnection {
1418
1456
  return Promise.reject(err);
1419
1457
  }
1420
1458
  }
1459
+ async isDatabaseEncrypted(database: string): Promise<capSQLiteResult> {
1460
+ if (database.endsWith('.db')) database = database.slice(0, -3);
1461
+ try {
1462
+ const res = await this.sqlite.isDatabaseEncrypted({ database: database });
1463
+ return Promise.resolve(res);
1464
+ } catch (err) {
1465
+ return Promise.reject(err);
1466
+ }
1467
+ }
1468
+ async isInConfigEncryption(): Promise<capSQLiteResult> {
1469
+ try {
1470
+ const res = await this.sqlite.isInConfigEncryption();
1471
+ return Promise.resolve(res);
1472
+ } catch (err) {
1473
+ return Promise.reject(err);
1474
+ }
1475
+ }
1476
+ async isInConfigBiometricAuth(): Promise<capSQLiteResult> {
1477
+ try {
1478
+ const res = await this.sqlite.isInConfigBiometricAuth();
1479
+ return Promise.resolve(res);
1480
+ } catch (err) {
1481
+ return Promise.reject(err);
1482
+ }
1483
+ }
1421
1484
  async isDatabase(database: string): Promise<capSQLiteResult> {
1422
1485
  if (database.endsWith('.db')) database = database.slice(0, -3);
1423
1486
  try {
package/src/web.ts CHANGED
@@ -536,4 +536,17 @@ export class CapacitorSQLiteWeb
536
536
  console.log('isNCDatabase', options);
537
537
  throw this.unimplemented('Not implemented on web.');
538
538
  }
539
+
540
+ async isDatabaseEncrypted(options: capSQLiteOptions): Promise<capSQLiteResult> {
541
+ console.log('isDatabaseEncrypted', options);
542
+ throw this.unimplemented('Not implemented on web.');
543
+ }
544
+
545
+ async isInConfigEncryption(): Promise<capSQLiteResult> {
546
+ throw this.unimplemented('Not implemented on web.');
547
+ }
548
+
549
+ async isInConfigBiometricAuth(): Promise<capSQLiteResult> {
550
+ throw this.unimplemented('Not implemented on web.');
551
+ }
539
552
  }