Mercurial > cgi-bin > hgweb.cgi > PassMan
comparison src/main/kotlin/name/blackcap/passman/Database.kt @ 5:ad997df1f560
Fix see() to be about as good as sccc.
author | David Barts <n5jrn@me.com> |
---|---|
date | Sun, 11 Sep 2022 21:29:20 -0700 |
parents | eafa3779aef8 |
children | 711cc42e96d7 |
comparison
equal
deleted
inserted
replaced
4:02b101422726 | 5:ad997df1f560 |
---|---|
16 fun open(passwordPrompt: String = DEFAULT_PROMPT, fileName: String = DB_FILE, | 16 fun open(passwordPrompt: String = DEFAULT_PROMPT, fileName: String = DB_FILE, |
17 create: Boolean = true): Database { | 17 create: Boolean = true): Database { |
18 val exists = Files.exists(Path.of(fileName)) | 18 val exists = Files.exists(Path.of(fileName)) |
19 if (!exists) { | 19 if (!exists) { |
20 if (create) { | 20 if (create) { |
21 error("initializing database ${see(fileName, simple = true)}") | 21 error("initializing database ${see(fileName)}") |
22 } else { | 22 } else { |
23 die("${see(fileName, simple = true)} not found") | 23 die("${see(fileName)} not found") |
24 } | 24 } |
25 } | 25 } |
26 val masterPassword = getPassword(passwordPrompt, !exists) | 26 val masterPassword = getPassword(passwordPrompt, !exists) |
27 val conn = DriverManager.getConnection("jdbc:sqlite:$fileName") | 27 val conn = DriverManager.getConnection("jdbc:sqlite:$fileName") |
28 val enc = if (exists) { reuse(conn, masterPassword) } else { init(conn, masterPassword) } | 28 val enc = if (exists) { reuse(conn, masterPassword) } else { init(conn, masterPassword) } |
118 encryption.decryptToString(getBytes(columnIndex)) | 118 encryption.decryptToString(getBytes(columnIndex)) |
119 | 119 |
120 public fun ResultSet.getDecrypted(columnIndex: Int, encryption: Encryption) = | 120 public fun ResultSet.getDecrypted(columnIndex: Int, encryption: Encryption) = |
121 encryption.decrypt(getBytes(columnIndex)) | 121 encryption.decrypt(getBytes(columnIndex)) |
122 | 122 |
123 public fun ResultSet.getDate(columnIndex: Int): java.util.Date? { | |
124 val rawDate = getLong(columnIndex) | |
125 return if (wasNull()) { null } else { java.util.Date(rawDate) } | |
126 } | |
127 | |
128 public fun PreparedStatement.setEncryptedString(columnIndex: Int, value: String, encryption: Encryption) = | 123 public fun PreparedStatement.setEncryptedString(columnIndex: Int, value: String, encryption: Encryption) = |
129 setBytes(columnIndex, encryption.encryptFromString(value)) | 124 setBytes(columnIndex, encryption.encryptFromString(value)) |
130 | 125 |
131 public fun PreparedStatement.setEncrypted(columnIndex: Int, value: CharArray, encryption: Encryption) = | 126 public fun PreparedStatement.setEncrypted(columnIndex: Int, value: CharArray, encryption: Encryption) = |
132 setBytes(columnIndex, encryption.encrypt(value)) | 127 setBytes(columnIndex, encryption.encrypt(value)) |