Mercurial > cgi-bin > hgweb.cgi > PassMan
comparison src/main/kotlin/name/blackcap/passman/Database.kt @ 3:eafa3779aef8
More bug fixes, quote strings in diagnostics.
author | David Barts <n5jrn@me.com> |
---|---|
date | Sun, 11 Sep 2022 20:36:06 -0700 |
parents | a6cfdffcaa94 |
children | ad997df1f560 |
comparison
equal
deleted
inserted
replaced
2:3c792ad36b3d | 3:eafa3779aef8 |
---|---|
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 $fileName") | 21 error("initializing database ${see(fileName, simple = true)}") |
22 } else { | 22 } else { |
23 die("$fileName not found") | 23 die("${see(fileName, simple = true)} 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) } |
97 die("corrupt database, missing test parameter") | 97 die("corrupt database, missing test parameter") |
98 } | 98 } |
99 val readFromDb = result.getDecryptedString(1, database.encryption) | 99 val readFromDb = result.getDecryptedString(1, database.encryption) |
100 if (readFromDb != PLAINTEXT) { | 100 if (readFromDb != PLAINTEXT) { |
101 /* might also get thrown by getDecryptedString if bad */ | 101 /* might also get thrown by getDecryptedString if bad */ |
102 println(" got: " + dump(readFromDb)) | |
103 println("expected: " + dump(PLAINTEXT)) | |
104 throw GeneralSecurityException("bad key!") | 102 throw GeneralSecurityException("bad key!") |
105 } | 103 } |
106 } | 104 } |
107 } catch (e: SQLException) { | 105 } catch (e: SQLException) { |
108 e.printStackTrace() | 106 e.printStackTrace() |