Mercurial > cgi-bin > hgweb.cgi > PassMan
comparison src/main/kotlin/name/blackcap/passman/Database.kt @ 8:698c4a3d758d
Some code clean-up.
author | David Barts <n5jrn@me.com> |
---|---|
date | Fri, 23 Sep 2022 20:59:52 -0700 |
parents | f245b9a53495 |
children | c69665ff37d0 |
comparison
equal
deleted
inserted
replaced
7:f245b9a53495 | 8:698c4a3d758d |
---|---|
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) = | 117 public fun ResultSet.getDecryptedString(columnIndex: Int, encryption: Encryption): String? { |
118 encryption.decryptToString(getBytes(columnIndex)) | 118 return encryption.decryptToString(getBytes(columnIndex) ?: return null) |
119 } | |
119 | 120 |
120 public fun ResultSet.getDecrypted(columnIndex: Int, encryption: Encryption) = | 121 public fun ResultSet.getDecrypted(columnIndex: Int, encryption: Encryption): CharArray? { |
121 encryption.decrypt(getBytes(columnIndex)) | 122 return encryption.decrypt(getBytes(columnIndex) ?: return null) |
123 } | |
122 | 124 |
123 public fun PreparedStatement.setEncryptedString(columnIndex: Int, value: String, encryption: Encryption) = | 125 public fun PreparedStatement.setEncryptedString(columnIndex: Int, value: String?, encryption: Encryption) = |
124 setBytes(columnIndex, encryption.encryptFromString(value)) | 126 if (value == null) { |
127 setNull(columnIndex, Types.BLOB) | |
128 } else { | |
129 setBytes(columnIndex, encryption.encryptFromString(value)) | |
130 } | |
125 | 131 |
126 public fun PreparedStatement.setEncrypted(columnIndex: Int, value: CharArray, encryption: Encryption) = | 132 public fun PreparedStatement.setEncrypted(columnIndex: Int, value: CharArray?, encryption: Encryption) = |
127 setBytes(columnIndex, encryption.encrypt(value)) | 133 if (value == null) { |
134 setNull(columnIndex, Types.BLOB) | |
135 } else { | |
136 setBytes(columnIndex, encryption.encrypt(value)) | |
137 } |