Skip to content

Commit 2320563

Browse files
committed
some small tuning
1 parent ac77172 commit 2320563

File tree

2 files changed

+15
-22
lines changed

2 files changed

+15
-22
lines changed

src/java.base/share/classes/sun/security/util/DerInputStream.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,11 @@ public DerValue[] getSet(int startLen) throws IOException {
208208
}
209209

210210
public DerValue[] getSet(int startLen, boolean implicit) throws IOException {
211-
return getDerValue().subs((byte)0, startLen);
211+
if (implicit) {
212+
return getDerValue().subs((byte) 0, startLen);
213+
} else {
214+
return getSet(startLen);
215+
}
212216
}
213217

214218
public int peekByte() throws IOException {
@@ -239,13 +243,12 @@ static int getLength(InputStream in) throws IOException {
239243
tmp = lenByte;
240244
if ((tmp & 0x080) == 0x00) { // short form, 1 byte datum
241245
value = tmp;
242-
} else { // long form or indefinite
246+
} else { // long form
243247
tmp &= 0x07f;
244248

245249
// tmp > 4 indicates more than 4Gb of data.
246-
if (tmp < 0 || tmp > 4) {
247-
throw new IOException(mdName + "lengthTag=" + tmp + ", "
248-
+ ((tmp < 0) ? "incorrect DER encoding." : "too big."));
250+
if (tmp > 4) {
251+
throw new IOException(mdName + "lengthTag=" + tmp + ", too big.");
249252
}
250253

251254
value = 0x0ff & in.read();

src/java.base/share/classes/sun/security/util/DerValue.java

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ public DerValue(byte[] encoding) throws IOException {
348348
length = lenByte;
349349
} else { // long form
350350
lenByte &= 0x07f;
351-
if (lenByte < 0 || lenByte > 4) {
351+
if (lenByte > 4) {
352352
throw new IOException("Invalid lenByte");
353353
}
354354
if (len < 2 + lenByte) {
@@ -455,11 +455,7 @@ public final DerInputStream data() {
455455
}
456456

457457
/**
458-
* Returns the data field inside this class. This method should be
459-
* avoided because the data field is mutable but every call always
460-
* return the same object. The caller had better directly use the
461-
* data field. A better way is to call data() that will always return
462-
* a new DerInputStream that points to the beginning of the content.
458+
* Returns the data field inside this class directly.
463459
*
464460
* Both this method and the {@link #data} field should be avoided.
465461
* Consider using {@link #data()} instead.
@@ -825,7 +821,7 @@ private Date getTimeInternal(boolean generalized) throws IOException {
825821
*/
826822

827823
int year, month, day, hour, minute, second, millis;
828-
String type = null;
824+
String type;
829825
int pos = start;
830826
int len = end - start;
831827

@@ -896,15 +892,9 @@ private Date getTimeInternal(boolean generalized) throws IOException {
896892
}
897893
pos++;
898894
switch (precision) {
899-
case 1:
900-
millis += 100 * thisDigit;
901-
break;
902-
case 2:
903-
millis += 10 * thisDigit;
904-
break;
905-
case 3:
906-
millis += thisDigit;
907-
break;
895+
case 1 -> millis += 100 * thisDigit;
896+
case 2 -> millis += 10 * thisDigit;
897+
case 3 -> millis += thisDigit;
908898
}
909899
}
910900
if (precision == 0) {
@@ -1212,6 +1202,6 @@ DerValue[] subs(byte expectedTag, int startLen) throws IOException {
12121202
while (dis.available() > 0) {
12131203
result.add(dis.getDerValue());
12141204
}
1215-
return result.toArray(new DerValue[result.size()]);
1205+
return result.toArray(new DerValue[0]);
12161206
}
12171207
}

0 commit comments

Comments
 (0)