Mercurial > cgi-bin > hgweb.cgi > PassMan
comparison src/main/kotlin/name/blackcap/passman/Database.kt @ 11:c69665ff37d0
Add merge subcommand (untested).
author | David Barts <n5jrn@me.com> |
---|---|
date | Sat, 21 Jan 2023 15:39:42 -0800 |
parents | 698c4a3d758d |
children | 0fc90892a3ae |
comparison
equal
deleted
inserted
replaced
10:cbe4c797c9a6 | 11:c69665ff37d0 |
---|---|
112 } | 112 } |
113 | 113 |
114 fun makeKey(name: String): Long = Hashing.hash(encryption.encryptFromString0(name.lowercase())) | 114 fun makeKey(name: String): Long = Hashing.hash(encryption.encryptFromString0(name.lowercase())) |
115 } | 115 } |
116 | 116 |
117 public fun ResultSet.getDecryptedString(columnIndex: Int, encryption: Encryption): String? { | 117 fun ResultSet.getDecryptedString(columnIndex: Int, encryption: Encryption): String? { |
118 return encryption.decryptToString(getBytes(columnIndex) ?: return null) | 118 return encryption.decryptToString(getBytes(columnIndex) ?: return null) |
119 } | 119 } |
120 | 120 |
121 public fun ResultSet.getDecrypted(columnIndex: Int, encryption: Encryption): CharArray? { | 121 fun ResultSet.getDecrypted(columnIndex: Int, encryption: Encryption): CharArray? { |
122 return encryption.decrypt(getBytes(columnIndex) ?: return null) | 122 return encryption.decrypt(getBytes(columnIndex) ?: return null) |
123 } | 123 } |
124 | 124 |
125 public fun PreparedStatement.setEncryptedString(columnIndex: Int, value: String?, encryption: Encryption) = | 125 fun PreparedStatement.setEncryptedString(columnIndex: Int, value: String?, encryption: Encryption) = |
126 if (value == null) { | 126 if (value == null) { |
127 setNull(columnIndex, Types.BLOB) | 127 setNull(columnIndex, Types.BLOB) |
128 } else { | 128 } else { |
129 setBytes(columnIndex, encryption.encryptFromString(value)) | 129 setBytes(columnIndex, encryption.encryptFromString(value)) |
130 } | 130 } |
131 | 131 |
132 public fun PreparedStatement.setEncrypted(columnIndex: Int, value: CharArray?, encryption: Encryption) = | 132 fun PreparedStatement.setEncrypted(columnIndex: Int, value: CharArray?, encryption: Encryption) = |
133 if (value == null) { | 133 if (value == null) { |
134 setNull(columnIndex, Types.BLOB) | 134 setNull(columnIndex, Types.BLOB) |
135 } else { | 135 } else { |
136 setBytes(columnIndex, encryption.encrypt(value)) | 136 setBytes(columnIndex, encryption.encrypt(value)) |
137 } | 137 } |
138 | |
139 fun PreparedStatement.setBytesOrNull(columnIndex: Int, value: ByteArray?) = | |
140 if (value == null) { | |
141 setNull(columnIndex, Types.BLOB) | |
142 } else { | |
143 setBytes(columnIndex, value) | |
144 } | |
145 | |
146 fun PreparedStatement.setLongOrNull(columnIndex: Int, value: Long?) = | |
147 if (value == null) { | |
148 setNull(columnIndex, Types.INTEGER) | |
149 } else { | |
150 setLong(columnIndex, value) | |
151 } |