< prev index next > test/jdk/sun/security/ec/ed/EdDSAParamSpec.java
Print this page
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.Signature;
import java.security.spec.EdDSAParameterSpec;
import java.util.Arrays;
! import jdk.test.lib.Convert;
/*
* @test
* @bug 8209632
* @summary Test EdDSAParameterSpec.
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.Signature;
import java.security.spec.EdDSAParameterSpec;
import java.util.Arrays;
! import java.util.Hex;
/*
* @test
* @bug 8209632
* @summary Test EdDSAParameterSpec.
byte[] maxCtx = new byte[255];
RND.nextBytes(maxCtx);
for (byte[] context : new byte[][]{"others".getBytes(), maxCtx}) {
System.out.printf("Testing signature for name: %s,"
+ " algorithm spec: (prehash:%s, context:%s)%n",
! name, preHash, Convert.byteArrayToHexString(context));
EdDSAParameterSpec params
= new EdDSAParameterSpec(preHash, context);
verifyPublic(sig, kp.getPublic(), MSG, params, initParam,
origSign);
}
byte[] maxCtx = new byte[255];
RND.nextBytes(maxCtx);
for (byte[] context : new byte[][]{"others".getBytes(), maxCtx}) {
System.out.printf("Testing signature for name: %s,"
+ " algorithm spec: (prehash:%s, context:%s)%n",
! name, preHash, Hex.encoder().encode(context));
EdDSAParameterSpec params
= new EdDSAParameterSpec(preHash, context);
verifyPublic(sig, kp.getPublic(), MSG, params, initParam,
origSign);
}
// which is set through the signature instance.
if (!(equals(context, initContext) && equals(preHash, initPreHash))) {
throw new RuntimeException(String.format("Signature verification"
+ " success with different param context(actual:%s, "
+ "expected:%s), Prehash(actual:%s, expected:%s)",
! Convert.byteArrayToHexString(context),
! Convert.byteArrayToHexString(initContext),
preHash, initPreHash));
} else {
System.out.println("Atleast a case matched");
}
}
// which is set through the signature instance.
if (!(equals(context, initContext) && equals(preHash, initPreHash))) {
throw new RuntimeException(String.format("Signature verification"
+ " success with different param context(actual:%s, "
+ "expected:%s), Prehash(actual:%s, expected:%s)",
! Hex.encoder().encode(context),
! Hex.encoder().encode(initContext),
preHash, initPreHash));
} else {
System.out.println("Atleast a case matched");
}
}
return false;
}
boolean equals = Arrays.equals(actual, expected);
if (!equals) {
throw new RuntimeException(String.format("Actual array: %s, "
! + "Expected array:%s", Convert.byteArrayToHexString(actual),
! Convert.byteArrayToHexString(expected)));
}
return equals;
}
}
return false;
}
boolean equals = Arrays.equals(actual, expected);
if (!equals) {
throw new RuntimeException(String.format("Actual array: %s, "
! + "Expected array:%s", Hex.encoder().encode(actual),
! Hex.encoder().encode(expected)));
}
return equals;
}
}
< prev index next >