Mercurial > cgi-bin > hgweb.cgi > PassMan
diff 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 |
line wrap: on
line diff
--- a/src/main/kotlin/name/blackcap/passman/Database.kt Sat Oct 01 20:43:59 2022 -0700 +++ b/src/main/kotlin/name/blackcap/passman/Database.kt Sat Jan 21 15:39:42 2023 -0800 @@ -114,24 +114,38 @@ fun makeKey(name: String): Long = Hashing.hash(encryption.encryptFromString0(name.lowercase())) } -public fun ResultSet.getDecryptedString(columnIndex: Int, encryption: Encryption): String? { +fun ResultSet.getDecryptedString(columnIndex: Int, encryption: Encryption): String? { return encryption.decryptToString(getBytes(columnIndex) ?: return null) } -public fun ResultSet.getDecrypted(columnIndex: Int, encryption: Encryption): CharArray? { +fun ResultSet.getDecrypted(columnIndex: Int, encryption: Encryption): CharArray? { return encryption.decrypt(getBytes(columnIndex) ?: return null) } -public fun PreparedStatement.setEncryptedString(columnIndex: Int, value: String?, encryption: Encryption) = +fun PreparedStatement.setEncryptedString(columnIndex: Int, value: String?, encryption: Encryption) = if (value == null) { setNull(columnIndex, Types.BLOB) } else { setBytes(columnIndex, encryption.encryptFromString(value)) } -public fun PreparedStatement.setEncrypted(columnIndex: Int, value: CharArray?, encryption: Encryption) = +fun PreparedStatement.setEncrypted(columnIndex: Int, value: CharArray?, encryption: Encryption) = if (value == null) { setNull(columnIndex, Types.BLOB) } else { setBytes(columnIndex, encryption.encrypt(value)) } + +fun PreparedStatement.setBytesOrNull(columnIndex: Int, value: ByteArray?) = + if (value == null) { + setNull(columnIndex, Types.BLOB) + } else { + setBytes(columnIndex, value) +} + +fun PreparedStatement.setLongOrNull(columnIndex: Int, value: Long?) = + if (value == null) { + setNull(columnIndex, Types.INTEGER) + } else { + setLong(columnIndex, value) + }