Secure delete full-text fields

This commit is contained in:
Ali 2019-12-20 20:25:46 +04:00
parent 8963691778
commit 49cea099b3
6 changed files with 18 additions and 6 deletions

View File

@ -1773,8 +1773,14 @@ public final class SqliteValueBox: ValueBox {
statement.reset() statement.reset()
} }
public func fullTextRemove(_ table: ValueBoxFullTextTable, itemId: String) { public func fullTextRemove(_ table: ValueBoxFullTextTable, itemId: String, secure: Bool) {
if let _ = self.fullTextTables[table.id] { if let _ = self.fullTextTables[table.id] {
if secure != self.secureDeleteEnabled {
self.secureDeleteEnabled = secure
let result = database.execute("PRAGMA secure_delete=\(secure ? 1 : 0)")
precondition(result)
}
guard let itemIdData = itemId.data(using: .utf8) else { guard let itemIdData = itemId.data(using: .utf8) else {
return return
} }

View File

@ -83,7 +83,7 @@ public protocol ValueBox {
func removeRange(_ table: ValueBoxTable, start: ValueBoxKey, end: ValueBoxKey) func removeRange(_ table: ValueBoxTable, start: ValueBoxKey, end: ValueBoxKey)
func fullTextSet(_ table: ValueBoxFullTextTable, collectionId: String, itemId: String, contents: String, tags: String) func fullTextSet(_ table: ValueBoxFullTextTable, collectionId: String, itemId: String, contents: String, tags: String)
func fullTextMatch(_ table: ValueBoxFullTextTable, collectionId: String?, query: String, tags: String?, values: (String, String) -> Bool) func fullTextMatch(_ table: ValueBoxFullTextTable, collectionId: String?, query: String, tags: String?, values: (String, String) -> Bool)
func fullTextRemove(_ table: ValueBoxFullTextTable, itemId: String) func fullTextRemove(_ table: ValueBoxFullTextTable, itemId: String, secure: Bool)
func removeAllFromTable(_ table: ValueBoxTable) func removeAllFromTable(_ table: ValueBoxTable)
func removeTable(_ table: ValueBoxTable) func removeTable(_ table: ValueBoxTable)
func renameTable(_ table: ValueBoxTable, to toTable: ValueBoxTable) func renameTable(_ table: ValueBoxTable, to toTable: ValueBoxTable)

View File

@ -1380,7 +1380,7 @@ final class MessageHistoryTable: Table {
} }
} }
self.valueBox.remove(self.table, key: self.key(index), secure: false) self.valueBox.remove(self.table, key: self.key(index), secure: true)
let updatedIndex = message.index let updatedIndex = message.index

View File

@ -66,7 +66,7 @@ final class MessageHistoryTextIndexTable {
} }
func remove(messageId: MessageId) { func remove(messageId: MessageId) {
self.valueBox.fullTextRemove(self.table, itemId: itemId(messageId)) self.valueBox.fullTextRemove(self.table, itemId: itemId(messageId), secure: true)
} }
func search(peerId: PeerId?, text: String, tags: MessageTags?) -> [MessageId] { func search(peerId: PeerId?, text: String, tags: MessageTags?) -> [MessageId] {

View File

@ -1764,8 +1764,14 @@ public final class SqliteValueBox: ValueBox {
statement.reset() statement.reset()
} }
public func fullTextRemove(_ table: ValueBoxFullTextTable, itemId: String) { public func fullTextRemove(_ table: ValueBoxFullTextTable, itemId: String, secure: Bool) {
if let _ = self.fullTextTables[table.id] { if let _ = self.fullTextTables[table.id] {
if secure != self.secureDeleteEnabled {
self.secureDeleteEnabled = secure
let result = database.execute("PRAGMA secure_delete=\(secure ? 1 : 0)")
precondition(result)
}
guard let itemIdData = itemId.data(using: .utf8) else { guard let itemIdData = itemId.data(using: .utf8) else {
return return
} }

View File

@ -82,7 +82,7 @@ public protocol ValueBox {
func removeRange(_ table: ValueBoxTable, start: ValueBoxKey, end: ValueBoxKey) func removeRange(_ table: ValueBoxTable, start: ValueBoxKey, end: ValueBoxKey)
func fullTextSet(_ table: ValueBoxFullTextTable, collectionId: String, itemId: String, contents: String, tags: String) func fullTextSet(_ table: ValueBoxFullTextTable, collectionId: String, itemId: String, contents: String, tags: String)
func fullTextMatch(_ table: ValueBoxFullTextTable, collectionId: String?, query: String, tags: String?, values: (String, String) -> Bool) func fullTextMatch(_ table: ValueBoxFullTextTable, collectionId: String?, query: String, tags: String?, values: (String, String) -> Bool)
func fullTextRemove(_ table: ValueBoxFullTextTable, itemId: String) func fullTextRemove(_ table: ValueBoxFullTextTable, itemId: String, secure: Bool)
func removeAllFromTable(_ table: ValueBoxTable) func removeAllFromTable(_ table: ValueBoxTable)
func removeTable(_ table: ValueBoxTable) func removeTable(_ table: ValueBoxTable)
func renameTable(_ table: ValueBoxTable, to toTable: ValueBoxTable) func renameTable(_ table: ValueBoxTable, to toTable: ValueBoxTable)