Skip to content

Commit 18f063b

Browse files
committed
Backport 0d0bd7bd409c0caa5edebe3d1eacf8e5bb48f984
1 parent 72e9063 commit 18f063b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+207
-312
lines changed

src/java.base/share/classes/sun/security/pkcs/PKCS9Attribute.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
package sun.security.pkcs;
2727

2828
import java.io.IOException;
29-
import java.io.OutputStream;
3029
import java.security.cert.CertificateException;
3130
import java.util.Date;
3231
import sun.security.x509.CertificateExtensions;
@@ -527,7 +526,7 @@ public PKCS9Attribute(DerValue derVal) throws IOException {
527526
* should be encoded as <code>T61String</code>s.
528527
*/
529528
@Override
530-
public void derEncode(OutputStream out) throws IOException {
529+
public void derEncode(DerOutputStream out) throws IOException {
531530
DerOutputStream temp = new DerOutputStream();
532531
temp.putOID(oid);
533532
switch (index) {
@@ -648,11 +647,7 @@ public void derEncode(OutputStream out) throws IOException {
648647
default: // can't happen
649648
}
650649

651-
DerOutputStream derOut = new DerOutputStream();
652-
derOut.write(DerValue.tag_Sequence, temp.toByteArray());
653-
654-
out.write(derOut.toByteArray());
655-
650+
out.write(DerValue.tag_Sequence, temp.toByteArray());
656651
}
657652

658653
/**

src/java.base/share/classes/sun/security/pkcs/SignerInfo.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
package sun.security.pkcs;
2727

28-
import java.io.OutputStream;
2928
import java.io.IOException;
3029
import java.math.BigInteger;
3130
import java.security.cert.CertPathValidatorException;
@@ -236,7 +235,7 @@ public void encode(DerOutputStream out) throws IOException {
236235
*
237236
* @exception IOException on encoding error.
238237
*/
239-
public void derEncode(OutputStream out) throws IOException {
238+
public void derEncode(DerOutputStream out) throws IOException {
240239
DerOutputStream seq = new DerOutputStream();
241240
seq.putInteger(version);
242241
DerOutputStream issuerAndSerialNumber = new DerOutputStream();
@@ -258,10 +257,7 @@ public void derEncode(OutputStream out) throws IOException {
258257
if (unauthenticatedAttributes != null)
259258
unauthenticatedAttributes.encode((byte)0xA1, seq);
260259

261-
DerOutputStream tmp = new DerOutputStream();
262-
tmp.write(DerValue.tag_Sequence, seq);
263-
264-
out.write(tmp.toByteArray());
260+
out.write(DerValue.tag_Sequence, seq);
265261
}
266262

267263
/*

src/java.base/share/classes/sun/security/pkcs10/PKCS10Attribute.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
package sun.security.pkcs10;
2727

28-
import java.io.OutputStream;
2928
import java.io.IOException;
3029

3130
import sun.security.pkcs.PKCS9Attribute;
@@ -108,7 +107,7 @@ public PKCS10Attribute(PKCS9Attribute attr) {
108107
*
109108
* @exception IOException on encoding errors.
110109
*/
111-
public void derEncode(OutputStream out) throws IOException {
110+
public void derEncode(DerOutputStream out) throws IOException {
112111
PKCS9Attribute attr = new PKCS9Attribute(attributeId, attributeValue);
113112
attr.derEncode(out);
114113
}

src/java.base/share/classes/sun/security/pkcs10/PKCS10Attributes.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
package sun.security.pkcs10;
2727

2828
import java.io.IOException;
29-
import java.io.OutputStream;
3029
import java.security.cert.CertificateException;
3130
import java.util.Collection;
3231
import java.util.Collections;
@@ -92,7 +91,7 @@ public PKCS10Attributes(DerInputStream in) throws IOException {
9291
* @param out the OutputStream to marshal the contents to.
9392
* @exception IOException on encoding errors.
9493
*/
95-
public void encode(OutputStream out) throws IOException {
94+
public void encode(DerOutputStream out) throws IOException {
9695
derEncode(out);
9796
}
9897

@@ -103,17 +102,14 @@ public void encode(OutputStream out) throws IOException {
103102
* @param out the OutputStream to marshal the contents to.
104103
* @exception IOException on encoding errors.
105104
*/
106-
public void derEncode(OutputStream out) throws IOException {
105+
public void derEncode(DerOutputStream out) throws IOException {
107106
// first copy the elements into an array
108107
Collection<PKCS10Attribute> allAttrs = map.values();
109108
PKCS10Attribute[] attribs =
110109
allAttrs.toArray(new PKCS10Attribute[map.size()]);
111110

112-
DerOutputStream attrOut = new DerOutputStream();
113-
attrOut.putOrderedSetOf(DerValue.createTag(DerValue.TAG_CONTEXT,
114-
true, (byte)0),
115-
attribs);
116-
out.write(attrOut.toByteArray());
111+
out.putOrderedSetOf(
112+
DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0), attribs);
117113
}
118114

119115
/**

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 1999, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2099, 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
@@ -26,7 +26,6 @@
2626
package sun.security.util;
2727

2828
import java.io.IOException;
29-
import java.io.OutputStream;
3029

3130
/**
3231
* Interface to an object that knows how to write its own DER
@@ -41,7 +40,7 @@ public interface DerEncoder {
4140
*
4241
* @param out the stream on which the DER encoding is written.
4342
*/
44-
public void derEncode(OutputStream out)
43+
public void derEncode(DerOutputStream out)
4544
throws IOException;
4645

4746
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
package sun.security.util;
2727

2828
import java.io.ByteArrayOutputStream;
29-
import java.io.OutputStream;
3029
import java.io.IOException;
3130
import java.math.BigInteger;
3231
import java.nio.charset.Charset;
@@ -583,7 +582,7 @@ public void putTag(byte tagClass, boolean form, byte val) {
583582
*
584583
* @exception IOException on output error.
585584
*/
586-
public void derEncode(OutputStream out) throws IOException {
585+
public void derEncode(DerOutputStream out) throws IOException {
587586
out.write(toByteArray());
588587
}
589588

src/java.base/share/classes/sun/security/x509/AVA.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
import java.io.ByteArrayOutputStream;
2929
import java.io.IOException;
30-
import java.io.OutputStream;
3130
import java.io.Reader;
3231
import java.text.Normalizer;
3332
import java.util.*;
@@ -638,14 +637,12 @@ public void encode(DerOutputStream out) throws IOException {
638637
*
639638
* @exception IOException on encoding error.
640639
*/
641-
public void derEncode(OutputStream out) throws IOException {
640+
public void derEncode(DerOutputStream out) throws IOException {
642641
DerOutputStream tmp = new DerOutputStream();
643-
DerOutputStream tmp2 = new DerOutputStream();
644642

645643
tmp.putOID(oid);
646644
value.encode(tmp);
647-
tmp2.write(DerValue.tag_Sequence, tmp);
648-
out.write(tmp2.toByteArray());
645+
out.write(DerValue.tag_Sequence, tmp);
649646
}
650647

651648
private String toKeyword(int format, Map<String, String> oidMap) {

src/java.base/share/classes/sun/security/x509/AlgorithmId.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,8 @@ public final void encode(DerOutputStream out) throws IOException {
164164
* @exception IOException on encoding error.
165165
*/
166166
@Override
167-
public void derEncode (OutputStream out) throws IOException {
167+
public void derEncode (DerOutputStream out) throws IOException {
168168
DerOutputStream bytes = new DerOutputStream();
169-
DerOutputStream tmp = new DerOutputStream();
170169

171170
bytes.putOID(algid);
172171

@@ -230,8 +229,7 @@ public void derEncode (OutputStream out) throws IOException {
230229
} else {
231230
bytes.write(encodedParams);
232231
}
233-
tmp.write(DerValue.tag_Sequence, bytes);
234-
out.write(tmp.toByteArray());
232+
out.write(DerValue.tag_Sequence, bytes);
235233
}
236234

237235

src/java.base/share/classes/sun/security/x509/AuthorityInfoAccessExtension.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
package sun.security.x509;
2727

2828
import java.io.IOException;
29-
import java.io.OutputStream;
3029

3130
import java.util.*;
3231

@@ -149,15 +148,14 @@ public String getName() {
149148
* @param out the DerOutputStream to write the extension to.
150149
* @exception IOException on encoding errors.
151150
*/
152-
public void encode(OutputStream out) throws IOException {
153-
DerOutputStream tmp = new DerOutputStream();
151+
@Override
152+
public void encode(DerOutputStream out) throws IOException {
154153
if (this.extensionValue == null) {
155154
this.extensionId = PKIXExtensions.AuthInfoAccess_Id;
156155
this.critical = false;
157156
encodeThis();
158157
}
159-
super.encode(tmp);
160-
out.write(tmp.toByteArray());
158+
super.encode(out);
161159
}
162160

163161
/**

src/java.base/share/classes/sun/security/x509/AuthorityKeyIdentifierExtension.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 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
@@ -26,7 +26,6 @@
2626
package sun.security.x509;
2727

2828
import java.io.IOException;
29-
import java.io.OutputStream;
3029
import java.util.Enumeration;
3130

3231
import sun.security.util.*;
@@ -215,18 +214,17 @@ public String toString() {
215214
/**
216215
* Write the extension to the OutputStream.
217216
*
218-
* @param out the OutputStream to write the extension to.
217+
* @param out the DerOutputStream to write the extension to.
219218
* @exception IOException on error.
220219
*/
221-
public void encode(OutputStream out) throws IOException {
222-
DerOutputStream tmp = new DerOutputStream();
220+
@Override
221+
public void encode(DerOutputStream out) throws IOException {
223222
if (this.extensionValue == null) {
224223
extensionId = PKIXExtensions.AuthorityKey_Id;
225224
critical = false;
226225
encodeThis();
227226
}
228-
super.encode(tmp);
229-
out.write(tmp.toByteArray());
227+
super.encode(out);
230228
}
231229

232230
/**

0 commit comments

Comments
 (0)