8263754: HexFormat 'fromHex' methods should be static

Reviewed-by: redestad, naoto, chegar
This commit is contained in:
Roger Riggs 2021-03-29 20:38:10 +00:00
parent a5d7de2351
commit 8cf1c62c34
5 changed files with 39 additions and 54 deletions

View file

@ -815,11 +815,10 @@ class RevocationChecker extends PKIXRevocationChecker {
* Removes any non-hexadecimal characters from a string.
*/
private static String stripOutSeparators(String value) {
HexFormat hex = HexFormat.of();
char[] chars = value.toCharArray();
StringBuilder hexNumber = new StringBuilder();
for (int i = 0; i < chars.length; i++) {
if (hex.isHexDigit(chars[i])) {
if (HexFormat.isHexDigit(chars[i])) {
hexNumber.append(chars[i]);
}
}

View file

@ -40,7 +40,6 @@ import java.security.cert.URICertStoreParameters;
import java.security.interfaces.ECKey;
import java.security.interfaces.EdECKey;
import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.ECParameterSpec;
import java.text.Collator;
import java.text.MessageFormat;
@ -4574,16 +4573,15 @@ public final class Main {
break;
case -1:
ObjectIdentifier oid = ObjectIdentifier.of(name);
HexFormat hexFmt = HexFormat.of();
byte[] data = null;
if (value != null) {
data = new byte[value.length() / 2 + 1];
int pos = 0;
for (char c: value.toCharArray()) {
if (!hexFmt.isHexDigit(c)) {
if (!HexFormat.isHexDigit(c)) {
continue;
}
int hex = hexFmt.fromHexDigit(c);
int hex = HexFormat.fromHexDigit(c);
if (pos % 2 == 0) {
data[pos/2] = (byte)(hex << 4);
} else {

View file

@ -29,7 +29,6 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.Reader;
import java.security.AccessController;
import java.text.Normalizer;
import java.util.*;
@ -251,7 +250,6 @@ public class AVA implements DerEncoder {
private static DerValue parseHexString
(Reader in, int format) throws IOException {
HexFormat hex = HexFormat.of();
int c;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte b = 0;
@ -263,7 +261,7 @@ public class AVA implements DerEncoder {
break;
}
try {
int cVal = hex.fromHexDigit(c); // throws on invalid character
int cVal = HexFormat.fromHexDigit(c); // throws on invalid character
if ((cNdx % 2) == 1) {
b = (byte)((b * 16) + (byte)(cVal));
baos.write(b);
@ -502,14 +500,13 @@ public class AVA implements DerEncoder {
private static Byte getEmbeddedHexPair(int c1, Reader in)
throws IOException {
HexFormat hex = HexFormat.of();
if (hex.isHexDigit(c1)) {
if (HexFormat.isHexDigit(c1)) {
int c2 = readChar(in, "unexpected EOF - " +
"escaped hex value must include two valid digits");
if (hex.isHexDigit(c2)) {
int hi = hex.fromHexDigit(c1);
int lo = hex.fromHexDigit(c2);
if (HexFormat.isHexDigit(c2)) {
int hi = HexFormat.fromHexDigit(c1);
int lo = HexFormat.fromHexDigit(c2);
return (byte)((hi<<4) + lo);
} else {
throw new IOException