mirror of
https://github.com/openjdk/jdk.git
synced 2026-08-03 14:47:03 +00:00
8381519: Enhance Der Value Handling
Reviewed-by: mschoene, jnimeh, valeriep
This commit is contained in:
parent
33e220059b
commit
48d32601cd
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1996, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1996, 2026, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -157,6 +157,9 @@ public class DerValue {
|
||||
*/
|
||||
public static final byte tag_SetOf = 0x31;
|
||||
|
||||
// Max nested depth for constructed data
|
||||
private static final int MAX_CONSTRUCTED_NEST = 30;
|
||||
|
||||
// This class is mostly immutable except that:
|
||||
//
|
||||
// 1. resetTag() modifies the tag
|
||||
@ -564,6 +567,14 @@ public class DerValue {
|
||||
* @return the octet string held in this DER value
|
||||
*/
|
||||
public byte[] getOctetString() throws IOException {
|
||||
return getOctetString(0);
|
||||
}
|
||||
|
||||
private byte[] getOctetString(int limit) throws IOException {
|
||||
if (++limit > MAX_CONSTRUCTED_NEST) {
|
||||
throw new IOException("Nested OctetString limit reached ("
|
||||
+ MAX_CONSTRUCTED_NEST + ").");
|
||||
}
|
||||
|
||||
if (tag != tag_OctetString && !isConstructed(tag_OctetString)) {
|
||||
throw new IOException(
|
||||
@ -582,7 +593,7 @@ public class DerValue {
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
DerInputStream dis = data();
|
||||
while (dis.available() > 0) {
|
||||
bout.write(dis.getDerValue().getOctetString());
|
||||
bout.write(dis.getDerValue().getOctetString(limit));
|
||||
}
|
||||
return bout.toByteArray();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user