-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement equals, hashCode for AesKey, RsaPrivateKey and RsaPublicKey (…
…#492) Implement equals, hashCode for AesKey, RsaPrivateKey and RsaPublicKey
- Loading branch information
1 parent
2db05cf
commit a104dde
Showing
7 changed files
with
203 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...ypted-config-value/src/test/java/com/palantir/config/crypto/algorithm/aes/AesKeyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* (c) Copyright 2023 Palantir Technologies Inc. All rights reserved. | ||
* | ||
* Licensed 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 com.palantir.config.crypto.algorithm.aes; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.palantir.config.crypto.algorithm.Algorithm; | ||
import java.security.NoSuchAlgorithmException; | ||
import javax.crypto.SecretKey; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class AesKeyTest { | ||
public static SecretKey newSecretKey() { | ||
javax.crypto.KeyGenerator keyGen; | ||
try { | ||
keyGen = javax.crypto.KeyGenerator.getInstance(Algorithm.AES.toString()); | ||
} catch (NoSuchAlgorithmException e) { | ||
throw new RuntimeException(e); | ||
} | ||
keyGen.init(128); | ||
return keyGen.generateKey(); | ||
} | ||
|
||
@Test | ||
public void testEqualityFromSameSecretKey() { | ||
SecretKey secretKey = newSecretKey(); | ||
assertThat(new AesKey(secretKey)).isEqualTo(new AesKey(secretKey)); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...onfig-value/src/test/java/com/palantir/config/crypto/algorithm/rsa/RsaPrivateKeyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* (c) Copyright 2023 Palantir Technologies Inc. All rights reserved. | ||
* | ||
* Licensed 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 com.palantir.config.crypto.algorithm.rsa; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.palantir.config.crypto.algorithm.Algorithm; | ||
import java.security.KeyPair; | ||
import java.security.KeyPairGenerator; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.security.PrivateKey; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class RsaPrivateKeyTest { | ||
|
||
private static KeyPair generateKeyPair() { | ||
KeyPairGenerator keyPairGenerator; | ||
try { | ||
keyPairGenerator = KeyPairGenerator.getInstance(Algorithm.RSA.toString()); | ||
} catch (NoSuchAlgorithmException e) { | ||
throw new RuntimeException(e); | ||
} | ||
keyPairGenerator.initialize(2048); | ||
return keyPairGenerator.generateKeyPair(); | ||
} | ||
|
||
@Test | ||
public void testEqualityFromSamePrivateKey() { | ||
PrivateKey privateKey = generateKeyPair().getPrivate(); | ||
assertThat(new RsaPrivateKey(privateKey)).isEqualTo(new RsaPrivateKey(privateKey)); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...config-value/src/test/java/com/palantir/config/crypto/algorithm/rsa/RsaPublicKeyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* (c) Copyright 2023 Palantir Technologies Inc. All rights reserved. | ||
* | ||
* Licensed 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 com.palantir.config.crypto.algorithm.rsa; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.palantir.config.crypto.algorithm.Algorithm; | ||
import java.security.KeyPair; | ||
import java.security.KeyPairGenerator; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.security.PublicKey; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class RsaPublicKeyTest { | ||
private static KeyPair generateKeyPair() { | ||
KeyPairGenerator keyPairGenerator; | ||
try { | ||
keyPairGenerator = KeyPairGenerator.getInstance(Algorithm.RSA.toString()); | ||
} catch (NoSuchAlgorithmException e) { | ||
throw new RuntimeException(e); | ||
} | ||
keyPairGenerator.initialize(2048); | ||
return keyPairGenerator.generateKeyPair(); | ||
} | ||
|
||
@Test | ||
public void testEqualityFromSamePublicKey() { | ||
PublicKey publicKey = generateKeyPair().getPublic(); | ||
assertThat(new RsaPublicKey(publicKey)).isEqualTo(new RsaPublicKey(publicKey)); | ||
} | ||
} |