Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyrat committed Jul 12, 2023
1 parent 34ba76b commit 72dc146
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 33 deletions.
8 changes: 4 additions & 4 deletions ios/KdbxSwift/Sources/KdbxSwift/DatabaseFileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ public class DatabaseFileManager {

} catch {
Logger.mainLog.error("Failed to read current KDBX file [message: \(error.localizedDescription)]")
fatalError("couldn't read KDBX file")
Logger.fatalError("couldn't read KDBX file")
}
}

guard let db = initDatabase(signature: fileData) else {
fatalError("database init failed")
Logger.fatalError("database init failed")
}

let dbFile = DatabaseFile(
Expand All @@ -90,15 +90,15 @@ public class DatabaseFileManager {
database = db

} catch {
fatalError("Unprocessed exception while opening database. Possibly hardware failure has corrupted the data on this device.")
Logger.fatalError("Unprocessed exception while opening database. Possibly hardware failure has corrupted the data on this device.")
}
return dbFile
}

public func saveToFile(db: Database?) {
do {
guard let targetDatabase = db ?? database else {
fatalError("No database to save")
Logger.fatalError("No database to save")
}
let fileData = try targetDatabase.save()
try fileData.write(to: kdbxAutofillURL, options: .atomic)
Expand Down
3 changes: 2 additions & 1 deletion ios/KdbxSwift/Sources/KdbxSwift/base32/Base32.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
// THE SOFTWARE.

import Foundation
import os.log

// https://tools.ietf.org/html/rfc4648

Expand Down Expand Up @@ -232,7 +233,7 @@ private func base32encode(_ data: UnsafeRawPointer, _ length: Int, _ table: [Int
return base32Encoded
} else {
resultBuffer.deallocate()
fatalError("internal error")
Logger.fatalError("internal error")
}
}

Expand Down
18 changes: 9 additions & 9 deletions ios/KdbxSwift/Sources/KdbxSwift/db/Database.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ open class Database: Eraseable {
}

public var keyHelper: KeyHelper {
fatalError("Pure virtual method")
Logger.fatalError("Pure virtual method")
}

internal init() {
Expand All @@ -59,27 +59,27 @@ open class Database: Eraseable {
}

public class func isSignatureMatches(data: ByteArray) -> Bool {
fatalError("Pure virtual method")
Logger.fatalError("Pure virtual method")
}

public func load(
dbFileName: String,
dbFileData: ByteArray,
preTransformedKeyMaterial: ByteArray
) throws {
fatalError("Pure virtual method")
Logger.fatalError("Pure virtual method")
}

public func save() throws -> ByteArray {
fatalError("Pure virtual method")
Logger.fatalError("Pure virtual method")
}

public func changeCompositeKey(to newKey: CompositeKey) {
fatalError("Pure virtual method")
Logger.fatalError("Pure virtual method")
}

public func getBackupGroup(createIfMissing: Bool) -> Group? {
fatalError("Pure virtual method")
Logger.fatalError("Pure virtual method")
}

public func count(includeGroups: Bool = true, includeEntries: Bool = true) -> Int {
Expand All @@ -101,15 +101,15 @@ open class Database: Eraseable {
}

public func delete(group: Group) {
fatalError("Pure virtual method")
Logger.fatalError("Pure virtual method")
}

public func delete(entry: Entry) {
fatalError("Pure virtual method")
Logger.fatalError("Pure virtual method")
}

public func makeAttachment(name: String, data: ByteArray) -> Attachment {
fatalError("Pure virtual method")
Logger.fatalError("Pure virtual method")
}

internal func resolveReferences<T>(
Expand Down
4 changes: 3 additions & 1 deletion ios/KdbxSwift/Sources/KdbxSwift/db/DatabaseItem.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os.log

open class DatabaseItem {
public enum TouchMode {
case accessed
Expand All @@ -18,6 +20,6 @@ open class DatabaseItem {
}

public func touch(_ mode: TouchMode, updateParents: Bool = true) {
fatalError("Pure abstract method")
Logger.fatalError("Pure abstract method")
}
}
7 changes: 4 additions & 3 deletions ios/KdbxSwift/Sources/KdbxSwift/db/Entry.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import os.log

public class EntryField: Eraseable {
public static let title = "Title"
Expand Down Expand Up @@ -203,7 +204,7 @@ public class Entry: DatabaseItem, Eraseable {

public var isHiddenFromSearch: Bool {
get { return false }
set { fatalError("This property can be modified only in some DB formats") }
set { Logger.fatalError("This property can be modified only in some DB formats") }
}

public var attachments: Array<Attachment>
Expand Down Expand Up @@ -298,7 +299,7 @@ public class Entry: DatabaseItem, Eraseable {
}

public func clone(makeNewUUID: Bool) -> Entry {
fatalError("Pure virtual method")
Logger.fatalError("Pure virtual method")
}

public func apply(to target: Entry, makeNewUUID: Bool) {
Expand Down Expand Up @@ -326,7 +327,7 @@ public class Entry: DatabaseItem, Eraseable {
}

public func backupState() {
fatalError("Pure virtual method")
Logger.fatalError("Pure virtual method")
}

override public func touch(_ mode: DatabaseItem.TouchMode, updateParents: Bool = true) {
Expand Down
7 changes: 4 additions & 3 deletions ios/KdbxSwift/Sources/KdbxSwift/db/Group.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import os.log

public class Group: DatabaseItem, Eraseable {
public static let defaultIconID = IconID.folder
Expand Down Expand Up @@ -79,7 +80,7 @@ public class Group: DatabaseItem, Eraseable {
}

public func clone(makeNewUUID: Bool) -> Group {
fatalError("Pure virtual method")
Logger.fatalError("Pure virtual method")
}

public func deepClone(makeNewUUIDs: Bool) -> Group {
Expand Down Expand Up @@ -192,11 +193,11 @@ public class Group: DatabaseItem, Eraseable {
}

public func createEntry(detached: Bool = false) -> Entry {
fatalError("Pure virtual method")
Logger.fatalError("Pure virtual method")
}

public func createGroup(detached: Bool = false) -> Group {
fatalError("Pure virtual method")
Logger.fatalError("Pure virtual method")
}

override public func touch(_ mode: DatabaseItem.TouchMode, updateParents: Bool = true) {
Expand Down
6 changes: 3 additions & 3 deletions ios/KdbxSwift/Sources/KdbxSwift/db/KeyHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ public class KeyHelper {
passwordData: ByteArray,
keyFileData: ByteArray
) throws -> ByteArray {
fatalError("Pure virtual method")
Logger.fatalError("Pure virtual method")
}

public func getKey(fromCombinedComponents combinedComponents: ByteArray) -> ByteArray {
fatalError("Pure virtual method")
Logger.fatalError("Pure virtual method")
}

public func getPasswordData(password: String) -> ByteArray {
fatalError("Pure virtual method")
Logger.fatalError("Pure virtual method")
}

public func processKeyFile(keyFileData: ByteArray) throws -> ByteArray {
Expand Down
3 changes: 2 additions & 1 deletion ios/KdbxSwift/Sources/KdbxSwift/db/cipher/DataCipher.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import os.log

protocol DataCipher: AnyObject {
var uuid: UUID { get }
Expand Down Expand Up @@ -48,7 +49,7 @@ extension DataCipher {
if keySize < hashSize {
return hash.prefix(keySize)
} else {
fatalError("Not implemented")
Logger.fatalError("Not implemented")
}
}
}
7 changes: 4 additions & 3 deletions ios/KdbxSwift/Sources/KdbxSwift/db/kdf/Argon2KDF.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import os.log

class AbstractArgon2KDF {
public static let saltParam = "S"
Expand All @@ -25,10 +26,10 @@ class AbstractArgon2KDF {
fileprivate let defaultParallelism: UInt32 = 2

fileprivate var name: String {
fatalError("Abstract method, override this")
Logger.fatalError("Abstract method, override this")
}
fileprivate var uuid: UUID {
fatalError("Abstract method, override this")
Logger.fatalError("Abstract method, override this")
}

fileprivate var progress = ProgressEx()
Expand Down Expand Up @@ -111,7 +112,7 @@ class AbstractArgon2KDF {
}

func transform(key: ByteArray, params: KDFParams) -> ByteArray {
fatalError("argon2 not implemented")
Logger.fatalError("argon2 not implemented")
}
}

Expand Down
4 changes: 2 additions & 2 deletions ios/KdbxSwift/Sources/KdbxSwift/db/kp2/Database2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ public class Database2: Database {
try header.writeInner(to: contentStream)
Logger.mainLog.trace("Header written OK")
contentStream.write(data: xmlData)
guard let contentData = contentStream.data else { fatalError() }
guard let contentData = contentStream.data else { Logger.fatalError("Failed to get data from contentStream") }

var dataToEncrypt = contentData
if header.isCompressed {
Expand Down Expand Up @@ -720,7 +720,7 @@ public class Database2: Database {
}

override public func delete(group: Group) {
guard let group = group as? Group2 else { fatalError() }
guard let group = group as? Group2 else { Logger.fatalError("Cannot delete group: not a Group") }
guard let parentGroup = group.parent else {
Logger.mainLog.warning("Cannot delete group: no parent group")
return
Expand Down
4 changes: 2 additions & 2 deletions ios/KdbxSwift/Sources/KdbxSwift/db/kp2/Header2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ final class Header2: Eraseable {

internal func initStreamCipher() {
guard let protectedStreamKey = protectedStreamKey else {
fatalError()
Logger.fatalError("initStreamCipher: Failed to assign protectedStreamKey")
}
self.streamCipher = StreamCipherFactory.create(
algorithm: innerStreamAlgorithm,
Expand Down Expand Up @@ -581,7 +581,7 @@ final class Header2: Eraseable {

func writeInner(to stream: ByteArray.OutputStream) throws {
assert(formatVersion >= .v4)
guard let protectedStreamKey = protectedStreamKey else { fatalError() }
guard let protectedStreamKey = protectedStreamKey else { Logger.fatalError("writeInner: failed to assign protectedStreamKey") }

Logger.mainLog.trace("Writing kdbx4 inner header")
stream.write(value: InnerFieldID.innerRandomStreamID.rawValue)
Expand Down
3 changes: 2 additions & 1 deletion ios/KdbxSwift/Sources/KdbxSwift/util/Extensions.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import os.log

extension StringProtocol {
func base64ToBase64url() -> String {
Expand Down Expand Up @@ -145,7 +146,7 @@ extension UUID {
internal var data: ByteArray {
var bytes = Array<UInt8>(repeating: 0, count: UUID.byteWidth)
guard let nsuuid = NSUUID(uuidString: self.uuidString) else {
fatalError()
Logger.fatalError("failed to create NSUUID")
}
nsuuid.getBytes(&bytes)
return ByteArray(bytes: bytes)
Expand Down
5 changes: 5 additions & 0 deletions ios/KdbxSwift/Sources/KdbxSwift/util/Logger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ extension Logger {
private static var subsystem = Bundle.main.bundleIdentifier!

static let mainLog = Logger(subsystem: subsystem, category: "main")

static func fatalError(_ message:String) -> Never {
mainLog.fault("\(message)")
Swift.fatalError(message)
}
}

//
Expand Down

0 comments on commit 72dc146

Please sign in to comment.