Skip to content

Commit 463ce03

Browse files
martinuyRealCLanger
authored andcommitted
8281388: Change wrapping of EncryptedPrivateKeyInfo
Reviewed-by: mbaesken Backport-of: 405381ce9b44c8b122a06e590e4d8240fd9ba996
1 parent 5829a66 commit 463ce03

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

src/java.base/share/classes/javax/crypto/EncryptedPrivateKeyInfo.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2017, 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
@@ -83,12 +83,12 @@ public EncryptedPrivateKeyInfo(byte[] encoded) throws IOException {
8383
"must be non-null");
8484
}
8585

86-
DerValue val = new DerValue(encoded);
86+
this.encoded = encoded.clone();
87+
DerValue val = DerValue.wrap(this.encoded);
8788
if (val.tag != DerValue.tag_Sequence) {
8889
throw new IOException("DER header error: no SEQ tag");
8990
}
9091

91-
this.encoded = encoded.clone();
9292
DerValue[] seq = new DerValue[2];
9393

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

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,34 @@ public static DerValue wrap(byte tag, DerOutputStream out) {
302302
return new DerValue(tag, out.buf(), 0, out.size(), false);
303303
}
304304

305+
/**
306+
* Wraps a byte array as a single DerValue.
307+
*
308+
* Attention: no cloning is made.
309+
*
310+
* @param buf the byte array containing the DER-encoded datum
311+
* @returns a new DerValue
312+
*/
313+
public static DerValue wrap(byte[] buf)
314+
throws IOException {
315+
return wrap(buf, 0, buf.length);
316+
}
317+
318+
/**
319+
* Wraps a byte array as a single DerValue.
320+
*
321+
* Attention: no cloning is made.
322+
*
323+
* @param buf the byte array containing the DER-encoded datum
324+
* @param offset where the encoded datum starts inside {@code buf}
325+
* @param len length of bytes to parse inside {@code buf}
326+
* @returns a new DerValue
327+
*/
328+
public static DerValue wrap(byte[] buf, int offset, int len)
329+
throws IOException {
330+
return new DerValue(buf, offset, len, true, false);
331+
}
332+
305333
/**
306334
* Parse an ASN.1/BER encoded datum. The entire encoding must hold exactly
307335
* one datum, including its tag and length.

0 commit comments

Comments
 (0)