Github user vanzin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/15172#discussion_r83515559
  
    --- Diff: 
common/network-common/src/main/java/org/apache/spark/network/sasl/aes/AesCipherOption.java
 ---
    @@ -0,0 +1,94 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.network.sasl.aes;
    +
    +import io.netty.buffer.ByteBuf;
    +import org.apache.spark.network.protocol.Encodable;
    +import org.apache.spark.network.protocol.Encoders;
    +
    +/**
    + * The AES cipher options for SASL encryption negotiation.
    + */
    +public class AesCipherOption implements Encodable {
    +  /** Serialization tag used to catch incorrect payloads. */
    +  private static final byte TAG_BYTE = (byte) 0xEB;
    +
    +  public byte[] inKey;
    +  public byte[] outKey;
    +  public byte[] inIv;
    +  public byte[] outIv;
    +
    +  public AesCipherOption() {
    +    this(null, null, null, null);
    +  }
    +  public AesCipherOption(byte[] inKey, byte[] inIv, byte[] outKey, byte[] 
outIv) {
    +    this.inKey = inKey;
    +    this.inIv = inIv;
    +    this.outKey = outKey;
    +    this.outIv = outIv;
    +  }
    +
    +  /**
    +   * Set key and input vector for cipher option
    +   * @param inKey The decrypt key of one side
    +   * @param inIv The input vector of one side
    +   * @param outKey The decrypt key of another side
    +   * @param outIv The input vector of another side
    +   */
    +  public void setParameters(byte[] inKey, byte[] inIv, byte[] outKey, 
byte[] outIv) {
    +    this.inKey = inKey;
    +    this.inIv = inIv;
    +    this.outKey = outKey;
    +    this.outIv = outIv;
    +  }
    +
    +  @Override
    +  public int encodedLength() {
    +    return 1 + ((inKey != null && inIv != null && outKey != null && outIv 
!= null) ?
    +      Encoders.ByteArrays.encodedLength(inKey) + 
Encoders.ByteArrays.encodedLength(inKey) +
    +      Encoders.ByteArrays.encodedLength(inIv) + 
Encoders.ByteArrays.encodedLength(outIv) : 0);
    +  }
    +
    +  @Override
    +  public void encode(ByteBuf buf) {
    +    buf.writeByte(TAG_BYTE);
    +    if (inKey != null && inIv != null && outKey != null && outIv != null) {
    +      Encoders.ByteArrays.encode(buf, inKey);
    +      Encoders.ByteArrays.encode(buf, inIv);
    +      Encoders.ByteArrays.encode(buf, outKey);
    +      Encoders.ByteArrays.encode(buf, outIv);
    +    }
    +  }
    +
    +  public static AesCipherOption decode(ByteBuf buf) {
    +    if (buf.readByte() != TAG_BYTE) {
    +      throw new IllegalStateException("Expected SaslMessage, received 
something else"
    +        + " (maybe your client does not have SASL enabled?)");
    +    }
    +
    +    if (buf.isReadable()) {
    --- End diff --
    
    Why do you need this check?
    
    If you just let exceptions propagate, you wouldn't need the empty 
constructor, and you could remove all the null checks from this code.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to