8296612: CertAttrSet is useless

Reviewed-by: mullan
This commit is contained in:
Weijun Wang 2022-11-10 22:23:58 +00:00
parent 6b456f7a9b
commit 27527b4975
52 changed files with 80 additions and 203 deletions

View file

@ -180,7 +180,7 @@ public final class OAEPParameters extends AlgorithmParametersSpi {
" impl not found");
}
tmp2 = new DerOutputStream();
mdAlgId.derEncode(tmp2);
mdAlgId.encode(tmp2);
tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0),
tmp2);

View file

@ -782,9 +782,9 @@ public class PKCS7 {
// CMSAlgorithmProtection (RFC6211)
DerOutputStream derAp = new DerOutputStream();
DerOutputStream derAlgs = new DerOutputStream();
digAlgID.derEncode(derAlgs);
digAlgID.encode(derAlgs);
DerOutputStream derSigAlg = new DerOutputStream();
sigAlgID.derEncode(derSigAlg);
sigAlgID.encode(derSigAlg);
derAlgs.writeImplicit((byte)0xA1, derSigAlg);
derAp.write(DerValue.tag_Sequence, derAlgs);
authAttrs = new PKCS9Attributes(new PKCS9Attribute[]{

View file

@ -524,7 +524,7 @@ public class PKCS9Attribute implements DerEncoder {
* should be encoded as <code>T61String</code>s.
*/
@Override
public void derEncode(DerOutputStream out) throws IOException {
public void encode(DerOutputStream out) throws IOException {
DerOutputStream temp = new DerOutputStream();
temp.putOID(oid);
switch (index) {

View file

@ -208,11 +208,6 @@ public class SignerInfo implements DerEncoder {
}
}
public void encode(DerOutputStream out) throws IOException {
derEncode(out);
}
/**
* DER encode this object onto an output stream.
* Implements the {@code DerEncoder} interface.
@ -222,7 +217,8 @@ public class SignerInfo implements DerEncoder {
*
* @exception IOException on encoding error.
*/
public void derEncode(DerOutputStream out) throws IOException {
@Override
public void encode(DerOutputStream out) throws IOException {
DerOutputStream seq = new DerOutputStream();
seq.putInteger(version);
DerOutputStream issuerAndSerialNumber = new DerOutputStream();

View file

@ -107,9 +107,10 @@ public class PKCS10Attribute implements DerEncoder {
*
* @exception IOException on encoding errors.
*/
public void derEncode(DerOutputStream out) throws IOException {
@Override
public void encode(DerOutputStream out) throws IOException {
PKCS9Attribute attr = new PKCS9Attribute(attributeId, attributeValue);
attr.derEncode(out);
attr.encode(out);
}
/**

View file

@ -87,16 +87,6 @@ public class PKCS10Attributes implements DerEncoder {
}
}
/**
* Encode the attributes in DER form to the stream.
*
* @param out the OutputStream to marshal the contents to.
* @exception IOException on encoding errors.
*/
public void encode(DerOutputStream out) throws IOException {
derEncode(out);
}
/**
* Encode the attributes in DER form to the stream.
* Implements the {@code DerEncoder} interface.
@ -104,7 +94,8 @@ public class PKCS10Attributes implements DerEncoder {
* @param out the OutputStream to marshal the contents to.
* @exception IOException on encoding errors.
*/
public void derEncode(DerOutputStream out) throws IOException {
@Override
public void encode(DerOutputStream out) throws IOException {
// first copy the elements into an array
Collection<PKCS10Attribute> allAttrs = map.values();
PKCS10Attribute[] attribs =

View file

@ -239,7 +239,7 @@ public final class PSSParameters extends AlgorithmParametersSpi {
}
if (!mdAlgId.getOID().equals(AlgorithmId.SHA_oid)) {
tmp2 = new DerOutputStream();
mdAlgId.derEncode(tmp2);
mdAlgId.encode(tmp2);
tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0),
tmp2);
}

View file

@ -40,7 +40,7 @@ public interface DerEncoder {
*
* @param out the stream on which the DER encoding is written.
*/
void derEncode(DerOutputStream out)
void encode(DerOutputStream out)
throws IOException;
}

View file

@ -404,7 +404,7 @@ extends ByteArrayOutputStream implements DerEncoder {
for (int i = 0; i < set.length; i++) {
streams[i] = new DerOutputStream();
set[i].derEncode(streams[i]);
set[i].encode(streams[i]);
}
// order the element encodings
@ -582,7 +582,8 @@ extends ByteArrayOutputStream implements DerEncoder {
*
* @exception IOException on output error.
*/
public void derEncode(DerOutputStream out) throws IOException {
@Override
public void encode(DerOutputStream out) throws IOException {
out.write(toByteArray());
}
@ -592,7 +593,7 @@ extends ByteArrayOutputStream implements DerEncoder {
* @throws IOException on output error
*/
public DerOutputStream write(DerEncoder encoder) throws IOException {
encoder.derEncode(this);
encoder.encode(this);
return this;
}

View file

@ -616,13 +616,6 @@ public class AVA implements DerEncoder {
return toRFC2253CanonicalString().hashCode();
}
/*
* AVAs are encoded as a SEQUENCE of two elements.
*/
public void encode(DerOutputStream out) throws IOException {
derEncode(out);
}
/**
* DER encode this object onto an output stream.
* Implements the <code>DerEncoder</code> interface.
@ -632,7 +625,8 @@ public class AVA implements DerEncoder {
*
* @exception IOException on encoding error.
*/
public void derEncode(DerOutputStream out) throws IOException {
@Override
public void encode(DerOutputStream out) throws IOException {
DerOutputStream tmp = new DerOutputStream();
tmp.putOID(oid);

View file

@ -147,13 +147,6 @@ public class AlgorithmId implements Serializable, DerEncoder {
algParams.init(encodedParams.clone());
}
/**
* Marshal a DER-encoded "AlgorithmID" sequence on the DER stream.
*/
public final void encode(DerOutputStream out) throws IOException {
derEncode(out);
}
/**
* DER encode this object onto an output stream.
* Implements the <code>DerEncoder</code> interface.
@ -164,7 +157,7 @@ public class AlgorithmId implements Serializable, DerEncoder {
* @exception IOException on encoding error.
*/
@Override
public void derEncode (DerOutputStream out) throws IOException {
public void encode (DerOutputStream out) throws IOException {
DerOutputStream bytes = new DerOutputStream();
bytes.putOID(algid);
@ -242,7 +235,7 @@ public class AlgorithmId implements Serializable, DerEncoder {
*/
public final byte[] encode() throws IOException {
DerOutputStream out = new DerOutputStream();
derEncode(out);
encode(out);
return out.toByteArray();
}

View file

@ -59,11 +59,9 @@ import sun.security.util.DerValue;
* </pre>
*
* @see Extension
* @see CertAttrSet
*/
public class AuthorityInfoAccessExtension extends Extension
implements CertAttrSet {
public class AuthorityInfoAccessExtension extends Extension {
public static final String NAME = "AuthorityInfoAccess";

View file

@ -50,10 +50,8 @@ import sun.security.util.*;
* @author Amit Kapoor
* @author Hemma Prafullchandra
* @see Extension
* @see CertAttrSet
*/
public class AuthorityKeyIdentifierExtension extends Extension
implements CertAttrSet {
public class AuthorityKeyIdentifierExtension extends Extension {
public static final String NAME = "AuthorityKeyIdentifier";

View file

@ -45,11 +45,9 @@ import sun.security.util.*;
* </pre>
* @author Amit Kapoor
* @author Hemma Prafullchandra
* @see CertAttrSet
* @see Extension
*/
public class BasicConstraintsExtension extends Extension
implements CertAttrSet {
public class BasicConstraintsExtension extends Extension {
public static final String NAME = "BasicConstraints";

View file

@ -76,10 +76,8 @@ import sun.security.util.ObjectIdentifier;
* @since 1.4.2
* @see DistributionPoint
* @see Extension
* @see CertAttrSet
*/
public class CRLDistributionPointsExtension extends Extension
implements CertAttrSet {
public class CRLDistributionPointsExtension extends Extension {
public static final String NAME = "CRLDistributionPoints";

View file

@ -41,10 +41,8 @@ import sun.security.util.*;
*
* @author Hemma Prafullchandra
* @see Extension
* @see CertAttrSet
*/
public class CRLNumberExtension extends Extension
implements CertAttrSet {
public class CRLNumberExtension extends Extension {
public static final String NAME = "CRLNumber";

View file

@ -36,10 +36,8 @@ import sun.security.util.*;
* @author Hemma Prafullchandra
* @see java.security.cert.CRLReason
* @see Extension
* @see CertAttrSet
*/
public class CRLReasonCodeExtension extends Extension
implements CertAttrSet {
public class CRLReasonCodeExtension extends Extension {
public static final String NAME = "CRLReasonCode";

View file

@ -1,44 +0,0 @@
/*
* Copyright (c) 1997, 2022, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.security.x509;
import sun.security.util.DerOutputStream;
import java.io.IOException;
/**
* This interface defines a certificate attribute that can be DER-encoded.
*/
public interface CertAttrSet {
/**
* Encodes the attribute to the output stream.
*
* @param out the DerOutputStream to encode the attribute to.
* @exception IOException on write errors.
*/
void encode(DerOutputStream out) throws IOException;
}

View file

@ -36,7 +36,7 @@ import sun.security.util.*;
* @author Amit Kapoor
* @author Hemma Prafullchandra
*/
public class CertificateAlgorithmId implements CertAttrSet {
public class CertificateAlgorithmId implements DerEncoder {
private AlgorithmId algId;
public static final String NAME = "algorithmID";

View file

@ -38,9 +38,9 @@ import sun.security.util.*;
*
* @author Amit Kapoor
* @author Hemma Prafullchandra
* @see CertAttrSet
* @see DerEncoder
*/
public class CertificateExtensions implements CertAttrSet {
public class CertificateExtensions implements DerEncoder {
public static final String NAME = "extensions";

View file

@ -56,10 +56,8 @@ import sun.security.util.DerOutputStream;
* @author Sean Mullan
* @since 1.5
* @see Extension
* @see CertAttrSet
*/
public class CertificateIssuerExtension extends Extension
implements CertAttrSet {
public class CertificateIssuerExtension extends Extension {
public static final String NAME = "CertificateIssuer";

View file

@ -63,10 +63,8 @@ import sun.security.util.DerOutputStream;
* @author Anne Anderson
* @since 1.4
* @see Extension
* @see CertAttrSet
*/
public class CertificatePoliciesExtension extends Extension
implements CertAttrSet {
public class CertificatePoliciesExtension extends Extension {
public static final String NAME = "CertificatePolicies";

View file

@ -36,9 +36,9 @@ import sun.security.util.*;
*
* @author Amit Kapoor
* @author Hemma Prafullchandra
* @see CertAttrSet
* @see DerEncoder
*/
public class CertificateSerialNumber implements CertAttrSet {
public class CertificateSerialNumber implements DerEncoder {
public static final String NAME = "serialNumber";

View file

@ -37,9 +37,9 @@ import sun.security.util.*;
*
* @author Amit Kapoor
* @author Hemma Prafullchandra
* @see CertAttrSet
* @see DerEncoder
*/
public class CertificateSubjectName implements CertAttrSet {
public class CertificateSubjectName implements DerEncoder {
public static final String NAME = "subject";

View file

@ -35,9 +35,9 @@ import sun.security.util.*;
*
* @author Amit Kapoor
* @author Hemma Prafullchandra
* @see CertAttrSet
* @see DerEncoder
*/
public class CertificateValidity implements CertAttrSet {
public class CertificateValidity implements DerEncoder {
public static final String NAME = "validity";
/**
@ -142,7 +142,7 @@ public class CertificateValidity implements CertAttrSet {
// in cases where default constructor is used check for
// null values
if (notBefore == null || notAfter == null) {
throw new IOException("CertAttrSet:CertificateValidity:" +
throw new IOException("CertificateValidity:" +
" null values to encode.\n");
}
DerOutputStream pair = new DerOutputStream();

View file

@ -35,9 +35,9 @@ import sun.security.util.*;
*
* @author Amit Kapoor
* @author Hemma Prafullchandra
* @see CertAttrSet
* @see DerEncoder
*/
public class CertificateVersion implements CertAttrSet {
public class CertificateVersion implements DerEncoder {
/**
* X509Certificate Version 1
*/

View file

@ -36,9 +36,9 @@ import sun.security.util.*;
*
* @author Amit Kapoor
* @author Hemma Prafullchandra
* @see CertAttrSet
* @see DerEncoder
*/
public class CertificateX509Key implements CertAttrSet {
public class CertificateX509Key implements DerEncoder {
public static final String NAME = "key";

View file

@ -76,8 +76,7 @@ import sun.security.util.ObjectIdentifier;
*
* @since 1.4
*/
public class ExtendedKeyUsageExtension extends Extension
implements CertAttrSet {
public class ExtendedKeyUsageExtension extends Extension {
public static final String NAME = "ExtendedKeyUsage";

View file

@ -58,7 +58,7 @@ import sun.security.util.*;
* @author Amit Kapoor
* @author Hemma Prafullchandra
*/
public class Extension implements java.security.cert.Extension {
public class Extension implements java.security.cert.Extension, DerEncoder {
protected ObjectIdentifier extensionId = null;
protected boolean critical = false;
@ -169,6 +169,7 @@ public class Extension implements java.security.cert.Extension {
* @param out the DerOutputStream to write the extension to.
* @exception IOException on encoding errors
*/
@Override
public void encode(DerOutputStream out) throws IOException {
if (extensionId == null)

View file

@ -53,11 +53,9 @@ import sun.security.util.*;
* SkipCerts ::= INTEGER (0..MAX)
* }</pre>
* @author Anne Anderson
* @see CertAttrSet
* @see Extension
*/
public class InhibitAnyPolicyExtension extends Extension
implements CertAttrSet {
public class InhibitAnyPolicyExtension extends Extension {
/**
* Object identifier for "any-policy"

View file

@ -55,8 +55,7 @@ import sun.security.util.*;
*
* @author Sean Mullan
*/
public class InvalidityDateExtension extends Extension
implements CertAttrSet {
public class InvalidityDateExtension extends Extension {
/**
* Attribute name and Reason codes

View file

@ -43,10 +43,8 @@ import sun.security.util.*;
* @author Amit Kapoor
* @author Hemma Prafullchandra
* @see Extension
* @see CertAttrSet
*/
public class IssuerAlternativeNameExtension
extends Extension implements CertAttrSet {
public class IssuerAlternativeNameExtension extends Extension {
public static final String NAME = "IssuerAlternativeName";

View file

@ -63,8 +63,7 @@ import sun.security.util.DerValue;
* @see DistributionPoint
* @since 1.6
*/
public class IssuingDistributionPointExtension extends Extension
implements CertAttrSet {
public class IssuingDistributionPointExtension extends Extension {
public static final String NAME = "IssuingDistributionPoint";

View file

@ -41,10 +41,8 @@ import sun.security.util.*;
* @author Amit Kapoor
* @author Hemma Prafullchandra
* @see Extension
* @see CertAttrSet
*/
public class KeyUsageExtension extends Extension
implements CertAttrSet {
public class KeyUsageExtension extends Extension {
public static final String NAME = "KeyUsage";
public static final String DIGITAL_SIGNATURE = "digital_signature";
@ -196,7 +194,7 @@ public class KeyUsageExtension extends Extension
set(8,val);
} else {
throw new IOException("Attribute name not recognized by"
+ " CertAttrSet:KeyUsage.");
+ " KeyUsage.");
}
encodeThis();
}
@ -225,7 +223,7 @@ public class KeyUsageExtension extends Extension
return isSet(8);
} else {
throw new IOException("Attribute name not recognized by"
+ " CertAttrSet:KeyUsage.");
+ " KeyUsage.");
}
}

View file

@ -57,10 +57,9 @@ import sun.security.pkcs.PKCS9Attribute;
* @author Amit Kapoor
* @author Hemma Prafullchandra
* @see Extension
* @see CertAttrSet
*/
public class NameConstraintsExtension extends Extension
implements CertAttrSet, Cloneable {
implements Cloneable {
public static final String NAME = "NameConstraints";

View file

@ -44,11 +44,9 @@ import sun.security.util.*;
*
* @author Hemma Prafullchandra
* @see Extension
* @see CertAttrSet
*/
public class NetscapeCertTypeExtension extends Extension
implements CertAttrSet {
public class NetscapeCertTypeExtension extends Extension {
public static final String NAME = "NetscapeCertType";
public static final String SSL_CLIENT = "ssl_client";
@ -101,7 +99,7 @@ public class NetscapeCertTypeExtension extends Extension
return mMapData[i].mPosition;
}
throw new IOException("Attribute name [" + name
+ "] not recognized by CertAttrSet:NetscapeCertType.");
+ "] not recognized by NetscapeCertType.");
}
// Encode this extension value

View file

@ -45,10 +45,8 @@ import java.io.IOException;
*
* @author Xuelei Fan
* @see Extension
* @see CertAttrSet
*/
public class OCSPNoCheckExtension extends Extension
implements CertAttrSet {
public class OCSPNoCheckExtension extends Extension {
public static final String NAME = "OCSPNoCheck";

View file

@ -50,10 +50,8 @@ import sun.security.util.*;
* @author Amit Kapoor
* @author Hemma Prafullchandra
* @see Extension
* @see CertAttrSet
*/
public class PolicyConstraintsExtension extends Extension
implements CertAttrSet {
public class PolicyConstraintsExtension extends Extension {
public static final String NAME = "PolicyConstraints";

View file

@ -47,10 +47,8 @@ import sun.security.util.*;
* @author Amit Kapoor
* @author Hemma Prafullchandra
* @see Extension
* @see CertAttrSet
*/
public class PolicyMappingsExtension extends Extension
implements CertAttrSet {
public class PolicyMappingsExtension extends Extension {
public static final String NAME = "PolicyMappings";

View file

@ -55,10 +55,8 @@ import sun.security.util.*;
* @author Amit Kapoor
* @author Hemma Prafullchandra
* @see Extension
* @see CertAttrSet
*/
public class PrivateKeyUsageExtension extends Extension
implements CertAttrSet {
public class PrivateKeyUsageExtension extends Extension {
public static final String NAME = "PrivateKeyUsage";

View file

@ -48,10 +48,8 @@ import sun.security.util.*;
* @author Amit Kapoor
* @author Hemma Prafullchandra
* @see Extension
* @see CertAttrSet
*/
public class SubjectAlternativeNameExtension extends Extension
implements CertAttrSet {
public class SubjectAlternativeNameExtension extends Extension {
public static final String NAME = "SubjectAlternativeName";

View file

@ -63,11 +63,9 @@ import sun.security.util.DerValue;
* </pre>
*
* @see Extension
* @see CertAttrSet
*/
public class SubjectInfoAccessExtension extends Extension
implements CertAttrSet {
public class SubjectInfoAccessExtension extends Extension {
public static final String NAME = "SubjectInfoAccess";

View file

@ -48,10 +48,8 @@ import sun.security.util.*;
* @author Amit Kapoor
* @author Hemma Prafullchandra
* @see Extension
* @see CertAttrSet
*/
public class SubjectKeyIdentifierExtension extends Extension
implements CertAttrSet {
public class SubjectKeyIdentifierExtension extends Extension {
public static final String NAME = "SubjectKeyIdentifier";

View file

@ -1235,7 +1235,7 @@ public class X509CRLImpl extends X509CRL implements DerEncoder {
}
@Override
public void derEncode(DerOutputStream out) throws IOException {
public void encode(DerOutputStream out) throws IOException {
if (signedCRL == null)
throw new IOException("Null CRL to encode");
out.write(signedCRL.clone());

View file

@ -31,7 +31,6 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.math.BigInteger;
import java.security.*;
import java.security.cert.*;
@ -274,24 +273,6 @@ public class X509CertImpl extends X509Certificate implements DerEncoder {
return cert;
}
/**
* Appends the certificate to an output stream.
*
* @param out an input stream to which the certificate is appended.
* @exception CertificateEncodingException on encoding errors.
*/
public void encode(OutputStream out)
throws CertificateEncodingException {
if (signedCert == null)
throw new CertificateEncodingException(
"Null certificate to encode");
try {
out.write(signedCert.clone());
} catch (IOException e) {
throw new CertificateEncodingException(e.toString());
}
}
/**
* DER encode this object onto an output stream.
* Implements the <code>DerEncoder</code> interface.
@ -300,7 +281,8 @@ public class X509CertImpl extends X509Certificate implements DerEncoder {
*
* @exception IOException on encoding error.
*/
public void derEncode(DerOutputStream out) throws IOException {
@Override
public void encode(DerOutputStream out) throws IOException {
if (signedCert == null)
throw new IOException("Null certificate to encode");
out.write(signedCert.clone());

View file

@ -58,7 +58,7 @@ import sun.security.util.HexDumpEncoder;
*
* @author Amit Kapoor
* @author Hemma Prafullchandra
* @see CertAttrSet
* @see DerEncoder
* @see X509CertImpl
*/
public class X509CertInfo {