mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8297065: DerOutputStream operations should not throw IOExceptions
Reviewed-by: mullan, valeriep
This commit is contained in:
parent
d83a07b72c
commit
2deb318c9f
109 changed files with 725 additions and 1112 deletions
|
@ -620,14 +620,11 @@ public class AVA implements DerEncoder {
|
|||
* DER encode this object onto an output stream.
|
||||
* Implements the <code>DerEncoder</code> interface.
|
||||
*
|
||||
* @param out
|
||||
* the output stream on which to write the DER encoding.
|
||||
*
|
||||
* @exception IOException on encoding error.
|
||||
* @param out the output stream on which to write the DER encoding.
|
||||
*/
|
||||
@Override
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
DerOutputStream tmp = new DerOutputStream();
|
||||
public void encode(DerOutputStream out) {
|
||||
DerOutputStream tmp = new DerOutputStream();
|
||||
|
||||
tmp.putOID(oid);
|
||||
value.encode(tmp);
|
||||
|
@ -705,12 +702,7 @@ public class AVA implements DerEncoder {
|
|||
if ((typeAndValue.charAt(0) >= '0' && typeAndValue.charAt(0) <= '9') ||
|
||||
!isDerString(value, false))
|
||||
{
|
||||
byte[] data;
|
||||
try {
|
||||
data = value.toByteArray();
|
||||
} catch (IOException ie) {
|
||||
throw new IllegalArgumentException("DER Value conversion");
|
||||
}
|
||||
byte[] data = value.toByteArray();
|
||||
typeAndValue.append('#');
|
||||
HexFormat.of().formatHex(typeAndValue, data);
|
||||
} else {
|
||||
|
@ -722,12 +714,7 @@ public class AVA implements DerEncoder {
|
|||
* NOTE: this implementation only emits DirectoryStrings of the
|
||||
* types returned by isDerString().
|
||||
*/
|
||||
String valStr;
|
||||
try {
|
||||
valStr = new String(value.getDataBytes(), UTF_8);
|
||||
} catch (IOException ie) {
|
||||
throw new IllegalArgumentException("DER Value conversion");
|
||||
}
|
||||
String valStr = new String(value.getDataBytes(), UTF_8);
|
||||
|
||||
/*
|
||||
* 2.4 (cont): If the UTF-8 string does not have any of the
|
||||
|
@ -840,12 +827,7 @@ public class AVA implements DerEncoder {
|
|||
if ((typeAndValue.charAt(0) >= '0' && typeAndValue.charAt(0) <= '9') ||
|
||||
!isDerString(value, true))
|
||||
{
|
||||
byte[] data;
|
||||
try {
|
||||
data = value.toByteArray();
|
||||
} catch (IOException ie) {
|
||||
throw new IllegalArgumentException("DER Value conversion");
|
||||
}
|
||||
byte[] data = value.toByteArray();
|
||||
typeAndValue.append('#');
|
||||
HexFormat.of().formatHex(typeAndValue, data);
|
||||
} else {
|
||||
|
@ -857,12 +839,7 @@ public class AVA implements DerEncoder {
|
|||
* NOTE: this implementation only emits DirectoryStrings of the
|
||||
* types returned by isDerString().
|
||||
*/
|
||||
String valStr;
|
||||
try {
|
||||
valStr = new String(value.getDataBytes(), UTF_8);
|
||||
} catch (IOException ie) {
|
||||
throw new IllegalArgumentException("DER Value conversion");
|
||||
}
|
||||
String valStr = new String(value.getDataBytes(), UTF_8);
|
||||
|
||||
/*
|
||||
* 2.4 (cont): If the UTF-8 string does not have any of the
|
||||
|
|
|
@ -72,7 +72,7 @@ public final class AccessDescription {
|
|||
return accessLocation;
|
||||
}
|
||||
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
public void encode(DerOutputStream out) {
|
||||
DerOutputStream tmp = new DerOutputStream();
|
||||
tmp.putOID(accessMethod);
|
||||
accessLocation.encode(tmp);
|
||||
|
|
|
@ -153,13 +153,10 @@ public class AlgorithmId implements Serializable, DerEncoder {
|
|||
* DER encode this object onto an output stream.
|
||||
* Implements the <code>DerEncoder</code> interface.
|
||||
*
|
||||
* @param out
|
||||
* the output stream on which to write the DER encoding.
|
||||
*
|
||||
* @exception IOException on encoding error.
|
||||
* @param out the output stream on which to write the DER encoding.
|
||||
*/
|
||||
@Override
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
public void encode(DerOutputStream out) {
|
||||
DerOutputStream bytes = new DerOutputStream();
|
||||
|
||||
bytes.putOID(algid);
|
||||
|
@ -220,7 +217,7 @@ public class AlgorithmId implements Serializable, DerEncoder {
|
|||
bytes.putNull();
|
||||
}
|
||||
} else {
|
||||
bytes.write(encodedParams);
|
||||
bytes.writeBytes(encodedParams);
|
||||
}
|
||||
out.write(DerValue.tag_Sequence, bytes);
|
||||
}
|
||||
|
@ -229,7 +226,7 @@ public class AlgorithmId implements Serializable, DerEncoder {
|
|||
/**
|
||||
* Returns the DER-encoded X.509 AlgorithmId as a byte array.
|
||||
*/
|
||||
public final byte[] encode() throws IOException {
|
||||
public final byte[] encode() {
|
||||
DerOutputStream out = new DerOutputStream();
|
||||
encode(out);
|
||||
return out.toByteArray();
|
||||
|
|
|
@ -76,10 +76,9 @@ public class AuthorityInfoAccessExtension extends Extension {
|
|||
*
|
||||
* @param accessDescriptions the List of AccessDescription,
|
||||
* cannot be null or empty.
|
||||
* @throws IOException on error
|
||||
*/
|
||||
public AuthorityInfoAccessExtension(
|
||||
List<AccessDescription> accessDescriptions) throws IOException {
|
||||
List<AccessDescription> accessDescriptions) {
|
||||
if (accessDescriptions == null || accessDescriptions.isEmpty()) {
|
||||
throw new IllegalArgumentException("accessDescriptions is null or empty");
|
||||
}
|
||||
|
@ -138,10 +137,9 @@ public class AuthorityInfoAccessExtension extends Extension {
|
|||
* Write the extension to the DerOutputStream.
|
||||
*
|
||||
* @param out the DerOutputStream to write the extension to.
|
||||
* @exception IOException on encoding errors.
|
||||
*/
|
||||
@Override
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
public void encode(DerOutputStream out) {
|
||||
if (this.extensionValue == null) {
|
||||
this.extensionId = PKIXExtensions.AuthInfoAccess_Id;
|
||||
this.critical = false;
|
||||
|
@ -151,7 +149,7 @@ public class AuthorityInfoAccessExtension extends Extension {
|
|||
}
|
||||
|
||||
// Encode this extension value
|
||||
private void encodeThis() throws IOException {
|
||||
private void encodeThis() {
|
||||
if (accessDescriptions.isEmpty()) {
|
||||
this.extensionValue = null;
|
||||
} else {
|
||||
|
|
|
@ -65,7 +65,7 @@ public class AuthorityKeyIdentifierExtension extends Extension {
|
|||
private SerialNumber serialNum = null;
|
||||
|
||||
// Encode only the extension value
|
||||
private void encodeThis() throws IOException {
|
||||
private void encodeThis() {
|
||||
if (id == null && names == null && serialNum == null) {
|
||||
this.extensionValue = null;
|
||||
return;
|
||||
|
@ -78,15 +78,11 @@ public class AuthorityKeyIdentifierExtension extends Extension {
|
|||
tmp.writeImplicit(DerValue.createTag(DerValue.TAG_CONTEXT,
|
||||
false, TAG_ID), tmp1);
|
||||
}
|
||||
try {
|
||||
if (names != null) {
|
||||
DerOutputStream tmp1 = new DerOutputStream();
|
||||
names.encode(tmp1);
|
||||
tmp.writeImplicit(DerValue.createTag(DerValue.TAG_CONTEXT,
|
||||
true, TAG_NAMES), tmp1);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new IOException(e.toString());
|
||||
if (names != null) {
|
||||
DerOutputStream tmp1 = new DerOutputStream();
|
||||
names.encode(tmp1);
|
||||
tmp.writeImplicit(DerValue.createTag(DerValue.TAG_CONTEXT,
|
||||
true, TAG_NAMES), tmp1);
|
||||
}
|
||||
if (serialNum != null) {
|
||||
DerOutputStream tmp1 = new DerOutputStream();
|
||||
|
@ -106,11 +102,9 @@ public class AuthorityKeyIdentifierExtension extends Extension {
|
|||
* @param names the GeneralNames associated with this extension
|
||||
* @param sn the CertificateSerialNumber associated with
|
||||
* this extension.
|
||||
* @exception IOException on error.
|
||||
*/
|
||||
public AuthorityKeyIdentifierExtension(KeyIdentifier kid, GeneralNames names,
|
||||
SerialNumber sn)
|
||||
throws IOException {
|
||||
SerialNumber sn) {
|
||||
if (kid == null && names == null && sn == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"AuthorityKeyIdentifierExtension cannot be empty");
|
||||
|
@ -205,10 +199,9 @@ public class AuthorityKeyIdentifierExtension extends Extension {
|
|||
* Write the extension to the OutputStream.
|
||||
*
|
||||
* @param out the DerOutputStream to write the extension to.
|
||||
* @exception IOException on error.
|
||||
*/
|
||||
@Override
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
public void encode(DerOutputStream out) {
|
||||
if (this.extensionValue == null) {
|
||||
extensionId = PKIXExtensions.AuthorityKey_Id;
|
||||
critical = false;
|
||||
|
|
|
@ -56,7 +56,7 @@ public class BasicConstraintsExtension extends Extension {
|
|||
private int pathLen = -1;
|
||||
|
||||
// Encode this extension value
|
||||
private void encodeThis() throws IOException {
|
||||
private void encodeThis() {
|
||||
DerOutputStream out = new DerOutputStream();
|
||||
DerOutputStream tmp = new DerOutputStream();
|
||||
|
||||
|
@ -78,7 +78,7 @@ public class BasicConstraintsExtension extends Extension {
|
|||
* @param ca true, if the subject of the Certificate is a CA.
|
||||
* @param len specifies the depth of the certification path.
|
||||
*/
|
||||
public BasicConstraintsExtension(boolean ca, int len) throws IOException {
|
||||
public BasicConstraintsExtension(boolean ca, int len) {
|
||||
this(Boolean.valueOf(ca), ca, len);
|
||||
}
|
||||
|
||||
|
@ -89,8 +89,7 @@ public class BasicConstraintsExtension extends Extension {
|
|||
* @param ca true, if the subject of the Certificate is a CA.
|
||||
* @param len specifies the depth of the certification path.
|
||||
*/
|
||||
public BasicConstraintsExtension(Boolean critical, boolean ca, int len)
|
||||
throws IOException {
|
||||
public BasicConstraintsExtension(Boolean critical, boolean ca, int len) {
|
||||
this.ca = ca;
|
||||
this.pathLen = len;
|
||||
this.extensionId = PKIXExtensions.BasicConstraints_Id;
|
||||
|
@ -178,7 +177,7 @@ public class BasicConstraintsExtension extends Extension {
|
|||
* @param out the DerOutputStream to encode the extension to.
|
||||
*/
|
||||
@Override
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
public void encode(DerOutputStream out) {
|
||||
if (extensionValue == null) {
|
||||
this.extensionId = PKIXExtensions.BasicConstraints_Id;
|
||||
critical = ca;
|
||||
|
|
|
@ -93,10 +93,9 @@ public class CRLDistributionPointsExtension extends Extension {
|
|||
* DistributionPoint; the criticality is set to false.
|
||||
*
|
||||
* @param distributionPoints the list of distribution points
|
||||
* @throws IOException on error
|
||||
*/
|
||||
public CRLDistributionPointsExtension(
|
||||
List<DistributionPoint> distributionPoints) throws IOException {
|
||||
List<DistributionPoint> distributionPoints) {
|
||||
|
||||
this(false, distributionPoints);
|
||||
}
|
||||
|
@ -108,10 +107,9 @@ public class CRLDistributionPointsExtension extends Extension {
|
|||
* @param isCritical the criticality setting.
|
||||
* @param distributionPoints the list of distribution points,
|
||||
* cannot be null or empty.
|
||||
* @throws IOException on error
|
||||
*/
|
||||
public CRLDistributionPointsExtension(boolean isCritical,
|
||||
List<DistributionPoint> distributionPoints) throws IOException {
|
||||
List<DistributionPoint> distributionPoints) {
|
||||
|
||||
this(PKIXExtensions.CRLDistributionPoints_Id, isCritical,
|
||||
distributionPoints, NAME);
|
||||
|
@ -122,7 +120,7 @@ public class CRLDistributionPointsExtension extends Extension {
|
|||
*/
|
||||
protected CRLDistributionPointsExtension(ObjectIdentifier extensionId,
|
||||
boolean isCritical, List<DistributionPoint> distributionPoints,
|
||||
String extensionName) throws IOException {
|
||||
String extensionName) {
|
||||
|
||||
if (distributionPoints == null || distributionPoints.isEmpty()) {
|
||||
throw new IllegalArgumentException(
|
||||
|
@ -189,10 +187,9 @@ public class CRLDistributionPointsExtension extends Extension {
|
|||
* Write the extension to the DerOutputStream.
|
||||
*
|
||||
* @param out the DerOutputStream to write the extension to.
|
||||
* @exception IOException on encoding errors.
|
||||
*/
|
||||
@Override
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
public void encode(DerOutputStream out) {
|
||||
encode(out, PKIXExtensions.CRLDistributionPoints_Id, false);
|
||||
}
|
||||
|
||||
|
@ -201,7 +198,7 @@ public class CRLDistributionPointsExtension extends Extension {
|
|||
* (Also called by the subclass)
|
||||
*/
|
||||
protected void encode(DerOutputStream out, ObjectIdentifier extensionId,
|
||||
boolean isCritical) throws IOException {
|
||||
boolean isCritical) {
|
||||
|
||||
if (this.extensionValue == null) {
|
||||
this.extensionId = extensionId;
|
||||
|
@ -221,7 +218,7 @@ public class CRLDistributionPointsExtension extends Extension {
|
|||
|
||||
|
||||
// Encode this extension value
|
||||
private void encodeThis() throws IOException {
|
||||
private void encodeThis() {
|
||||
if (distributionPoints.isEmpty()) {
|
||||
this.extensionValue = null;
|
||||
} else {
|
||||
|
|
|
@ -137,30 +137,24 @@ public class CRLExtensions {
|
|||
* @param out the DerOutputStream to marshal the contents to.
|
||||
* @param isExplicit the tag indicating whether this is an entry
|
||||
* extension (false) or a CRL extension (true).
|
||||
* @exception CRLException on encoding errors.
|
||||
*/
|
||||
public void encode(OutputStream out, boolean isExplicit)
|
||||
throws CRLException {
|
||||
try {
|
||||
DerOutputStream extOut = new DerOutputStream();
|
||||
for (Extension ext : map.values()) {
|
||||
ext.encode(extOut);
|
||||
}
|
||||
|
||||
DerOutputStream seq = new DerOutputStream();
|
||||
seq.write(DerValue.tag_Sequence, extOut);
|
||||
|
||||
DerOutputStream tmp = new DerOutputStream();
|
||||
if (isExplicit)
|
||||
tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT,
|
||||
true, (byte)0), seq);
|
||||
else
|
||||
tmp = seq;
|
||||
|
||||
out.write(tmp.toByteArray());
|
||||
} catch (IOException e) {
|
||||
throw new CRLException("Encoding error: " + e.toString());
|
||||
public void encode(DerOutputStream out, boolean isExplicit) {
|
||||
DerOutputStream extOut = new DerOutputStream();
|
||||
for (Extension ext : map.values()) {
|
||||
ext.encode(extOut);
|
||||
}
|
||||
|
||||
DerOutputStream seq = new DerOutputStream();
|
||||
seq.write(DerValue.tag_Sequence, extOut);
|
||||
|
||||
DerOutputStream tmp = new DerOutputStream();
|
||||
if (isExplicit)
|
||||
tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT,
|
||||
true, (byte) 0), seq);
|
||||
else
|
||||
tmp = seq;
|
||||
|
||||
out.writeBytes(tmp.toByteArray());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -53,7 +53,7 @@ public class CRLNumberExtension extends Extension {
|
|||
private final String extensionLabel;
|
||||
|
||||
// Encode this extension value
|
||||
private void encodeThis() throws IOException {
|
||||
private void encodeThis() {
|
||||
if (crlNumber == null) {
|
||||
this.extensionValue = null;
|
||||
return;
|
||||
|
@ -69,7 +69,7 @@ public class CRLNumberExtension extends Extension {
|
|||
*
|
||||
* @param crlNum the value to be set for the extension.
|
||||
*/
|
||||
public CRLNumberExtension(int crlNum) throws IOException {
|
||||
public CRLNumberExtension(int crlNum) {
|
||||
this(PKIXExtensions.CRLNumber_Id, false, BigInteger.valueOf(crlNum),
|
||||
NAME, LABEL);
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ public class CRLNumberExtension extends Extension {
|
|||
*
|
||||
* @param crlNum the value to be set for the extension, cannot be null
|
||||
*/
|
||||
public CRLNumberExtension(BigInteger crlNum) throws IOException {
|
||||
public CRLNumberExtension(BigInteger crlNum) {
|
||||
this(PKIXExtensions.CRLNumber_Id, false, crlNum, NAME, LABEL);
|
||||
}
|
||||
|
||||
|
@ -88,8 +88,8 @@ public class CRLNumberExtension extends Extension {
|
|||
* Creates the extension (also called by the subclass).
|
||||
*/
|
||||
protected CRLNumberExtension(ObjectIdentifier extensionId,
|
||||
boolean isCritical, BigInteger crlNum, String extensionName,
|
||||
String extensionLabel) throws IOException {
|
||||
boolean isCritical, BigInteger crlNum, String extensionName,
|
||||
String extensionLabel) {
|
||||
|
||||
if (crlNum == null) {
|
||||
throw new IllegalArgumentException("CRL number cannot be null");
|
||||
|
@ -158,10 +158,9 @@ public class CRLNumberExtension extends Extension {
|
|||
* Write the extension to the DerOutputStream.
|
||||
*
|
||||
* @param out the DerOutputStream to write the extension to.
|
||||
* @exception IOException on encoding errors.
|
||||
*/
|
||||
@Override
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
public void encode(DerOutputStream out) {
|
||||
encode(out, PKIXExtensions.CRLNumber_Id, true);
|
||||
}
|
||||
|
||||
|
@ -170,7 +169,7 @@ public class CRLNumberExtension extends Extension {
|
|||
* (Also called by the subclass)
|
||||
*/
|
||||
protected void encode(DerOutputStream out, ObjectIdentifier extensionId,
|
||||
boolean isCritical) throws IOException {
|
||||
boolean isCritical) {
|
||||
|
||||
if (this.extensionValue == null) {
|
||||
this.extensionId = extensionId;
|
||||
|
|
|
@ -45,7 +45,7 @@ public class CRLReasonCodeExtension extends Extension {
|
|||
|
||||
private int reasonCode;
|
||||
|
||||
private void encodeThis() throws IOException {
|
||||
private void encodeThis() {
|
||||
if (reasonCode == 0) {
|
||||
this.extensionValue = null;
|
||||
return;
|
||||
|
@ -71,8 +71,7 @@ public class CRLReasonCodeExtension extends Extension {
|
|||
* @param critical true if the extension is to be treated as critical.
|
||||
* @param reason the enumerated value for the reason code, must be positive.
|
||||
*/
|
||||
public CRLReasonCodeExtension(boolean critical, int reason)
|
||||
throws IOException {
|
||||
public CRLReasonCodeExtension(boolean critical, int reason) {
|
||||
if (reason <= 0) {
|
||||
throw new IllegalArgumentException("reason code must be positive");
|
||||
}
|
||||
|
@ -110,10 +109,9 @@ public class CRLReasonCodeExtension extends Extension {
|
|||
* Write the extension to the DerOutputStream.
|
||||
*
|
||||
* @param out the DerOutputStream to write the extension to.
|
||||
* @exception IOException on encoding errors.
|
||||
*/
|
||||
@Override
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
public void encode(DerOutputStream out) {
|
||||
if (this.extensionValue == null) {
|
||||
this.extensionId = PKIXExtensions.ReasonCode_Id;
|
||||
this.critical = false;
|
||||
|
|
|
@ -85,10 +85,9 @@ public class CertificateAlgorithmId implements DerEncoder {
|
|||
* Encode the algorithm identifier in DER form to the stream.
|
||||
*
|
||||
* @param out the DerOutputStream to marshal the contents to.
|
||||
* @exception IOException on errors.
|
||||
*/
|
||||
@Override
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
public void encode(DerOutputStream out) {
|
||||
algId.encode(out);
|
||||
}
|
||||
|
||||
|
|
|
@ -137,11 +137,9 @@ public class CertificateExtensions implements DerEncoder {
|
|||
* the context specific tag as needed in the X.509 v3 certificate.
|
||||
*
|
||||
* @param out the DerOutputStream to marshal the contents to.
|
||||
* @exception CertificateException on encoding errors.
|
||||
* @exception IOException on errors.
|
||||
*/
|
||||
@Override
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
public void encode(DerOutputStream out) {
|
||||
encode(out, false);
|
||||
}
|
||||
|
||||
|
@ -150,11 +148,8 @@ public class CertificateExtensions implements DerEncoder {
|
|||
*
|
||||
* @param out the DerOutputStream to marshal the contents to.
|
||||
* @param isCertReq if true then no context specific tag is added.
|
||||
* @exception CertificateException on encoding errors.
|
||||
* @exception IOException on errors.
|
||||
*/
|
||||
public void encode(DerOutputStream out, boolean isCertReq)
|
||||
throws IOException {
|
||||
public void encode(DerOutputStream out, boolean isCertReq) {
|
||||
DerOutputStream extOut = new DerOutputStream();
|
||||
for (Extension ext : map.values()) {
|
||||
ext.encode(extOut);
|
||||
|
|
|
@ -66,7 +66,7 @@ public class CertificateIssuerExtension extends Extension {
|
|||
/**
|
||||
* Encode this extension
|
||||
*/
|
||||
private void encodeThis() throws IOException {
|
||||
private void encodeThis() {
|
||||
if (names == null || names.isEmpty()) {
|
||||
this.extensionValue = null;
|
||||
return;
|
||||
|
@ -81,9 +81,8 @@ public class CertificateIssuerExtension extends Extension {
|
|||
* Criticality is automatically set to true.
|
||||
*
|
||||
* @param issuer the certificate issuer, cannot be null or empty.
|
||||
* @throws IOException on error
|
||||
*/
|
||||
public CertificateIssuerExtension(GeneralNames issuer) throws IOException {
|
||||
public CertificateIssuerExtension(GeneralNames issuer) {
|
||||
if (issuer == null || issuer.isEmpty()) {
|
||||
throw new IllegalArgumentException("issuer cannot be null or empty");
|
||||
}
|
||||
|
@ -128,10 +127,9 @@ public class CertificateIssuerExtension extends Extension {
|
|||
* Write the extension to the OutputStream.
|
||||
*
|
||||
* @param out the DerOutputStream to write the extension to
|
||||
* @exception IOException on encoding errors
|
||||
*/
|
||||
@Override
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
public void encode(DerOutputStream out) {
|
||||
if (extensionValue == null) {
|
||||
extensionId = PKIXExtensions.CertificateIssuer_Id;
|
||||
critical = true;
|
||||
|
|
|
@ -74,7 +74,7 @@ public class CertificatePoliciesExtension extends Extension {
|
|||
private List<PolicyInformation> certPolicies;
|
||||
|
||||
// Encode this extension value.
|
||||
private void encodeThis() throws IOException {
|
||||
private void encodeThis() {
|
||||
if (certPolicies == null || certPolicies.isEmpty()) {
|
||||
this.extensionValue = null;
|
||||
} else {
|
||||
|
@ -96,8 +96,7 @@ public class CertificatePoliciesExtension extends Extension {
|
|||
*
|
||||
* @param certPolicies the List of PolicyInformation.
|
||||
*/
|
||||
public CertificatePoliciesExtension(List<PolicyInformation> certPolicies)
|
||||
throws IOException {
|
||||
public CertificatePoliciesExtension(List<PolicyInformation> certPolicies) {
|
||||
this(Boolean.FALSE, certPolicies);
|
||||
}
|
||||
|
||||
|
@ -109,7 +108,7 @@ public class CertificatePoliciesExtension extends Extension {
|
|||
* @param certPolicies the List of PolicyInformation, cannot be null or empty.
|
||||
*/
|
||||
public CertificatePoliciesExtension(Boolean critical,
|
||||
List<PolicyInformation> certPolicies) throws IOException {
|
||||
List<PolicyInformation> certPolicies) {
|
||||
if (certPolicies == null || certPolicies.isEmpty()) {
|
||||
throw new IllegalArgumentException(
|
||||
"certificate policies cannot be null or empty");
|
||||
|
@ -168,10 +167,9 @@ public class CertificatePoliciesExtension extends Extension {
|
|||
* Write the extension to the DerOutputStream.
|
||||
*
|
||||
* @param out the DerOutputStream to write the extension to.
|
||||
* @exception IOException on encoding errors.
|
||||
*/
|
||||
@Override
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
public void encode(DerOutputStream out) {
|
||||
if (extensionValue == null) {
|
||||
extensionId = PKIXExtensions.CertificatePolicies_Id;
|
||||
critical = false;
|
||||
|
|
|
@ -37,7 +37,7 @@ import sun.security.util.*;
|
|||
* @author Amit Kapoor
|
||||
* @author Hemma Prafullchandra
|
||||
*/
|
||||
public class CertificatePolicyId {
|
||||
public class CertificatePolicyId implements DerEncoder {
|
||||
private final ObjectIdentifier id;
|
||||
|
||||
/**
|
||||
|
@ -79,9 +79,9 @@ public class CertificatePolicyId {
|
|||
* Write the CertificatePolicyId to the DerOutputStream.
|
||||
*
|
||||
* @param out the DerOutputStream to write the object to.
|
||||
* @exception IOException on errors.
|
||||
*/
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
@Override
|
||||
public void encode(DerOutputStream out) {
|
||||
out.putOID(id);
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ import sun.security.util.*;
|
|||
* @author Amit Kapoor
|
||||
* @author Hemma Prafullchandra
|
||||
*/
|
||||
public class CertificatePolicyMap {
|
||||
public class CertificatePolicyMap implements DerEncoder {
|
||||
private final CertificatePolicyId issuerDomain;
|
||||
private final CertificatePolicyId subjectDomain;
|
||||
|
||||
|
@ -94,9 +94,9 @@ public class CertificatePolicyMap {
|
|||
* Write the CertificatePolicyMap to the DerOutputStream.
|
||||
*
|
||||
* @param out the DerOutputStream to write the object to.
|
||||
* @exception IOException on errors.
|
||||
*/
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
@Override
|
||||
public void encode(DerOutputStream out) {
|
||||
DerOutputStream tmp = new DerOutputStream();
|
||||
|
||||
issuerDomain.encode(tmp);
|
||||
|
|
|
@ -38,7 +38,7 @@ import sun.security.util.*;
|
|||
* @author Amit Kapoor
|
||||
* @author Hemma Prafullchandra
|
||||
*/
|
||||
public class CertificatePolicySet {
|
||||
public class CertificatePolicySet implements DerEncoder {
|
||||
|
||||
private final Vector<CertificatePolicyId> ids;
|
||||
|
||||
|
@ -82,7 +82,8 @@ public class CertificatePolicySet {
|
|||
*
|
||||
* @param out the DerOutputStream to encode the data to.
|
||||
*/
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
@Override
|
||||
public void encode(DerOutputStream out) {
|
||||
DerOutputStream tmp = new DerOutputStream();
|
||||
|
||||
for (int i = 0; i < ids.size(); i++) {
|
||||
|
|
|
@ -104,10 +104,9 @@ public class CertificateSerialNumber implements DerEncoder {
|
|||
* Encode the serial number in DER form to the stream.
|
||||
*
|
||||
* @param out the DerOutputStream to marshal the contents to.
|
||||
* @exception IOException on errors.
|
||||
*/
|
||||
@Override
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
public void encode(DerOutputStream out) {
|
||||
serial.encode(out);
|
||||
}
|
||||
|
||||
|
|
|
@ -91,10 +91,9 @@ public class CertificateSubjectName implements DerEncoder {
|
|||
* Encode the name in DER form to the stream.
|
||||
*
|
||||
* @param out the DerOutputStream to marshal the contents to.
|
||||
* @exception IOException on errors.
|
||||
*/
|
||||
@Override
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
public void encode(DerOutputStream out) {
|
||||
dnName.encode(out);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,10 +123,9 @@ public class CertificateValidity implements DerEncoder {
|
|||
* Encode the CertificateValidity period in DER form to the stream.
|
||||
*
|
||||
* @param out the DerOutputStream to marshal the contents to.
|
||||
* @exception IOException on errors.
|
||||
*/
|
||||
@Override
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
public void encode(DerOutputStream out) {
|
||||
|
||||
DerOutputStream pair = new DerOutputStream();
|
||||
|
||||
|
|
|
@ -146,10 +146,9 @@ public class CertificateVersion implements DerEncoder {
|
|||
* Encode the CertificateVersion period in DER form to the stream.
|
||||
*
|
||||
* @param out the DerOutputStream to marshal the contents to.
|
||||
* @exception IOException on errors.
|
||||
*/
|
||||
@Override
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
public void encode(DerOutputStream out) {
|
||||
// Nothing for default
|
||||
if (version == V1) {
|
||||
return;
|
||||
|
|
|
@ -88,11 +88,10 @@ public class CertificateX509Key implements DerEncoder {
|
|||
* Encode the key in DER form to the stream.
|
||||
*
|
||||
* @param out the DerOutputStream to marshal the contents to.
|
||||
* @exception IOException on errors.
|
||||
*/
|
||||
@Override
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
out.write(key.getEncoded());
|
||||
public void encode(DerOutputStream out) {
|
||||
out.writeBytes(key.getEncoded());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -150,9 +150,9 @@ public class DNSName implements GeneralNameInterface {
|
|||
* Encode the DNSName into the DerOutputStream.
|
||||
*
|
||||
* @param out the DER stream to encode the DNSName to.
|
||||
* @exception IOException on encoding errors.
|
||||
*/
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
@Override
|
||||
public void encode(DerOutputStream out) {
|
||||
out.putIA5String(name);
|
||||
}
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ public class DeltaCRLIndicatorExtension extends CRLNumberExtension {
|
|||
*
|
||||
* @param crlNum the value to be set for the extension.
|
||||
*/
|
||||
public DeltaCRLIndicatorExtension(int crlNum) throws IOException {
|
||||
public DeltaCRLIndicatorExtension(int crlNum) {
|
||||
super(PKIXExtensions.DeltaCRLIndicator_Id, true,
|
||||
BigInteger.valueOf(crlNum), NAME, LABEL);
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ public class DeltaCRLIndicatorExtension extends CRLNumberExtension {
|
|||
*
|
||||
* @param crlNum the value to be set for the extension.
|
||||
*/
|
||||
public DeltaCRLIndicatorExtension(BigInteger crlNum) throws IOException {
|
||||
public DeltaCRLIndicatorExtension(BigInteger crlNum) {
|
||||
super(PKIXExtensions.DeltaCRLIndicator_Id, true, crlNum, NAME, LABEL);
|
||||
}
|
||||
|
||||
|
@ -102,10 +102,9 @@ public class DeltaCRLIndicatorExtension extends CRLNumberExtension {
|
|||
* Writes the extension to the DerOutputStream.
|
||||
*
|
||||
* @param out the DerOutputStream to write the extension to.
|
||||
* @exception IOException on encoding errors.
|
||||
*/
|
||||
@Override
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
public void encode(DerOutputStream out) {
|
||||
super.encode(out, PKIXExtensions.DeltaCRLIndicator_Id, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import java.io.IOException;
|
|||
import java.util.*;
|
||||
|
||||
import sun.security.util.BitArray;
|
||||
import sun.security.util.DerEncoder;
|
||||
import sun.security.util.DerOutputStream;
|
||||
import sun.security.util.DerValue;
|
||||
|
||||
|
@ -93,7 +94,7 @@ import sun.security.util.DerValue;
|
|||
* @since 1.4.2
|
||||
* @see CRLDistributionPointsExtension
|
||||
*/
|
||||
public class DistributionPoint {
|
||||
public class DistributionPoint implements DerEncoder {
|
||||
|
||||
// reason flag bits
|
||||
// NOTE that these are NOT quite the same as the CRL reason code extension
|
||||
|
@ -275,9 +276,9 @@ public class DistributionPoint {
|
|||
* Write the DistributionPoint value to the DerOutputStream.
|
||||
*
|
||||
* @param out the DerOutputStream to write the extension to.
|
||||
* @exception IOException on error.
|
||||
*/
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
@Override
|
||||
public void encode(DerOutputStream out) {
|
||||
DerOutputStream tagged = new DerOutputStream();
|
||||
|
||||
// NOTE: only one of pointNames and pointRDN can be set
|
||||
|
|
|
@ -28,6 +28,7 @@ package sun.security.x509;
|
|||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
import sun.security.util.DerEncoder;
|
||||
import sun.security.util.DerOutputStream;
|
||||
import sun.security.util.DerValue;
|
||||
|
||||
|
@ -78,7 +79,7 @@ import sun.security.util.DerValue;
|
|||
* @see IssuingDistributionPointExtension
|
||||
* @since 1.6
|
||||
*/
|
||||
public class DistributionPointName {
|
||||
public class DistributionPointName implements DerEncoder {
|
||||
|
||||
// ASN.1 context specific tag values
|
||||
private static final byte TAG_FULL_NAME = 0;
|
||||
|
@ -164,9 +165,9 @@ public class DistributionPointName {
|
|||
* Encodes the distribution point name and writes it to the DerOutputStream.
|
||||
*
|
||||
* @param out the output stream.
|
||||
* @exception IOException on encoding error.
|
||||
*/
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
@Override
|
||||
public void encode(DerOutputStream out) {
|
||||
|
||||
DerOutputStream theChoice = new DerOutputStream();
|
||||
|
||||
|
|
|
@ -124,9 +124,9 @@ public class EDIPartyName implements GeneralNameInterface {
|
|||
* Encode the EDI party name into the DerOutputStream.
|
||||
*
|
||||
* @param out the DER stream to encode the EDIPartyName to.
|
||||
* @exception IOException on encoding errors.
|
||||
*/
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
@Override
|
||||
public void encode(DerOutputStream out) {
|
||||
DerOutputStream tagged = new DerOutputStream();
|
||||
DerOutputStream tmp = new DerOutputStream();
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ public class ExtendedKeyUsageExtension extends Extension {
|
|||
private Vector<ObjectIdentifier> keyUsages;
|
||||
|
||||
// Encode this extension value.
|
||||
private void encodeThis() throws IOException {
|
||||
private void encodeThis() {
|
||||
if (keyUsages == null || keyUsages.isEmpty()) {
|
||||
this.extensionValue = null;
|
||||
return;
|
||||
|
@ -108,8 +108,7 @@ public class ExtendedKeyUsageExtension extends Extension {
|
|||
*
|
||||
* @param keyUsages the Vector of KeyUsages (ObjectIdentifiers)
|
||||
*/
|
||||
public ExtendedKeyUsageExtension(Vector<ObjectIdentifier> keyUsages)
|
||||
throws IOException {
|
||||
public ExtendedKeyUsageExtension(Vector<ObjectIdentifier> keyUsages) {
|
||||
this(Boolean.FALSE, keyUsages);
|
||||
}
|
||||
|
||||
|
@ -121,8 +120,7 @@ public class ExtendedKeyUsageExtension extends Extension {
|
|||
* @param keyUsages the Vector of KeyUsages (ObjectIdentifiers),
|
||||
* cannot be null or empty.
|
||||
*/
|
||||
public ExtendedKeyUsageExtension(Boolean critical, Vector<ObjectIdentifier> keyUsages)
|
||||
throws IOException {
|
||||
public ExtendedKeyUsageExtension(Boolean critical, Vector<ObjectIdentifier> keyUsages) {
|
||||
if (keyUsages == null || keyUsages.isEmpty()) {
|
||||
throw new IllegalArgumentException(
|
||||
"key usages cannot be null or empty");
|
||||
|
@ -188,10 +186,9 @@ public class ExtendedKeyUsageExtension extends Extension {
|
|||
* Write the extension to the DerOutputStream.
|
||||
*
|
||||
* @param out the DerOutputStream to write the extension to.
|
||||
* @exception IOException on encoding errors.
|
||||
*/
|
||||
@Override
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
public void encode(DerOutputStream out) {
|
||||
if (extensionValue == null) {
|
||||
extensionId = PKIXExtensions.ExtendedKeyUsage_Id;
|
||||
critical = false;
|
||||
|
|
|
@ -169,10 +169,9 @@ public class Extension implements java.security.cert.Extension, DerEncoder {
|
|||
* Write the extension to the DerOutputStream.
|
||||
*
|
||||
* @param out the DerOutputStream to write the extension to.
|
||||
* @exception IOException on encoding errors
|
||||
*/
|
||||
@Override
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
public void encode(DerOutputStream out) {
|
||||
|
||||
Objects.requireNonNull(extensionId,
|
||||
"No OID to encode for the extension");
|
||||
|
|
|
@ -65,8 +65,7 @@ public class FreshestCRLExtension extends CRLDistributionPointsExtension {
|
|||
*
|
||||
* @param distributionPoints the list of delta CRL distribution points.
|
||||
*/
|
||||
public FreshestCRLExtension(List<DistributionPoint> distributionPoints)
|
||||
throws IOException {
|
||||
public FreshestCRLExtension(List<DistributionPoint> distributionPoints) {
|
||||
|
||||
super(PKIXExtensions.FreshestCRL_Id, false, distributionPoints, NAME);
|
||||
}
|
||||
|
@ -88,10 +87,9 @@ public class FreshestCRLExtension extends CRLDistributionPointsExtension {
|
|||
* Writes the extension to the DerOutputStream.
|
||||
*
|
||||
* @param out the DerOutputStream to write the extension to.
|
||||
* @exception IOException on encoding errors.
|
||||
*/
|
||||
@Override
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
public void encode(DerOutputStream out) {
|
||||
super.encode(out, PKIXExtensions.FreshestCRL_Id, false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ import sun.security.util.*;
|
|||
* @author Amit Kapoor
|
||||
* @author Hemma Prafullchandra
|
||||
*/
|
||||
public class GeneralName {
|
||||
public class GeneralName implements DerEncoder {
|
||||
|
||||
// Private data members
|
||||
private final GeneralNameInterface name;
|
||||
|
@ -231,9 +231,9 @@ public class GeneralName {
|
|||
* Encode the name to the specified DerOutputStream.
|
||||
*
|
||||
* @param out the DerOutputStream to encode the GeneralName to.
|
||||
* @exception IOException on encoding errors.
|
||||
*/
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
@Override
|
||||
public void encode(DerOutputStream out) {
|
||||
DerOutputStream tmp = new DerOutputStream();
|
||||
name.encode(tmp);
|
||||
int nameType = name.getType();
|
||||
|
|
|
@ -25,8 +25,6 @@
|
|||
|
||||
package sun.security.x509;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import sun.security.util.*;
|
||||
|
||||
/**
|
||||
|
@ -36,7 +34,7 @@ import sun.security.util.*;
|
|||
* @author Amit Kapoor
|
||||
* @author Hemma Prafullchandra
|
||||
*/
|
||||
public interface GeneralNameInterface {
|
||||
public interface GeneralNameInterface extends DerEncoder {
|
||||
/**
|
||||
* The list of names supported.
|
||||
*/
|
||||
|
@ -65,15 +63,6 @@ public interface GeneralNameInterface {
|
|||
*/
|
||||
int getType();
|
||||
|
||||
/**
|
||||
* Encode the name to the specified DerOutputStream.
|
||||
*
|
||||
* @param out the DerOutputStream to encode the GeneralName to.
|
||||
* @exception IOException thrown if the GeneralName could not be
|
||||
* encoded.
|
||||
*/
|
||||
void encode(DerOutputStream out) throws IOException;
|
||||
|
||||
/**
|
||||
* Return type of constraint inputName places on this name:<ul>
|
||||
* <li>NAME_DIFF_TYPE = -1: input name is different type from name (i.e. does not constrain).
|
||||
|
|
|
@ -109,9 +109,8 @@ public class GeneralNames {
|
|||
* Write the extension to the DerOutputStream.
|
||||
*
|
||||
* @param out the DerOutputStream to write the extension to.
|
||||
* @exception IOException on error.
|
||||
*/
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
public void encode(DerOutputStream out) {
|
||||
if (isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ import sun.security.util.*;
|
|||
* @author Amit Kapoor
|
||||
* @author Hemma Prafullchandra
|
||||
*/
|
||||
public class GeneralSubtree {
|
||||
public class GeneralSubtree implements DerEncoder {
|
||||
private static final byte TAG_MIN = 0;
|
||||
private static final byte TAG_MAX = 1;
|
||||
private static final int MIN_DEFAULT = 0;
|
||||
|
@ -194,7 +194,8 @@ public class GeneralSubtree {
|
|||
*
|
||||
* @param out the DerOutputStream to encode this object to.
|
||||
*/
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
@Override
|
||||
public void encode(DerOutputStream out) {
|
||||
DerOutputStream seq = new DerOutputStream();
|
||||
|
||||
name.encode(seq);
|
||||
|
|
|
@ -43,7 +43,7 @@ import sun.security.util.*;
|
|||
* @author Hemma Prafullchandra
|
||||
* @author Andreas Sterbenz
|
||||
*/
|
||||
public class GeneralSubtrees implements Cloneable {
|
||||
public class GeneralSubtrees implements Cloneable, DerEncoder {
|
||||
|
||||
private final List<GeneralSubtree> trees;
|
||||
|
||||
|
@ -132,7 +132,8 @@ public class GeneralSubtrees implements Cloneable {
|
|||
*
|
||||
* @param out the DerOutputStream to encode this object to.
|
||||
*/
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
@Override
|
||||
public void encode(DerOutputStream out) {
|
||||
DerOutputStream seq = new DerOutputStream();
|
||||
|
||||
for (int i = 0, n = size(); i < n; i++) {
|
||||
|
|
|
@ -226,9 +226,9 @@ public class IPAddressName implements GeneralNameInterface {
|
|||
* Encode the IPAddress name into the DerOutputStream.
|
||||
*
|
||||
* @param out the DER stream to encode the IPAddressName to.
|
||||
* @exception IOException on encoding errors.
|
||||
*/
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
@Override
|
||||
public void encode(DerOutputStream out) {
|
||||
out.putOctetString(address);
|
||||
}
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ public class InhibitAnyPolicyExtension extends Extension {
|
|||
private int skipCerts = Integer.MAX_VALUE;
|
||||
|
||||
// Encode this extension value
|
||||
private void encodeThis() throws IOException {
|
||||
private void encodeThis() {
|
||||
DerOutputStream out = new DerOutputStream();
|
||||
out.putInteger(skipCerts);
|
||||
this.extensionValue = out.toByteArray();
|
||||
|
@ -81,7 +81,7 @@ public class InhibitAnyPolicyExtension extends Extension {
|
|||
* @param skipCerts specifies the depth of the certification path.
|
||||
* Use value of -1 to request unlimited depth.
|
||||
*/
|
||||
public InhibitAnyPolicyExtension(int skipCerts) throws IOException {
|
||||
public InhibitAnyPolicyExtension(int skipCerts) {
|
||||
if (skipCerts < -1)
|
||||
throw new IllegalArgumentException("Invalid value for skipCerts");
|
||||
if (skipCerts == -1)
|
||||
|
@ -144,7 +144,7 @@ public class InhibitAnyPolicyExtension extends Extension {
|
|||
* @param out the DerOutputStream to encode the extension to.
|
||||
*/
|
||||
@Override
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
public void encode(DerOutputStream out) {
|
||||
if (extensionValue == null) {
|
||||
this.extensionId = PKIXExtensions.InhibitAnyPolicy_Id;
|
||||
critical = true;
|
||||
|
|
|
@ -64,7 +64,7 @@ public class InvalidityDateExtension extends Extension {
|
|||
|
||||
private Date date;
|
||||
|
||||
private void encodeThis() throws IOException {
|
||||
private void encodeThis() {
|
||||
if (date == null) {
|
||||
this.extensionValue = null;
|
||||
return;
|
||||
|
@ -80,7 +80,7 @@ public class InvalidityDateExtension extends Extension {
|
|||
*
|
||||
* @param date the invalidity date
|
||||
*/
|
||||
public InvalidityDateExtension(Date date) throws IOException {
|
||||
public InvalidityDateExtension(Date date) {
|
||||
this(false, date);
|
||||
}
|
||||
|
||||
|
@ -90,8 +90,7 @@ public class InvalidityDateExtension extends Extension {
|
|||
* @param critical true if the extension is to be treated as critical.
|
||||
* @param date the invalidity date, cannot be null.
|
||||
*/
|
||||
public InvalidityDateExtension(boolean critical, Date date)
|
||||
throws IOException {
|
||||
public InvalidityDateExtension(boolean critical, Date date) {
|
||||
if (date == null) {
|
||||
throw new IllegalArgumentException("date cannot be null");
|
||||
}
|
||||
|
@ -141,10 +140,9 @@ public class InvalidityDateExtension extends Extension {
|
|||
* Write the extension to the DerOutputStream.
|
||||
*
|
||||
* @param out the DerOutputStream to write the extension to
|
||||
* @exception IOException on encoding errors
|
||||
*/
|
||||
@Override
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
public void encode(DerOutputStream out) {
|
||||
if (this.extensionValue == null) {
|
||||
this.extensionId = PKIXExtensions.InvalidityDate_Id;
|
||||
this.critical = false;
|
||||
|
|
|
@ -52,7 +52,7 @@ public class IssuerAlternativeNameExtension extends Extension {
|
|||
GeneralNames names;
|
||||
|
||||
// Encode this extension
|
||||
private void encodeThis() throws IOException {
|
||||
private void encodeThis() {
|
||||
if (names == null || names.isEmpty()) {
|
||||
this.extensionValue = null;
|
||||
return;
|
||||
|
@ -66,10 +66,8 @@ public class IssuerAlternativeNameExtension extends Extension {
|
|||
* Create a IssuerAlternativeNameExtension with the passed GeneralNames.
|
||||
*
|
||||
* @param names the GeneralNames for the issuer.
|
||||
* @exception IOException on error.
|
||||
*/
|
||||
public IssuerAlternativeNameExtension(GeneralNames names)
|
||||
throws IOException {
|
||||
public IssuerAlternativeNameExtension(GeneralNames names) {
|
||||
this(false, names);
|
||||
}
|
||||
|
||||
|
@ -79,10 +77,8 @@ public class IssuerAlternativeNameExtension extends Extension {
|
|||
*
|
||||
* @param critical true if the extension is to be treated as critical.
|
||||
* @param names the GeneralNames for the issuer, cannot be null or empty.
|
||||
* @exception IOException on error.
|
||||
*/
|
||||
public IssuerAlternativeNameExtension(Boolean critical, GeneralNames names)
|
||||
throws IOException {
|
||||
public IssuerAlternativeNameExtension(Boolean critical, GeneralNames names) {
|
||||
if (names == null || names.isEmpty()) {
|
||||
throw new IllegalArgumentException("names cannot be null or empty");
|
||||
}
|
||||
|
@ -138,10 +134,9 @@ public class IssuerAlternativeNameExtension extends Extension {
|
|||
* Write the extension to the OutputStream.
|
||||
*
|
||||
* @param out the DerOutputStream to write the extension to.
|
||||
* @exception IOException on encoding error.
|
||||
*/
|
||||
@Override
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
public void encode(DerOutputStream out) {
|
||||
if (extensionValue == null) {
|
||||
extensionId = PKIXExtensions.IssuerAlternativeName_Id;
|
||||
critical = false;
|
||||
|
|
|
@ -112,13 +112,11 @@ public class IssuingDistributionPointExtension extends Extension {
|
|||
* <code>hasOnlyUserCerts</code>, <code>hasOnlyCACerts</code>,
|
||||
* <code>hasOnlyAttributeCerts</code> is set to <code>true</code>,
|
||||
* or all arguments are either <code>null</code> or <code>false</code>.
|
||||
* @throws IOException on encoding error.
|
||||
*/
|
||||
public IssuingDistributionPointExtension(
|
||||
DistributionPointName distributionPoint, ReasonFlags revocationReasons,
|
||||
boolean hasOnlyUserCerts, boolean hasOnlyCACerts,
|
||||
boolean hasOnlyAttributeCerts, boolean isIndirectCRL)
|
||||
throws IOException {
|
||||
boolean hasOnlyAttributeCerts, boolean isIndirectCRL) {
|
||||
|
||||
if (distributionPoint == null &&
|
||||
revocationReasons == null &&
|
||||
|
@ -222,10 +220,9 @@ public class IssuingDistributionPointExtension extends Extension {
|
|||
* DerOutputStream.
|
||||
*
|
||||
* @param out the output stream.
|
||||
* @exception IOException on encoding error.
|
||||
*/
|
||||
@Override
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
public void encode(DerOutputStream out) {
|
||||
if (this.extensionValue == null) {
|
||||
this.extensionId = PKIXExtensions.IssuingDistributionPoint_Id;
|
||||
this.critical = false;
|
||||
|
@ -264,7 +261,7 @@ public class IssuingDistributionPointExtension extends Extension {
|
|||
}
|
||||
|
||||
// Encodes this extension value
|
||||
private void encodeThis() throws IOException {
|
||||
private void encodeThis() {
|
||||
|
||||
if (distributionPoint == null &&
|
||||
revocationReasons == null &&
|
||||
|
|
|
@ -125,7 +125,7 @@ public class KeyIdentifier {
|
|||
* @param out the DerOutputStream to write the object to.
|
||||
* @exception IOException
|
||||
*/
|
||||
void encode(DerOutputStream out) throws IOException {
|
||||
void encode(DerOutputStream out) {
|
||||
out.putOctetString(octetString);
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ public class KeyUsageExtension extends Extension {
|
|||
private boolean[] bitString;
|
||||
|
||||
// Encode this extension value
|
||||
private void encodeThis() throws IOException {
|
||||
private void encodeThis() {
|
||||
DerOutputStream os = new DerOutputStream();
|
||||
os.putTruncatedUnalignedBitString(new BitArray(this.bitString));
|
||||
this.extensionValue = os.toByteArray();
|
||||
|
@ -94,7 +94,7 @@ public class KeyUsageExtension extends Extension {
|
|||
*
|
||||
* @param bitString the bits to be set for the extension.
|
||||
*/
|
||||
public KeyUsageExtension(byte[] bitString) throws IOException {
|
||||
public KeyUsageExtension(byte[] bitString) {
|
||||
this.bitString =
|
||||
new BitArray(bitString.length*8,bitString).toBooleanArray();
|
||||
this.extensionId = PKIXExtensions.KeyUsage_Id;
|
||||
|
@ -108,7 +108,7 @@ public class KeyUsageExtension extends Extension {
|
|||
*
|
||||
* @param bitString the bits to be set for the extension.
|
||||
*/
|
||||
public KeyUsageExtension(boolean[] bitString) throws IOException {
|
||||
public KeyUsageExtension(boolean[] bitString) {
|
||||
this.bitString = bitString;
|
||||
this.extensionId = PKIXExtensions.KeyUsage_Id;
|
||||
this.critical = true;
|
||||
|
@ -121,7 +121,7 @@ public class KeyUsageExtension extends Extension {
|
|||
*
|
||||
* @param bitString the bits to be set for the extension.
|
||||
*/
|
||||
public KeyUsageExtension(BitArray bitString) throws IOException {
|
||||
public KeyUsageExtension(BitArray bitString) {
|
||||
this.bitString = bitString.toBooleanArray();
|
||||
this.extensionId = PKIXExtensions.KeyUsage_Id;
|
||||
this.critical = true;
|
||||
|
@ -272,10 +272,9 @@ public class KeyUsageExtension extends Extension {
|
|||
* Write the extension to the DerOutputStream.
|
||||
*
|
||||
* @param out the DerOutputStream to write the extension to.
|
||||
* @exception IOException on encoding errors.
|
||||
*/
|
||||
@Override
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
public void encode(DerOutputStream out) {
|
||||
if (this.extensionValue == null) {
|
||||
this.extensionId = PKIXExtensions.KeyUsage_Id;
|
||||
this.critical = true;
|
||||
|
|
|
@ -101,7 +101,7 @@ public class NameConstraintsExtension extends Extension
|
|||
}
|
||||
|
||||
// Encode this extension value.
|
||||
private void encodeThis() throws IOException {
|
||||
private void encodeThis() {
|
||||
minMaxValid = false;
|
||||
if (permitted == null && excluded == null) {
|
||||
this.extensionValue = null;
|
||||
|
@ -135,8 +135,7 @@ public class NameConstraintsExtension extends Extension
|
|||
* @param excluded the excluded GeneralSubtrees (null for optional).
|
||||
*/
|
||||
public NameConstraintsExtension(GeneralSubtrees permitted,
|
||||
GeneralSubtrees excluded)
|
||||
throws IOException {
|
||||
GeneralSubtrees excluded) {
|
||||
if (permitted == null && excluded == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"permitted and excluded cannot both be null");
|
||||
|
@ -226,10 +225,9 @@ public class NameConstraintsExtension extends Extension
|
|||
* Write the extension to the OutputStream.
|
||||
*
|
||||
* @param out the DerOutputStream to write the extension to.
|
||||
* @exception IOException on encoding errors.
|
||||
*/
|
||||
@Override
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
public void encode(DerOutputStream out) {
|
||||
if (this.extensionValue == null) {
|
||||
this.extensionId = PKIXExtensions.NameConstraints_Id;
|
||||
this.critical = true;
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
package sun.security.x509;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
import sun.security.util.*;
|
||||
|
||||
|
@ -86,13 +85,6 @@ public class NetscapeCertTypeExtension extends Extension {
|
|||
new MapEntry(OBJECT_SIGNING_CA, 7),
|
||||
};
|
||||
|
||||
private static final Vector<String> mAttributeNames = new Vector<>();
|
||||
static {
|
||||
for (MapEntry entry : mMapData) {
|
||||
mAttributeNames.add(entry.mName);
|
||||
}
|
||||
}
|
||||
|
||||
private static int getPosition(String name) throws IOException {
|
||||
for (int i = 0; i < mMapData.length; i++) {
|
||||
if (name.equalsIgnoreCase(mMapData[i].mName))
|
||||
|
@ -103,7 +95,7 @@ public class NetscapeCertTypeExtension extends Extension {
|
|||
}
|
||||
|
||||
// Encode this extension value
|
||||
private void encodeThis() throws IOException {
|
||||
private void encodeThis() {
|
||||
DerOutputStream os = new DerOutputStream();
|
||||
os.putTruncatedUnalignedBitString(new BitArray(this.bitString));
|
||||
this.extensionValue = os.toByteArray();
|
||||
|
@ -138,7 +130,7 @@ public class NetscapeCertTypeExtension extends Extension {
|
|||
*
|
||||
* @param bitString the bits to be set for the extension.
|
||||
*/
|
||||
public NetscapeCertTypeExtension(byte[] bitString) throws IOException {
|
||||
public NetscapeCertTypeExtension(byte[] bitString) {
|
||||
this.bitString =
|
||||
new BitArray(bitString.length*8, bitString).toBooleanArray();
|
||||
this.extensionId = NetscapeCertType_Id;
|
||||
|
@ -152,7 +144,7 @@ public class NetscapeCertTypeExtension extends Extension {
|
|||
*
|
||||
* @param bitString the bits to be set for the extension.
|
||||
*/
|
||||
public NetscapeCertTypeExtension(boolean[] bitString) throws IOException {
|
||||
public NetscapeCertTypeExtension(boolean[] bitString) {
|
||||
this.bitString = bitString;
|
||||
this.extensionId = NetscapeCertType_Id;
|
||||
this.critical = true;
|
||||
|
@ -238,10 +230,9 @@ public class NetscapeCertTypeExtension extends Extension {
|
|||
* Write the extension to the DerOutputStream.
|
||||
*
|
||||
* @param out the DerOutputStream to write the extension to.
|
||||
* @exception IOException on encoding errors.
|
||||
*/
|
||||
@Override
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
public void encode(DerOutputStream out) {
|
||||
if (this.extensionValue == null) {
|
||||
this.extensionId = NetscapeCertType_Id;
|
||||
this.critical = true;
|
||||
|
|
|
@ -86,9 +86,9 @@ public class OIDName implements GeneralNameInterface {
|
|||
* Encode the OID name into the DerOutputStream.
|
||||
*
|
||||
* @param out the DER stream to encode the OIDName to.
|
||||
* @exception IOException on encoding errors.
|
||||
*/
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
@Override
|
||||
public void encode(DerOutputStream out) {
|
||||
out.putOID(oid);
|
||||
}
|
||||
|
||||
|
|
|
@ -151,9 +151,9 @@ public class OtherName implements GeneralNameInterface {
|
|||
* Encode the Other name into the DerOutputStream.
|
||||
*
|
||||
* @param out the DER stream to encode the Other-Name to.
|
||||
* @exception IOException on encoding errors.
|
||||
*/
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
@Override
|
||||
public void encode(DerOutputStream out) {
|
||||
if (gni != null) {
|
||||
// This OtherName has a supported class
|
||||
gni.encode(out);
|
||||
|
|
|
@ -62,7 +62,7 @@ public class PolicyConstraintsExtension extends Extension {
|
|||
private int inhibit = -1;
|
||||
|
||||
// Encode this extension value.
|
||||
private void encodeThis() throws IOException {
|
||||
private void encodeThis() {
|
||||
if (require == -1 && inhibit == -1) {
|
||||
this.extensionValue = null;
|
||||
return;
|
||||
|
@ -94,8 +94,7 @@ public class PolicyConstraintsExtension extends Extension {
|
|||
* @param require require explicit policy (-1 for optional).
|
||||
* @param inhibit inhibit policy mapping (-1 for optional).
|
||||
*/
|
||||
public PolicyConstraintsExtension(int require, int inhibit)
|
||||
throws IOException {
|
||||
public PolicyConstraintsExtension(int require, int inhibit) {
|
||||
this(Boolean.TRUE, require, inhibit);
|
||||
}
|
||||
|
||||
|
@ -108,8 +107,7 @@ public class PolicyConstraintsExtension extends Extension {
|
|||
* @param require require explicit policy (-1 for optional).
|
||||
* @param inhibit inhibit policy mapping (-1 for optional).
|
||||
*/
|
||||
public PolicyConstraintsExtension(Boolean critical, int require, int inhibit)
|
||||
throws IOException {
|
||||
public PolicyConstraintsExtension(Boolean critical, int require, int inhibit) {
|
||||
if (require == -1 && inhibit == -1) {
|
||||
throw new IllegalArgumentException(
|
||||
"require and inhibit cannot both be -1");
|
||||
|
@ -190,10 +188,9 @@ public class PolicyConstraintsExtension extends Extension {
|
|||
* Write the extension to the DerOutputStream.
|
||||
*
|
||||
* @param out the DerOutputStream to write the extension to.
|
||||
* @exception IOException on encoding errors.
|
||||
*/
|
||||
@Override
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
public void encode(DerOutputStream out) {
|
||||
if (extensionValue == null) {
|
||||
extensionId = PKIXExtensions.PolicyConstraints_Id;
|
||||
critical = true;
|
||||
|
|
|
@ -32,6 +32,7 @@ import java.util.LinkedHashSet;
|
|||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import sun.security.util.DerEncoder;
|
||||
import sun.security.util.DerValue;
|
||||
import sun.security.util.DerOutputStream;
|
||||
/**
|
||||
|
@ -59,7 +60,7 @@ import sun.security.util.DerOutputStream;
|
|||
* @author Anne Anderson
|
||||
* @since 1.4
|
||||
*/
|
||||
public class PolicyInformation {
|
||||
public class PolicyInformation implements DerEncoder {
|
||||
|
||||
// Attribute names
|
||||
public static final String NAME = "PolicyInformation";
|
||||
|
@ -178,15 +179,15 @@ public class PolicyInformation {
|
|||
* Write the PolicyInformation to the DerOutputStream.
|
||||
*
|
||||
* @param out the DerOutputStream to write the extension to.
|
||||
* @exception IOException on encoding errors.
|
||||
*/
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
@Override
|
||||
public void encode(DerOutputStream out) {
|
||||
DerOutputStream tmp = new DerOutputStream();
|
||||
policyIdentifier.encode(tmp);
|
||||
if (!policyQualifiers.isEmpty()) {
|
||||
DerOutputStream tmp2 = new DerOutputStream();
|
||||
for (PolicyQualifierInfo pq : policyQualifiers) {
|
||||
tmp2.write(pq.getEncoded());
|
||||
tmp2.writeBytes(pq.getEncoded());
|
||||
}
|
||||
tmp.write(DerValue.tag_Sequence, tmp2);
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ public class PolicyMappingsExtension extends Extension {
|
|||
private List<CertificatePolicyMap> maps;
|
||||
|
||||
// Encode this extension value
|
||||
private void encodeThis() throws IOException {
|
||||
private void encodeThis() {
|
||||
if (maps == null || maps.isEmpty()) {
|
||||
this.extensionValue = null;
|
||||
return;
|
||||
|
@ -77,8 +77,7 @@ public class PolicyMappingsExtension extends Extension {
|
|||
*
|
||||
* @param maps the List of CertificatePolicyMap, cannot be null or empty.
|
||||
*/
|
||||
public PolicyMappingsExtension(List<CertificatePolicyMap> maps)
|
||||
throws IOException {
|
||||
public PolicyMappingsExtension(List<CertificatePolicyMap> maps) {
|
||||
if (maps == null || maps.isEmpty()) {
|
||||
throw new IllegalArgumentException("maps cannot be null or empty");
|
||||
}
|
||||
|
@ -129,10 +128,9 @@ public class PolicyMappingsExtension extends Extension {
|
|||
* Write the extension to the OutputStream.
|
||||
*
|
||||
* @param out the DerOutputStream to write the extension to.
|
||||
* @exception IOException on encoding errors.
|
||||
*/
|
||||
@Override
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
public void encode(DerOutputStream out) {
|
||||
if (extensionValue == null) {
|
||||
extensionId = PKIXExtensions.PolicyMappings_Id;
|
||||
critical = true;
|
||||
|
|
|
@ -68,7 +68,7 @@ public class PrivateKeyUsageExtension extends Extension {
|
|||
private Date notAfter = null;
|
||||
|
||||
// Encode this extension value.
|
||||
private void encodeThis() throws IOException {
|
||||
private void encodeThis() {
|
||||
if (notBefore == null && notAfter == null) {
|
||||
this.extensionValue = null;
|
||||
return;
|
||||
|
@ -101,8 +101,7 @@ public class PrivateKeyUsageExtension extends Extension {
|
|||
* @param notAfter the date/time after which the private key
|
||||
* should not be used.
|
||||
*/
|
||||
public PrivateKeyUsageExtension(Date notBefore, Date notAfter)
|
||||
throws IOException {
|
||||
public PrivateKeyUsageExtension(Date notBefore, Date notAfter) {
|
||||
if (notBefore == null && notAfter == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"notBefore and notAfter cannot both be null");
|
||||
|
@ -230,10 +229,9 @@ public class PrivateKeyUsageExtension extends Extension {
|
|||
* Write the extension to the OutputStream.
|
||||
*
|
||||
* @param out the DerOutputStream to write the extension to.
|
||||
* @exception IOException on encoding errors.
|
||||
*/
|
||||
@Override
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
public void encode(DerOutputStream out) {
|
||||
if (extensionValue == null) {
|
||||
extensionId = PKIXExtensions.PrivateKeyUsage_Id;
|
||||
critical = false;
|
||||
|
|
|
@ -333,9 +333,8 @@ public class RDN {
|
|||
* Encode the RDN in DER-encoded form.
|
||||
*
|
||||
* @param out DerOutputStream to which RDN is to be written
|
||||
* @throws IOException on error
|
||||
*/
|
||||
void encode(DerOutputStream out) throws IOException {
|
||||
void encode(DerOutputStream out) {
|
||||
out.putOrderedSetOf(DerValue.tag_Set, assertion);
|
||||
}
|
||||
|
||||
|
|
|
@ -114,9 +114,9 @@ public class RFC822Name implements GeneralNameInterface
|
|||
* Encode the RFC822 name into the DerOutputStream.
|
||||
*
|
||||
* @param out the DER stream to encode the RFC822Name to.
|
||||
* @exception IOException on encoding errors.
|
||||
*/
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
@Override
|
||||
public void encode(DerOutputStream out) {
|
||||
out.putIA5String(name);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,10 +27,7 @@ package sun.security.x509;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import sun.security.util.BitArray;
|
||||
import sun.security.util.DerInputStream;
|
||||
import sun.security.util.DerOutputStream;
|
||||
import sun.security.util.DerValue;
|
||||
import sun.security.util.*;
|
||||
|
||||
/**
|
||||
* Represent the CRL Reason Flags.
|
||||
|
@ -53,7 +50,7 @@ import sun.security.util.DerValue;
|
|||
*
|
||||
* @author Hemma Prafullchandra
|
||||
*/
|
||||
public class ReasonFlags {
|
||||
public class ReasonFlags implements DerEncoder {
|
||||
|
||||
/**
|
||||
* Reasons
|
||||
|
@ -231,9 +228,9 @@ public class ReasonFlags {
|
|||
* Write the extension to the DerOutputStream.
|
||||
*
|
||||
* @param out the DerOutputStream to write the extension to.
|
||||
* @exception IOException on encoding errors.
|
||||
*/
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
@Override
|
||||
public void encode(DerOutputStream out) {
|
||||
out.putTruncatedUnalignedBitString(new BitArray(this.bitString));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2002, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
|
@ -108,9 +108,8 @@ public class SerialNumber {
|
|||
* Encode the SerialNumber in DER form to the stream.
|
||||
*
|
||||
* @param out the DerOutputStream to marshal the contents to.
|
||||
* @exception IOException on errors.
|
||||
*/
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
public void encode(DerOutputStream out) {
|
||||
out.putInteger(serialNum);
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ public class SubjectAlternativeNameExtension extends Extension {
|
|||
GeneralNames names;
|
||||
|
||||
// Encode this extension
|
||||
private void encodeThis() throws IOException {
|
||||
private void encodeThis() {
|
||||
if (names == null || names.isEmpty()) {
|
||||
this.extensionValue = null;
|
||||
return;
|
||||
|
@ -72,10 +72,8 @@ public class SubjectAlternativeNameExtension extends Extension {
|
|||
* The extension is marked non-critical.
|
||||
*
|
||||
* @param names the GeneralNames for the subject.
|
||||
* @exception IOException on error.
|
||||
*/
|
||||
public SubjectAlternativeNameExtension(GeneralNames names)
|
||||
throws IOException {
|
||||
public SubjectAlternativeNameExtension(GeneralNames names) {
|
||||
this(Boolean.FALSE, names);
|
||||
}
|
||||
|
||||
|
@ -85,10 +83,8 @@ public class SubjectAlternativeNameExtension extends Extension {
|
|||
*
|
||||
* @param critical true if the extension is to be treated as critical.
|
||||
* @param names the GeneralNames for the subject, cannot be null or empty.
|
||||
* @exception IOException on error.
|
||||
*/
|
||||
public SubjectAlternativeNameExtension(Boolean critical, GeneralNames names)
|
||||
throws IOException {
|
||||
public SubjectAlternativeNameExtension(Boolean critical, GeneralNames names) {
|
||||
if (names == null || names.isEmpty()) {
|
||||
throw new IllegalArgumentException("names cannot be null or empty");
|
||||
}
|
||||
|
@ -142,10 +138,9 @@ public class SubjectAlternativeNameExtension extends Extension {
|
|||
* Write the extension to the OutputStream.
|
||||
*
|
||||
* @param out the DerOutputStream to write the extension to.
|
||||
* @exception IOException on encoding errors.
|
||||
*/
|
||||
@Override
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
public void encode(DerOutputStream out) {
|
||||
if (extensionValue == null) {
|
||||
extensionId = PKIXExtensions.SubjectAlternativeName_Id;
|
||||
critical = false;
|
||||
|
|
|
@ -80,10 +80,9 @@ public class SubjectInfoAccessExtension extends Extension {
|
|||
*
|
||||
* @param accessDescriptions the List of AccessDescription,
|
||||
* cannot be null or empty.
|
||||
* @throws IOException on error
|
||||
*/
|
||||
public SubjectInfoAccessExtension(
|
||||
List<AccessDescription> accessDescriptions) throws IOException {
|
||||
List<AccessDescription> accessDescriptions) {
|
||||
if (accessDescriptions == null || accessDescriptions.isEmpty()) {
|
||||
throw new IllegalArgumentException(
|
||||
"accessDescriptions cannot be null or empty");
|
||||
|
@ -143,10 +142,9 @@ public class SubjectInfoAccessExtension extends Extension {
|
|||
* Write the extension to the DerOutputStream.
|
||||
*
|
||||
* @param out the DerOutputStream to write the extension to.
|
||||
* @exception IOException on encoding errors.
|
||||
*/
|
||||
@Override
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
public void encode(DerOutputStream out) {
|
||||
if (this.extensionValue == null) {
|
||||
this.extensionId = PKIXExtensions.SubjectInfoAccess_Id;
|
||||
this.critical = false;
|
||||
|
@ -156,7 +154,7 @@ public class SubjectInfoAccessExtension extends Extension {
|
|||
}
|
||||
|
||||
// Encode this extension value
|
||||
private void encodeThis() throws IOException {
|
||||
private void encodeThis() {
|
||||
if (accessDescriptions.isEmpty()) {
|
||||
this.extensionValue = null;
|
||||
} else {
|
||||
|
|
|
@ -57,7 +57,7 @@ public class SubjectKeyIdentifierExtension extends Extension {
|
|||
private KeyIdentifier id;
|
||||
|
||||
// Encode this extension value
|
||||
private void encodeThis() throws IOException {
|
||||
private void encodeThis() {
|
||||
if (id == null) {
|
||||
this.extensionValue = null;
|
||||
return;
|
||||
|
@ -72,8 +72,7 @@ public class SubjectKeyIdentifierExtension extends Extension {
|
|||
* The criticality is set to False.
|
||||
* @param octetString the octet string identifying the key identifier.
|
||||
*/
|
||||
public SubjectKeyIdentifierExtension(byte[] octetString)
|
||||
throws IOException {
|
||||
public SubjectKeyIdentifierExtension(byte[] octetString) {
|
||||
id = new KeyIdentifier(octetString);
|
||||
|
||||
this.extensionId = PKIXExtensions.SubjectKey_Id;
|
||||
|
@ -110,10 +109,9 @@ public class SubjectKeyIdentifierExtension extends Extension {
|
|||
* Write the extension to the OutputStream.
|
||||
*
|
||||
* @param out the DerOutputStream to write the extension to.
|
||||
* @exception IOException on encoding errors.
|
||||
*/
|
||||
@Override
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
public void encode(DerOutputStream out) {
|
||||
if (extensionValue == null) {
|
||||
extensionId = PKIXExtensions.SubjectKey_Id;
|
||||
critical = false;
|
||||
|
|
|
@ -197,9 +197,9 @@ public class URIName implements GeneralNameInterface {
|
|||
* Encode the URI name into the DerOutputStream.
|
||||
*
|
||||
* @param out the DER stream to encode the URIName to.
|
||||
* @exception IOException on encoding errors.
|
||||
*/
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
@Override
|
||||
public void encode(DerOutputStream out) {
|
||||
out.putIA5String(uri.toASCIIString());
|
||||
}
|
||||
|
||||
|
|
|
@ -92,9 +92,8 @@ public class UniqueIdentity {
|
|||
*
|
||||
* @param out the DerOutputStream to marshal the contents to.
|
||||
* @param tag encode it under the following tag.
|
||||
* @exception IOException on errors.
|
||||
*/
|
||||
public void encode(DerOutputStream out, byte tag) throws IOException {
|
||||
public void encode(DerOutputStream out, byte tag) {
|
||||
byte[] bytes = id.toByteArray();
|
||||
int excessBits = bytes.length*8 - id.length();
|
||||
|
||||
|
@ -102,7 +101,7 @@ public class UniqueIdentity {
|
|||
out.putLength(bytes.length + 1);
|
||||
|
||||
out.write(excessBits);
|
||||
out.write(bytes);
|
||||
out.writeBytes(bytes);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -364,10 +364,9 @@ public class X400Address implements GeneralNameInterface {
|
|||
* Encode the X400 name into the DerOutputStream.
|
||||
*
|
||||
* @param out the DER stream to encode the X400Address to.
|
||||
* @exception IOException on encoding errors.
|
||||
*/
|
||||
@Override
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
public void encode(DerOutputStream out) {
|
||||
out.putDerValue(derValue);
|
||||
}
|
||||
|
||||
|
|
|
@ -826,7 +826,8 @@ public class X500Name implements GeneralNameInterface, Principal {
|
|||
*
|
||||
* @param out where to put the DER-encoded X.500 name
|
||||
*/
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
@Override
|
||||
public void encode(DerOutputStream out) {
|
||||
DerOutputStream tmp = new DerOutputStream();
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
names[i].encode(tmp);
|
||||
|
|
|
@ -152,47 +152,40 @@ public class X509CRLEntryImpl extends X509CRLEntry
|
|||
*
|
||||
* @param outStrm an output stream to which the encoded revoked
|
||||
* certificate is written.
|
||||
* @exception CRLException on encoding errors.
|
||||
*/
|
||||
public void encode(DerOutputStream outStrm) throws CRLException {
|
||||
try {
|
||||
if (revokedCert == null) {
|
||||
DerOutputStream tmp = new DerOutputStream();
|
||||
// sequence { serialNumber, revocationDate, extensions }
|
||||
serialNumber.encode(tmp);
|
||||
public void encode(DerOutputStream outStrm) {
|
||||
if (revokedCert == null) {
|
||||
DerOutputStream tmp = new DerOutputStream();
|
||||
// sequence { serialNumber, revocationDate, extensions }
|
||||
serialNumber.encode(tmp);
|
||||
|
||||
if (revocationDate.getTime() < CertificateValidity.YR_2050) {
|
||||
tmp.putUTCTime(revocationDate);
|
||||
} else {
|
||||
tmp.putGeneralizedTime(revocationDate);
|
||||
}
|
||||
|
||||
if (extensions != null)
|
||||
extensions.encode(tmp, isExplicit);
|
||||
|
||||
DerOutputStream seq = new DerOutputStream();
|
||||
seq.write(DerValue.tag_Sequence, tmp);
|
||||
|
||||
revokedCert = seq.toByteArray();
|
||||
if (revocationDate.getTime() < CertificateValidity.YR_2050) {
|
||||
tmp.putUTCTime(revocationDate);
|
||||
} else {
|
||||
tmp.putGeneralizedTime(revocationDate);
|
||||
}
|
||||
outStrm.write(revokedCert);
|
||||
} catch (IOException e) {
|
||||
throw new CRLException("Encoding error: " + e.toString());
|
||||
|
||||
if (extensions != null)
|
||||
extensions.encode(tmp, isExplicit);
|
||||
|
||||
DerOutputStream seq = new DerOutputStream();
|
||||
seq.write(DerValue.tag_Sequence, tmp);
|
||||
|
||||
revokedCert = seq.toByteArray();
|
||||
}
|
||||
outStrm.writeBytes(revokedCert);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ASN.1 DER-encoded form of this CRL Entry,
|
||||
* which corresponds to the inner SEQUENCE.
|
||||
*
|
||||
* @exception CRLException if an encoding error occurs.
|
||||
*/
|
||||
public byte[] getEncoded() throws CRLException {
|
||||
public byte[] getEncoded() {
|
||||
return getEncoded0().clone();
|
||||
}
|
||||
|
||||
// Called internally to avoid clone
|
||||
private byte[] getEncoded0() throws CRLException {
|
||||
private byte[] getEncoded0() {
|
||||
if (revokedCert == null)
|
||||
this.encode(new DerOutputStream());
|
||||
return revokedCert;
|
||||
|
@ -523,17 +516,13 @@ public class X509CRLEntryImpl extends X509CRLEntry
|
|||
if (compSerial != 0) {
|
||||
return compSerial;
|
||||
}
|
||||
try {
|
||||
byte[] thisEncoded = this.getEncoded0();
|
||||
byte[] thatEncoded = that.getEncoded0();
|
||||
for (int i=0; i<thisEncoded.length && i<thatEncoded.length; i++) {
|
||||
int a = thisEncoded[i] & 0xff;
|
||||
int b = thatEncoded[i] & 0xff;
|
||||
if (a != b) return a-b;
|
||||
}
|
||||
return thisEncoded.length -thatEncoded.length;
|
||||
} catch (CRLException ce) {
|
||||
return -1;
|
||||
byte[] thisEncoded = this.getEncoded0();
|
||||
byte[] thatEncoded = that.getEncoded0();
|
||||
for (int i=0; i<thisEncoded.length && i<thatEncoded.length; i++) {
|
||||
int a = thisEncoded[i] & 0xff;
|
||||
int b = thatEncoded[i] & 0xff;
|
||||
if (a != b) return a-b;
|
||||
}
|
||||
return thisEncoded.length -thatEncoded.length;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -298,48 +298,43 @@ public class X509CRLImpl extends X509CRL implements DerEncoder {
|
|||
* @exception CRLException on encoding errors.
|
||||
*/
|
||||
public byte[] encodeInfo() throws CRLException {
|
||||
try {
|
||||
DerOutputStream tmp = new DerOutputStream();
|
||||
DerOutputStream rCerts = new DerOutputStream();
|
||||
DerOutputStream seq = new DerOutputStream();
|
||||
DerOutputStream tmp = new DerOutputStream();
|
||||
DerOutputStream rCerts = new DerOutputStream();
|
||||
DerOutputStream seq = new DerOutputStream();
|
||||
|
||||
if (version != 0) // v2 crl encode version
|
||||
tmp.putInteger(version);
|
||||
infoSigAlgId.encode(tmp);
|
||||
if ((version == 0) && (issuer.toString() == null))
|
||||
throw new CRLException("Null Issuer DN not allowed in v1 CRL");
|
||||
issuer.encode(tmp);
|
||||
if (version != 0) // v2 crl encode version
|
||||
tmp.putInteger(version);
|
||||
infoSigAlgId.encode(tmp);
|
||||
if ((version == 0) && (issuer.toString() == null))
|
||||
throw new CRLException("Null Issuer DN not allowed in v1 CRL");
|
||||
issuer.encode(tmp);
|
||||
|
||||
if (thisUpdate.getTime() < CertificateValidity.YR_2050)
|
||||
tmp.putUTCTime(thisUpdate);
|
||||
if (thisUpdate.getTime() < CertificateValidity.YR_2050)
|
||||
tmp.putUTCTime(thisUpdate);
|
||||
else
|
||||
tmp.putGeneralizedTime(thisUpdate);
|
||||
|
||||
if (nextUpdate != null) {
|
||||
if (nextUpdate.getTime() < CertificateValidity.YR_2050)
|
||||
tmp.putUTCTime(nextUpdate);
|
||||
else
|
||||
tmp.putGeneralizedTime(thisUpdate);
|
||||
|
||||
if (nextUpdate != null) {
|
||||
if (nextUpdate.getTime() < CertificateValidity.YR_2050)
|
||||
tmp.putUTCTime(nextUpdate);
|
||||
else
|
||||
tmp.putGeneralizedTime(nextUpdate);
|
||||
}
|
||||
|
||||
if (!revokedList.isEmpty()) {
|
||||
for (X509CRLEntry entry : revokedList) {
|
||||
((X509CRLEntryImpl)entry).encode(rCerts);
|
||||
}
|
||||
tmp.write(DerValue.tag_Sequence, rCerts);
|
||||
}
|
||||
|
||||
if (extensions != null)
|
||||
extensions.encode(tmp, isExplicit);
|
||||
|
||||
seq.write(DerValue.tag_Sequence, tmp);
|
||||
|
||||
return seq.toByteArray();
|
||||
} catch (IOException e) {
|
||||
throw new CRLException("Encoding error: " + e.getMessage());
|
||||
tmp.putGeneralizedTime(nextUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
if (!revokedList.isEmpty()) {
|
||||
for (X509CRLEntry entry : revokedList) {
|
||||
((X509CRLEntryImpl) entry).encode(rCerts);
|
||||
}
|
||||
tmp.write(DerValue.tag_Sequence, rCerts);
|
||||
}
|
||||
|
||||
if (extensions != null)
|
||||
extensions.encode(tmp, isExplicit);
|
||||
|
||||
seq.write(DerValue.tag_Sequence, tmp);
|
||||
|
||||
return seq.toByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
private static final boolean isExplicit = true;
|
||||
|
@ -605,36 +600,31 @@ public class X509CRLImpl extends X509CRL implements DerEncoder {
|
|||
public static X509CRLImpl newSigned(TBSCertList info, PrivateKey key, String algorithm, String provider)
|
||||
throws CRLException, NoSuchAlgorithmException, InvalidKeyException,
|
||||
NoSuchProviderException, SignatureException {
|
||||
try {
|
||||
Signature sigEngine = SignatureUtil.fromKey(algorithm, key, provider);
|
||||
AlgorithmId sigAlgId = SignatureUtil.fromSignature(sigEngine, key);
|
||||
info.infoSigAlgId = sigAlgId;
|
||||
Signature sigEngine = SignatureUtil.fromKey(algorithm, key, provider);
|
||||
AlgorithmId sigAlgId = SignatureUtil.fromSignature(sigEngine, key);
|
||||
info.infoSigAlgId = sigAlgId;
|
||||
|
||||
DerOutputStream out = new DerOutputStream();
|
||||
DerOutputStream tmp = new DerOutputStream();
|
||||
DerOutputStream out = new DerOutputStream();
|
||||
DerOutputStream tmp = new DerOutputStream();
|
||||
|
||||
// encode crl info
|
||||
byte[] tbsCertList = info.encodeInfo();
|
||||
tmp.writeBytes(tbsCertList);
|
||||
// encode crl info
|
||||
byte[] tbsCertList = info.encodeInfo();
|
||||
tmp.writeBytes(tbsCertList);
|
||||
|
||||
// encode algorithm identifier
|
||||
sigAlgId.encode(tmp);
|
||||
// encode algorithm identifier
|
||||
sigAlgId.encode(tmp);
|
||||
|
||||
// Create and encode the signature itself.
|
||||
sigEngine.update(tbsCertList, 0, tbsCertList.length);
|
||||
byte[] signature = sigEngine.sign();
|
||||
tmp.putBitString(signature);
|
||||
// Create and encode the signature itself.
|
||||
sigEngine.update(tbsCertList, 0, tbsCertList.length);
|
||||
byte[] signature = sigEngine.sign();
|
||||
tmp.putBitString(signature);
|
||||
|
||||
// Wrap the signed data in a SEQUENCE { data, algorithm, sig }
|
||||
out.write(DerValue.tag_Sequence, tmp);
|
||||
byte[] signedCRL = out.toByteArray();
|
||||
// Wrap the signed data in a SEQUENCE { data, algorithm, sig }
|
||||
out.write(DerValue.tag_Sequence, tmp);
|
||||
byte[] signedCRL = out.toByteArray();
|
||||
|
||||
return new X509CRLImpl(info, sigAlgId, signature,
|
||||
tbsCertList, signedCRL);
|
||||
} catch (IOException e) {
|
||||
throw new CRLException("Error while encoding data: " +
|
||||
e.getMessage());
|
||||
}
|
||||
return new X509CRLImpl(info, sigAlgId, signature,
|
||||
tbsCertList, signedCRL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1251,8 +1241,8 @@ public class X509CRLImpl extends X509CRL implements DerEncoder {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
out.write(signedCRL.clone());
|
||||
public void encode(DerOutputStream out) {
|
||||
out.writeBytes(signedCRL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -260,12 +260,10 @@ public class X509CertImpl extends X509Certificate implements DerEncoder {
|
|||
* Implements the <code>DerEncoder</code> interface.
|
||||
*
|
||||
* @param out the output stream on which to write the DER encoding.
|
||||
*
|
||||
* @exception IOException on encoding error.
|
||||
*/
|
||||
@Override
|
||||
public void encode(DerOutputStream out) throws IOException {
|
||||
out.write(signedCert.clone());
|
||||
public void encode(DerOutputStream out) {
|
||||
out.writeBytes(signedCert);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -468,35 +466,31 @@ public class X509CertImpl extends X509Certificate implements DerEncoder {
|
|||
public static X509CertImpl newSigned(X509CertInfo info, PrivateKey key, String algorithm, String provider)
|
||||
throws CertificateException, NoSuchAlgorithmException,
|
||||
InvalidKeyException, NoSuchProviderException, SignatureException {
|
||||
try {
|
||||
Signature sigEngine = SignatureUtil.fromKey(
|
||||
algorithm, key, provider);
|
||||
AlgorithmId algId = SignatureUtil.fromSignature(sigEngine, key);
|
||||
Signature sigEngine = SignatureUtil.fromKey(
|
||||
algorithm, key, provider);
|
||||
AlgorithmId algId = SignatureUtil.fromSignature(sigEngine, key);
|
||||
|
||||
DerOutputStream out = new DerOutputStream();
|
||||
DerOutputStream tmp = new DerOutputStream();
|
||||
DerOutputStream out = new DerOutputStream();
|
||||
DerOutputStream tmp = new DerOutputStream();
|
||||
|
||||
// encode certificate info
|
||||
info.setAlgorithmId(new CertificateAlgorithmId(algId));
|
||||
info.encode(tmp);
|
||||
byte[] rawCert = tmp.toByteArray();
|
||||
// encode certificate info
|
||||
info.setAlgorithmId(new CertificateAlgorithmId(algId));
|
||||
info.encode(tmp);
|
||||
byte[] rawCert = tmp.toByteArray();
|
||||
|
||||
// encode algorithm identifier
|
||||
algId.encode(tmp);
|
||||
// encode algorithm identifier
|
||||
algId.encode(tmp);
|
||||
|
||||
// Create and encode the signature itself.
|
||||
sigEngine.update(rawCert, 0, rawCert.length);
|
||||
byte[] signature = sigEngine.sign();
|
||||
tmp.putBitString(signature);
|
||||
// Create and encode the signature itself.
|
||||
sigEngine.update(rawCert, 0, rawCert.length);
|
||||
byte[] signature = sigEngine.sign();
|
||||
tmp.putBitString(signature);
|
||||
|
||||
// Wrap the signed data in a SEQUENCE { data, algorithm, sig }
|
||||
out.write(DerValue.tag_Sequence, tmp);
|
||||
byte[] signedCert = out.toByteArray();
|
||||
// Wrap the signed data in a SEQUENCE { data, algorithm, sig }
|
||||
out.write(DerValue.tag_Sequence, tmp);
|
||||
byte[] signedCert = out.toByteArray();
|
||||
|
||||
return new X509CertImpl(info, algId, signature, signedCert);
|
||||
} catch (IOException e) {
|
||||
throw new CertificateEncodingException(e.toString());
|
||||
}
|
||||
return new X509CertImpl(info, algId, signature, signedCert);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1253,13 +1247,7 @@ public class X509CertImpl extends X509Certificate implements DerEncoder {
|
|||
default:
|
||||
// add DER encoded form
|
||||
DerOutputStream derOut = new DerOutputStream();
|
||||
try {
|
||||
name.encode(derOut);
|
||||
} catch (IOException ioe) {
|
||||
// should not occur since name has already been decoded
|
||||
// from cert (this would indicate a bug in our code)
|
||||
throw new RuntimeException("name cannot be encoded", ioe);
|
||||
}
|
||||
name.encode(derOut);
|
||||
nameEntry.add(derOut.toByteArray());
|
||||
if (name.getType() == GeneralNameInterface.NAME_ANY
|
||||
&& name instanceof OtherName oname) {
|
||||
|
|
|
@ -145,15 +145,14 @@ public class X509CertInfo {
|
|||
*
|
||||
* @param out an output stream to which the certificate is appended.
|
||||
* @exception CertificateException on encoding errors.
|
||||
* @exception IOException on other errors.
|
||||
*/
|
||||
public void encode(DerOutputStream out)
|
||||
throws CertificateException, IOException {
|
||||
throws CertificateException {
|
||||
if (rawCertInfo == null) {
|
||||
emit(out);
|
||||
rawCertInfo = out.toByteArray();
|
||||
} else {
|
||||
out.write(rawCertInfo.clone());
|
||||
out.writeBytes(rawCertInfo.clone());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -170,7 +169,7 @@ public class X509CertInfo {
|
|||
rawCertInfo = tmp.toByteArray();
|
||||
}
|
||||
return rawCertInfo.clone();
|
||||
} catch (IOException | CertificateException e) {
|
||||
} catch (CertificateException e) {
|
||||
throw new CertificateEncodingException(e.toString());
|
||||
}
|
||||
}
|
||||
|
@ -464,8 +463,7 @@ public class X509CertInfo {
|
|||
/*
|
||||
* Marshal the contents of a "raw" certificate into a DER sequence.
|
||||
*/
|
||||
private void emit(DerOutputStream out)
|
||||
throws CertificateException, IOException {
|
||||
private void emit(DerOutputStream out) throws CertificateException {
|
||||
DerOutputStream tmp = new DerOutputStream();
|
||||
|
||||
// version number, iff not V1
|
||||
|
|
|
@ -55,7 +55,7 @@ import sun.security.util.*;
|
|||
*
|
||||
* @author David Brownell
|
||||
*/
|
||||
public class X509Key implements PublicKey {
|
||||
public class X509Key implements PublicKey, DerEncoder {
|
||||
|
||||
/** use serialVersionUID from JDK 1.1. for interoperability */
|
||||
@java.io.Serial
|
||||
|
@ -100,8 +100,7 @@ public class X509Key implements PublicKey {
|
|||
* data is stored and transmitted losslessly, but no knowledge
|
||||
* about this particular algorithm is available.
|
||||
*/
|
||||
private X509Key(AlgorithmId algid, BitArray key)
|
||||
throws InvalidKeyException {
|
||||
private X509Key(AlgorithmId algid, BitArray key) {
|
||||
this.algid = algid;
|
||||
setKey(key);
|
||||
encode();
|
||||
|
@ -190,10 +189,9 @@ public class X509Key implements PublicKey {
|
|||
* values using the X509Key member functions, such as <code>parse</code>
|
||||
* and <code>decode</code>.
|
||||
*
|
||||
* @exception IOException on parsing errors.
|
||||
* @exception InvalidKeyException on invalid key encodings.
|
||||
*/
|
||||
protected void parseKeyBits() throws IOException, InvalidKeyException {
|
||||
protected void parseKeyBits() throws InvalidKeyException {
|
||||
encode();
|
||||
}
|
||||
|
||||
|
@ -287,11 +285,9 @@ public class X509Key implements PublicKey {
|
|||
|
||||
/**
|
||||
* Encode SubjectPublicKeyInfo sequence on the DER output stream.
|
||||
*
|
||||
* @exception IOException on encoding errors.
|
||||
*/
|
||||
public final void encode(DerOutputStream out) throws IOException
|
||||
{
|
||||
@Override
|
||||
public final void encode(DerOutputStream out) {
|
||||
encode(out, this.algid, getKey());
|
||||
}
|
||||
|
||||
|
@ -299,26 +295,15 @@ public class X509Key implements PublicKey {
|
|||
* Returns the DER-encoded form of the key as a byte array.
|
||||
*/
|
||||
public byte[] getEncoded() {
|
||||
try {
|
||||
return getEncodedInternal().clone();
|
||||
} catch (InvalidKeyException e) {
|
||||
// XXX
|
||||
}
|
||||
return null;
|
||||
return getEncodedInternal().clone();
|
||||
}
|
||||
|
||||
public byte[] getEncodedInternal() throws InvalidKeyException {
|
||||
public byte[] getEncodedInternal() {
|
||||
byte[] encoded = encodedKey;
|
||||
if (encoded == null) {
|
||||
try {
|
||||
DerOutputStream out = new DerOutputStream();
|
||||
encode(out);
|
||||
encoded = out.toByteArray();
|
||||
} catch (IOException e) {
|
||||
throw new InvalidKeyException("IOException : " +
|
||||
e.getMessage());
|
||||
}
|
||||
encodedKey = encoded;
|
||||
DerOutputStream out = new DerOutputStream();
|
||||
encode(out);
|
||||
encodedKey = encoded = out.toByteArray();
|
||||
}
|
||||
return encoded;
|
||||
}
|
||||
|
@ -332,10 +317,8 @@ public class X509Key implements PublicKey {
|
|||
|
||||
/**
|
||||
* Returns the DER-encoded form of the key as a byte array.
|
||||
*
|
||||
* @exception InvalidKeyException on encoding errors.
|
||||
*/
|
||||
public byte[] encode() throws InvalidKeyException {
|
||||
public byte[] encode() {
|
||||
return getEncodedInternal().clone();
|
||||
}
|
||||
|
||||
|
@ -428,18 +411,14 @@ public class X509Key implements PublicKey {
|
|||
if (!(obj instanceof Key)) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
byte[] thisEncoded = this.getEncodedInternal();
|
||||
byte[] otherEncoded;
|
||||
if (obj instanceof X509Key) {
|
||||
otherEncoded = ((X509Key)obj).getEncodedInternal();
|
||||
} else {
|
||||
otherEncoded = ((Key)obj).getEncoded();
|
||||
}
|
||||
return Arrays.equals(thisEncoded, otherEncoded);
|
||||
} catch (InvalidKeyException e) {
|
||||
return false;
|
||||
byte[] thisEncoded = this.getEncodedInternal();
|
||||
byte[] otherEncoded;
|
||||
if (obj instanceof X509Key) {
|
||||
otherEncoded = ((X509Key) obj).getEncodedInternal();
|
||||
} else {
|
||||
otherEncoded = ((Key) obj).getEncoded();
|
||||
}
|
||||
return Arrays.equals(thisEncoded, otherEncoded);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -447,24 +426,18 @@ public class X509Key implements PublicKey {
|
|||
* which are equal will also have the same hashcode.
|
||||
*/
|
||||
public int hashCode() {
|
||||
try {
|
||||
byte[] b1 = getEncodedInternal();
|
||||
int r = b1.length;
|
||||
for (int i = 0; i < b1.length; i++) {
|
||||
r += (b1[i] & 0xff) * 37;
|
||||
}
|
||||
return r;
|
||||
} catch (InvalidKeyException e) {
|
||||
// should not happen
|
||||
return 0;
|
||||
byte[] b1 = getEncodedInternal();
|
||||
int r = b1.length;
|
||||
for (int i = 0; i < b1.length; i++) {
|
||||
r += (b1[i] & 0xff) * 37;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
/*
|
||||
* Produce SubjectPublicKey encoding from algorithm id and key material.
|
||||
*/
|
||||
static void encode(DerOutputStream out, AlgorithmId algid, BitArray key)
|
||||
throws IOException {
|
||||
static void encode(DerOutputStream out, AlgorithmId algid, BitArray key) {
|
||||
DerOutputStream tmp = new DerOutputStream();
|
||||
algid.encode(tmp);
|
||||
tmp.putUnalignedBitString(key);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue