Skip to content

Commit 0c653db

Browse files
LuciferYangdongjoon-hyun
authored andcommitted
[SPARK-49879][CORE] Move TransportCipherUtil to a separate file to eliminate Java compilation warnings
### What changes were proposed in this pull request? Run `build/mvn clean install -pl common/network-common`, we can see the following compilation warnings: ``` [WARNING] [Warn] /Users/yangjie01/SourceCode/git/spark-maven/common/network-common/src/main/java/org/apache/spark/network/crypto/CtrTransportCipher.java:73:11: auxiliary class TransportCipherUtil in /Users/yangjie01/SourceCode/git/spark-maven/common/network-common/src/main/java/org/apache/spark/network/crypto/TransportCipher.java should not be accessed from outside its own source file [WARNING] [Warn] /Users/yangjie01/SourceCode/git/spark-maven/common/network-common/src/main/java/org/apache/spark/network/crypto/GcmTransportCipher.java:63:15: auxiliary class TransportCipherUtil in /Users/yangjie01/SourceCode/git/spark-maven/common/network-common/src/main/java/org/apache/spark/network/crypto/TransportCipher.java should not be accessed from outside its own source file ``` So this pr moves `TransportCipherUtil` to a separate file to eliminate the aforementioned Java compilation warnings. ### Why are the changes needed? Fix compilation warnings. ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? - Pass GitHub Actions - locally run `build/mvn clean install -pl common/network-common`, no longer have the aforementioned compilation warnings. ### Was this patch authored or co-authored using generative AI tooling? No Closes #48352 from LuciferYang/Move-TransportCipherUtil. Authored-by: yangjie01 <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
1 parent fcda935 commit 0c653db

File tree

2 files changed

+41
-20
lines changed

2 files changed

+41
-20
lines changed

common/network-common/src/main/java/org/apache/spark/network/crypto/TransportCipher.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,12 @@
1717

1818
package org.apache.spark.network.crypto;
1919

20-
import com.google.common.annotations.VisibleForTesting;
21-
import com.google.crypto.tink.subtle.Hex;
22-
import com.google.crypto.tink.subtle.Hkdf;
2320
import io.netty.channel.Channel;
2421

25-
import javax.crypto.spec.SecretKeySpec;
2622
import java.io.IOException;
27-
import java.nio.charset.StandardCharsets;
2823
import java.security.GeneralSecurityException;
2924

3025
interface TransportCipher {
3126
String getKeyId() throws GeneralSecurityException;
3227
void addToChannel(Channel channel) throws IOException, GeneralSecurityException;
3328
}
34-
35-
class TransportCipherUtil {
36-
/*
37-
* This method is used for testing to verify key derivation.
38-
*/
39-
@VisibleForTesting
40-
static String getKeyId(SecretKeySpec key) throws GeneralSecurityException {
41-
byte[] keyIdBytes = Hkdf.computeHkdf("HmacSha256",
42-
key.getEncoded(),
43-
null,
44-
"keyID".getBytes(StandardCharsets.UTF_8),
45-
32);
46-
return Hex.encode(keyIdBytes);
47-
}
48-
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.spark.network.crypto;
19+
20+
import java.nio.charset.StandardCharsets;
21+
import java.security.GeneralSecurityException;
22+
import javax.crypto.spec.SecretKeySpec;
23+
24+
import com.google.common.annotations.VisibleForTesting;
25+
import com.google.crypto.tink.subtle.Hex;
26+
import com.google.crypto.tink.subtle.Hkdf;
27+
28+
class TransportCipherUtil {
29+
/**
30+
* This method is used for testing to verify key derivation.
31+
*/
32+
@VisibleForTesting
33+
static String getKeyId(SecretKeySpec key) throws GeneralSecurityException {
34+
byte[] keyIdBytes = Hkdf.computeHkdf("HmacSha256",
35+
key.getEncoded(),
36+
null,
37+
"keyID".getBytes(StandardCharsets.UTF_8),
38+
32);
39+
return Hex.encode(keyIdBytes);
40+
}
41+
}

0 commit comments

Comments
 (0)