Skip to content

Commit 1feff78

Browse files
committedApr 15, 2022
8281388: Change wrapping of EncryptedPrivateKeyInfo
Reviewed-by: andrew
1 parent 28bdf44 commit 1feff78

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed
 

‎jdk/src/share/classes/javax/crypto/EncryptedPrivateKeyInfo.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -80,12 +80,12 @@ public EncryptedPrivateKeyInfo(byte[] encoded) throws IOException {
8080
"must be non-null");
8181
}
8282

83-
DerValue val = new DerValue(encoded);
83+
this.encoded = encoded.clone();
84+
DerValue val = DerValue.wrap(this.encoded);
8485
if (val.tag != DerValue.tag_Sequence) {
8586
throw new IOException("DER header error: no SEQ tag");
8687
}
8788

88-
this.encoded = encoded.clone();
8989
DerValue[] seq = new DerValue[2];
9090

9191
seq[0] = val.data.getDerValue();

‎jdk/src/share/classes/sun/security/util/DerValue.java

+28
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,34 @@ public DerValue(byte[] buf) throws IOException {
306306
data = init(true, new ByteArrayInputStream(buf, offset, len), allowBER);
307307
}
308308

309+
/**
310+
* Wraps a byte array as a single DerValue.
311+
*
312+
* Attention: no cloning is made.
313+
*
314+
* @param buf the byte array containing the DER-encoded datum
315+
* @returns a new DerValue
316+
*/
317+
public static DerValue wrap(byte[] buf)
318+
throws IOException {
319+
return wrap(buf, 0, buf.length);
320+
}
321+
322+
/**
323+
* Wraps a byte array as a single DerValue.
324+
*
325+
* Attention: no cloning is made.
326+
*
327+
* @param buf the byte array containing the DER-encoded datum
328+
* @param offset where the encoded datum starts inside {@code buf}
329+
* @param len length of bytes to parse inside {@code buf}
330+
* @returns a new DerValue
331+
*/
332+
public static DerValue wrap(byte[] buf, int offset, int len)
333+
throws IOException {
334+
return new DerValue(buf, offset, len);
335+
}
336+
309337
/**
310338
* Get an ASN.1/DER encoded datum from part of a buffer.
311339
* That part of the buffer must hold exactly one datum, including

0 commit comments

Comments
 (0)
Please sign in to comment.