sarutak commented on a change in pull request #32801:
URL: https://github.com/apache/spark/pull/32801#discussion_r726767859
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/misc.scala
##########
@@ -301,3 +305,137 @@ case class CurrentUser() extends LeafExpression with
Unevaluable {
override def prettyName: String = "current_user"
final override val nodePatterns: Seq[TreePattern] = Seq(CURRENT_LIKE)
}
+
+/**
+ * The base implementation for AES encryption and decryption.
+ */
+abstract class AesBase(left: Expression, right: Expression)
+ extends BinaryExpression with ImplicitCastInputTypes with NullIntolerant
with Serializable {
+
+ override def dataType: DataType = BinaryType
+ override def nullable: Boolean = true
+ override def inputTypes: Seq[DataType] = Seq(BinaryType, BinaryType)
+ protected val cipherMode: Int
+
+ @transient lazy protected val cipher: Cipher = try {
+ Cipher.getInstance("AES")
+ } catch {
+ case e @ (_: NoSuchPaddingException | _: NoSuchAlgorithmException) =>
+ throw new RuntimeException(e)
+ }
+
+ protected override def nullSafeEval(input1: Any, input2: Any): Any = {
+ val input = input1.asInstanceOf[Array[Byte]]
+ val key = input2.asInstanceOf[Array[Byte]]
+ val inputLength = input.length
+ val keyLength = key.length
+ val secretKey = keyLength match {
+ case 16 | 24 | 32 => new SecretKeySpec(key, 0, keyLength, "AES")
+ case _ => null
+ }
+
+ if (secretKey == null) {
+ return null
+ }
+
+ try {
+ cipher.init(cipherMode, secretKey)
+ cipher.doFinal(input, 0, inputLength)
+ } catch {
+ case _: GeneralSecurityException =>
+ null
+ }
+ }
+
+ override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
Review comment:
Seems better. I'll try it. Thank you.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]