Skip to content

Commit

Permalink
Apply spotless formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
sp717 committed Jul 31, 2024
1 parent 2afa60c commit d510787
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,3 @@ public Optional<byte[]> getBytes() {
return Optional.ofNullable(bytes);
}
}


142 changes: 72 additions & 70 deletions tst/com/amazon/corretto/crypto/provider/test/EdDSATest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

import java.nio.ByteBuffer;
import java.security.*;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.security.SignatureException;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -146,9 +146,9 @@ public void jceInteropValidation() throws GeneralSecurityException {
final KeyPair keyPair = nativeGen.generateKeyPair();

final PKCS8EncodedKeySpec privateKeyPkcs8 =
new PKCS8EncodedKeySpec(keyPair.getPrivate().getEncoded());
new PKCS8EncodedKeySpec(keyPair.getPrivate().getEncoded());
final X509EncodedKeySpec publicKeyX509 =
new X509EncodedKeySpec(keyPair.getPublic().getEncoded());
new X509EncodedKeySpec(keyPair.getPublic().getEncoded());

final KeyFactory kf = KeyFactory.getInstance("Ed25519", "SunEC");
final PrivateKey privateKey = kf.generatePrivate(privateKeyPkcs8);
Expand Down Expand Up @@ -176,46 +176,46 @@ public void jceInteropValidation() throws GeneralSecurityException {
assertTrue(nativeSig.verify(signature), "JCE->Native: Ed25519");
}

// @Test
// public void bcValidation() throws GeneralSecurityException {
// // Generate Keys with BouncyCastle & Sign/Verify with ACCP
// final byte[] message = new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
// final Signature eddsa = Signature.getInstance("Ed25519", NATIVE_PROVIDER);
// final KeyPair keyPair = bcGen.generateKeyPair();
//
// StringBuilder keystr = new StringBuilder();
// StringBuilder keystr2 = new StringBuilder();
//
// for (byte b : keyPair.getPrivate().getEncoded()) {
// keystr.append(String.format("%02X ", b));
// }
//
// for (byte b : keyPair.getPublic().getEncoded()) {
// keystr2.append(String.format("%02X ", b));
// }
//
// System.out.println(keystr.toString());
// System.out.println(keystr2.toString());
//
// final PKCS8EncodedKeySpec privateKeyPkcs8 =
// new PKCS8EncodedKeySpec(keyPair.getPrivate().getEncoded());
// final X509EncodedKeySpec publicKeyX509 =
// new X509EncodedKeySpec(keyPair.getPublic().getEncoded());
//
// final KeyFactory kf = KeyFactory.getInstance("Ed25519", NATIVE_PROVIDER);
//
// final PrivateKey privateKey = kf.generatePrivate(privateKeyPkcs8);
// final PublicKey publicKey = kf.generatePublic(publicKeyX509);
//
// eddsa.initSign(privateKey);
// eddsa.update(message, 0, message.length);
//
// final byte[] signature = eddsa.sign();
//
// eddsa.initVerify(publicKey);
// eddsa.update(message);
// assertTrue(eddsa.verify(signature));
// }
// @Test
// public void bcValidation() throws GeneralSecurityException {
// // Generate Keys with BouncyCastle & Sign/Verify with ACCP
// final byte[] message = new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
// final Signature eddsa = Signature.getInstance("Ed25519", NATIVE_PROVIDER);
// final KeyPair keyPair = bcGen.generateKeyPair();
//
// StringBuilder keystr = new StringBuilder();
// StringBuilder keystr2 = new StringBuilder();
//
// for (byte b : keyPair.getPrivate().getEncoded()) {
// keystr.append(String.format("%02X ", b));
// }
//
// for (byte b : keyPair.getPublic().getEncoded()) {
// keystr2.append(String.format("%02X ", b));
// }
//
// System.out.println(keystr.toString());
// System.out.println(keystr2.toString());
//
// final PKCS8EncodedKeySpec privateKeyPkcs8 =
// new PKCS8EncodedKeySpec(keyPair.getPrivate().getEncoded());
// final X509EncodedKeySpec publicKeyX509 =
// new X509EncodedKeySpec(keyPair.getPublic().getEncoded());
//
// final KeyFactory kf = KeyFactory.getInstance("Ed25519", NATIVE_PROVIDER);
//
// final PrivateKey privateKey = kf.generatePrivate(privateKeyPkcs8);
// final PublicKey publicKey = kf.generatePublic(publicKeyX509);
//
// eddsa.initSign(privateKey);
// eddsa.update(message, 0, message.length);
//
// final byte[] signature = eddsa.sign();
//
// eddsa.initVerify(publicKey);
// eddsa.update(message);
// assertTrue(eddsa.verify(signature));
// }

@Test
public void bcKeyValidation() throws GeneralSecurityException {
Expand All @@ -242,30 +242,30 @@ public void bcKeyValidation() throws GeneralSecurityException {
}
}

// @Test
// public void bcKeyValidation2() throws GeneralSecurityException {
// final KeyPair kp = bcGen.generateKeyPair();
// final byte[] pkBC = kp.getPrivate().getEncoded();
// final byte[] pbkBC = kp.getPublic().getEncoded();
//
// final PKCS8EncodedKeySpec privateKeyPkcs8 = new PKCS8EncodedKeySpec(pkBC);
// final X509EncodedKeySpec publicKeyX509 = new X509EncodedKeySpec(pbkBC);
//
// final KeyFactory kf = KeyFactory.getInstance("Ed25519", NATIVE_PROVIDER);
//
// final byte[] pkACCP = kf.generatePrivate(privateKeyPkcs8).getEncoded();
// final byte[] pbkACCP = kf.generatePublic(publicKeyX509).getEncoded();
//
// assertTrue(pkACCP.length == pkBC.length);
// for (int i = 0; i < pkACCP.length; i++) {
// assertTrue(pkACCP[i] == pkBC[i]);
// }
//
// assertTrue(pbkACCP.length == pbkBC.length);
// for (int i = 0; i < pbkACCP.length; i++) {
// assertTrue(pbkACCP[i] == pbkBC[i]);
// }
// }
// @Test
// public void bcKeyValidation2() throws GeneralSecurityException {
// final KeyPair kp = bcGen.generateKeyPair();
// final byte[] pkBC = kp.getPrivate().getEncoded();
// final byte[] pbkBC = kp.getPublic().getEncoded();
//
// final PKCS8EncodedKeySpec privateKeyPkcs8 = new PKCS8EncodedKeySpec(pkBC);
// final X509EncodedKeySpec publicKeyX509 = new X509EncodedKeySpec(pbkBC);
//
// final KeyFactory kf = KeyFactory.getInstance("Ed25519", NATIVE_PROVIDER);
//
// final byte[] pkACCP = kf.generatePrivate(privateKeyPkcs8).getEncoded();
// final byte[] pbkACCP = kf.generatePublic(publicKeyX509).getEncoded();
//
// assertTrue(pkACCP.length == pkBC.length);
// for (int i = 0; i < pkACCP.length; i++) {
// assertTrue(pkACCP[i] == pkBC[i]);
// }
//
// assertTrue(pbkACCP.length == pbkBC.length);
// for (int i = 0; i < pbkACCP.length; i++) {
// assertTrue(pbkACCP[i] == pbkBC[i]);
// }
// }

@Test
public void eddsaValidation() throws GeneralSecurityException {
Expand Down Expand Up @@ -309,8 +309,10 @@ public void testInvalidKey() throws GeneralSecurityException {

final KeyFactory kf = KeyFactory.getInstance("Ed25519", NATIVE_PROVIDER);

TestUtil.assertThrows(InvalidKeySpecException.class, () -> kf.generatePrivate(invalidPrivateKeySpec));
TestUtil.assertThrows(InvalidKeySpecException.class, () -> kf.generatePublic(invalidPublicKeySpec));
TestUtil.assertThrows(
InvalidKeySpecException.class, () -> kf.generatePrivate(invalidPrivateKeySpec));
TestUtil.assertThrows(
InvalidKeySpecException.class, () -> kf.generatePublic(invalidPublicKeySpec));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ static long getRawPointer(final Object evpKey) throws Exception {
@ParameterizedTest(name = "{1}")
@MethodSource("allPairs")
public void keysSerialize(final KeyPair keyPair, final String testName) throws Exception {
final KeyFactory kf = KeyFactory.getInstance(keyPair.getPrivate().getAlgorithm(), NATIVE_PROVIDER);
final KeyFactory kf =
KeyFactory.getInstance(keyPair.getPrivate().getAlgorithm(), NATIVE_PROVIDER);

final Key privateKey = kf.translateKey(keyPair.getPrivate());
final Key publicKey = kf.translateKey(keyPair.getPublic());
Expand Down

0 comments on commit d510787

Please sign in to comment.