8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
Reviewed-by: mullan
This commit is contained in:
parent
e8064300cb
commit
7e89934d9e
@ -454,7 +454,7 @@ public class AVA implements DerEncoder {
|
||||
if (embeddedHex.size() > 0) {
|
||||
// add space(s) before embedded hex bytes
|
||||
for (int i = 0; i < spaceCount; i++) {
|
||||
temp.append(" ");
|
||||
temp.append(' ');
|
||||
}
|
||||
spaceCount = 0;
|
||||
|
||||
@ -472,7 +472,7 @@ public class AVA implements DerEncoder {
|
||||
} else {
|
||||
// add space(s)
|
||||
for (int i = 0; i < spaceCount; i++) {
|
||||
temp.append(" ");
|
||||
temp.append(' ');
|
||||
}
|
||||
spaceCount = 0;
|
||||
temp.append((char)c);
|
||||
@ -853,7 +853,7 @@ public class AVA implements DerEncoder {
|
||||
}
|
||||
sbuffer.append(c);
|
||||
}
|
||||
typeAndValue.append(sbuffer.toString());
|
||||
typeAndValue.append(sbuffer);
|
||||
}
|
||||
return typeAndValue.toString();
|
||||
}
|
||||
@ -1039,7 +1039,7 @@ public class AVA implements DerEncoder {
|
||||
StringBuilder retval = new StringBuilder(40);
|
||||
|
||||
retval.append(keyword);
|
||||
retval.append("=");
|
||||
retval.append('=');
|
||||
|
||||
try {
|
||||
String valStr = value.getAsString();
|
||||
@ -1147,9 +1147,11 @@ public class AVA implements DerEncoder {
|
||||
// Emit the string ... quote it if needed
|
||||
// if string is already quoted, don't re-quote
|
||||
if (!alreadyQuoted && quoteNeeded) {
|
||||
retval.append("\"" + sbuffer.toString() + "\"");
|
||||
retval.append('\"')
|
||||
.append(sbuffer)
|
||||
.append('\"');
|
||||
} else {
|
||||
retval.append(sbuffer.toString());
|
||||
retval.append(sbuffer);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
@ -196,17 +196,20 @@ implements CertAttrSet<String> {
|
||||
* Return the object as a string.
|
||||
*/
|
||||
public String toString() {
|
||||
String s = super.toString() + "AuthorityKeyIdentifier [\n";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(super.toString())
|
||||
.append("AuthorityKeyIdentifier [\n");
|
||||
if (id != null) {
|
||||
s += id.toString(); // id already has a newline
|
||||
sb.append(id); // id already has a newline
|
||||
}
|
||||
if (names != null) {
|
||||
s += names.toString() + "\n";
|
||||
sb.append(names).append('\n');
|
||||
}
|
||||
if (serialNum != null) {
|
||||
s += serialNum.toString() + "\n";
|
||||
sb.append(serialNum).append('\n');
|
||||
}
|
||||
return (s + "]\n");
|
||||
sb.append("]\n");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -171,15 +171,11 @@ implements CertAttrSet<String> {
|
||||
* Return user readable form of extension.
|
||||
*/
|
||||
public String toString() {
|
||||
String s = super.toString() + "BasicConstraints:[\n";
|
||||
|
||||
s += ((ca) ? (" CA:true") : (" CA:false")) + "\n";
|
||||
if (pathLen >= 0) {
|
||||
s += " PathLen:" + pathLen + "\n";
|
||||
} else {
|
||||
s += " PathLen: undefined\n";
|
||||
}
|
||||
return (s + "]\n");
|
||||
return super.toString() +
|
||||
"BasicConstraints:[\n CA:" + ca +
|
||||
"\n PathLen:" +
|
||||
((pathLen >= 0) ? String.valueOf(pathLen) : " undefined") +
|
||||
"\n]\n";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -231,8 +231,8 @@ public class CRLDistributionPointsExtension extends Extension
|
||||
distributionPoints = (List<DistributionPoint>)obj;
|
||||
} else {
|
||||
throw new IOException("Attribute name [" + name +
|
||||
"] not recognized by " +
|
||||
"CertAttrSet:" + extensionName + ".");
|
||||
"] not recognized by " +
|
||||
"CertAttrSet:" + extensionName + '.');
|
||||
}
|
||||
encodeThis();
|
||||
}
|
||||
@ -245,8 +245,8 @@ public class CRLDistributionPointsExtension extends Extension
|
||||
return distributionPoints;
|
||||
} else {
|
||||
throw new IOException("Attribute name [" + name +
|
||||
"] not recognized by " +
|
||||
"CertAttrSet:" + extensionName + ".");
|
||||
"] not recognized by " +
|
||||
"CertAttrSet:" + extensionName + '.');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -146,8 +146,8 @@ implements CertAttrSet<String> {
|
||||
}
|
||||
crlNumber = (BigInteger)obj;
|
||||
} else {
|
||||
throw new IOException("Attribute name not recognized by"
|
||||
+ " CertAttrSet:" + extensionName + ".");
|
||||
throw new IOException("Attribute name not recognized by" +
|
||||
" CertAttrSet:" + extensionName + '.');
|
||||
}
|
||||
encodeThis();
|
||||
}
|
||||
@ -172,8 +172,8 @@ implements CertAttrSet<String> {
|
||||
if (name.equalsIgnoreCase(NUMBER)) {
|
||||
crlNumber = null;
|
||||
} else {
|
||||
throw new IOException("Attribute name not recognized by"
|
||||
+ " CertAttrSet:" + extensionName + ".");
|
||||
throw new IOException("Attribute name not recognized by" +
|
||||
" CertAttrSet:" + extensionName + '.');
|
||||
}
|
||||
encodeThis();
|
||||
}
|
||||
@ -182,10 +182,15 @@ implements CertAttrSet<String> {
|
||||
* Returns a printable representation of the CRLNumberExtension.
|
||||
*/
|
||||
public String toString() {
|
||||
String s = super.toString() + extensionLabel + ": " +
|
||||
((crlNumber == null) ? "" : Debug.toHexString(crlNumber))
|
||||
+ "\n";
|
||||
return (s);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(super.toString())
|
||||
.append(extensionLabel)
|
||||
.append(": ");
|
||||
if (crlNumber != null) {
|
||||
sb.append(Debug.toHexString(crlNumber));
|
||||
}
|
||||
sb.append('\n');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -195,7 +200,7 @@ implements CertAttrSet<String> {
|
||||
* @exception IOException on encoding errors.
|
||||
*/
|
||||
public void encode(OutputStream out) throws IOException {
|
||||
DerOutputStream tmp = new DerOutputStream();
|
||||
DerOutputStream tmp = new DerOutputStream();
|
||||
encode(out, PKIXExtensions.CRLNumber_Id, true);
|
||||
}
|
||||
|
||||
|
@ -158,7 +158,7 @@ public class CertException extends SecurityException {
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
return "[Certificate Exception: " + getMessage() + "]";
|
||||
return "[Certificate Exception: " + getMessage() + ']';
|
||||
}
|
||||
|
||||
/**
|
||||
@ -168,6 +168,6 @@ public class CertException extends SecurityException {
|
||||
{
|
||||
return getVerfDescription()
|
||||
+ ( (moreData != null)
|
||||
? ( "\n (" + moreData + ")" ) : "" );
|
||||
? ( "\n (" + moreData + ')' ) : "" );
|
||||
}
|
||||
}
|
||||
|
@ -160,10 +160,12 @@ implements CertAttrSet<String> {
|
||||
if (certPolicies == null) {
|
||||
return "";
|
||||
}
|
||||
StringBuilder sb = new StringBuilder(super.toString());
|
||||
sb.append("CertificatePolicies [\n");
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(super.toString())
|
||||
.append("CertificatePolicies [\n");
|
||||
for (PolicyInformation info : certPolicies) {
|
||||
sb.append(info.toString());
|
||||
sb.append(info);
|
||||
}
|
||||
sb.append("]\n");
|
||||
return sb.toString();
|
||||
|
@ -134,8 +134,8 @@ public class CertificateValidity implements CertAttrSet<String> {
|
||||
public String toString() {
|
||||
if (notBefore == null || notAfter == null)
|
||||
return "";
|
||||
return ("Validity: [From: " + notBefore.toString() +
|
||||
",\n To: " + notAfter.toString() + "]");
|
||||
return "Validity: [From: " + notBefore +
|
||||
",\n To: " + notAfter + ']';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -380,23 +380,29 @@ public class DistributionPoint {
|
||||
*/
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("DistributionPoint:\n ");
|
||||
if (fullName != null) {
|
||||
sb.append("DistributionPoint:\n " + fullName + "\n");
|
||||
sb.append(fullName);
|
||||
}
|
||||
if (relativeName != null) {
|
||||
sb.append("DistributionPoint:\n " + relativeName + "\n");
|
||||
sb.append(relativeName);
|
||||
}
|
||||
sb.append('\n');
|
||||
|
||||
if (reasonFlags != null) {
|
||||
sb.append(" ReasonFlags:\n");
|
||||
for (int i = 0; i < reasonFlags.length; i++) {
|
||||
if (reasonFlags[i]) {
|
||||
sb.append(" " + reasonToString(i) + "\n");
|
||||
sb.append(" ")
|
||||
.append(reasonToString(i))
|
||||
.append('\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
if (crlIssuer != null) {
|
||||
sb.append(" CRLIssuer:" + crlIssuer + "\n");
|
||||
sb.append(" CRLIssuer:")
|
||||
.append(crlIssuer)
|
||||
.append('\n');
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
@ -230,13 +230,13 @@ public class DistributionPointName {
|
||||
*/
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("DistributionPointName:\n ");
|
||||
if (fullName != null) {
|
||||
sb.append("DistributionPointName:\n " + fullName + "\n");
|
||||
|
||||
sb.append(fullName);
|
||||
} else {
|
||||
sb.append("DistributionPointName:\n " + relativeName + "\n");
|
||||
sb.append(relativeName);
|
||||
}
|
||||
|
||||
sb.append('\n');
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
@ -209,10 +209,15 @@ public class EDIPartyName implements GeneralNameInterface {
|
||||
* Return the printable string.
|
||||
*/
|
||||
public String toString() {
|
||||
return ("EDIPartyName: " +
|
||||
((assigner == null) ? "" :
|
||||
(" nameAssigner = " + assigner + ","))
|
||||
+ " partyName = " + party);
|
||||
StringBuilder sb = new StringBuilder("EDIPartyName: ");
|
||||
if (assigner != null) {
|
||||
sb.append(" nameAssigner = ")
|
||||
.append(assigner)
|
||||
.append(',');
|
||||
}
|
||||
sb.append(" partyName = ")
|
||||
.append(party);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -219,13 +219,8 @@ public class Extension implements java.security.cert.Extension {
|
||||
* Returns the Extension in user readable form.
|
||||
*/
|
||||
public String toString() {
|
||||
String s = "ObjectId: " + extensionId.toString();
|
||||
if (critical) {
|
||||
s += " Criticality=true\n";
|
||||
} else {
|
||||
s += " Criticality=false\n";
|
||||
}
|
||||
return (s);
|
||||
return "ObjectId: " + extensionId +
|
||||
" Criticality=" + critical + '\n';
|
||||
}
|
||||
|
||||
// Value to mix up the hash
|
||||
|
@ -127,15 +127,22 @@ public class GeneralSubtree {
|
||||
* Return a printable string of the GeneralSubtree.
|
||||
*/
|
||||
public String toString() {
|
||||
String s = "\n GeneralSubtree: [\n" +
|
||||
" GeneralName: " + ((name == null) ? "" : name.toString()) +
|
||||
"\n Minimum: " + minimum;
|
||||
if (maximum == -1) {
|
||||
s += "\t Maximum: undefined";
|
||||
} else
|
||||
s += "\t Maximum: " + maximum;
|
||||
s += " ]\n";
|
||||
return (s);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("\n GeneralSubtree: [")
|
||||
.append("\n GeneralName: ");
|
||||
if (name != null) {
|
||||
sb.append(name);
|
||||
}
|
||||
sb.append("\n Minimum: ")
|
||||
.append(minimum)
|
||||
.append("\n Maximum: ");
|
||||
if (maximum == -1) {
|
||||
sb.append("undefined");
|
||||
} else {
|
||||
sb.append(maximum);
|
||||
}
|
||||
sb.append(" ]\n");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -124,8 +124,7 @@ public class GeneralSubtrees implements Cloneable {
|
||||
* Return a printable string of the GeneralSubtree.
|
||||
*/
|
||||
public String toString() {
|
||||
String s = " GeneralSubtrees:\n" + trees.toString() + "\n";
|
||||
return s;
|
||||
return " GeneralSubtrees:\n" + trees + '\n';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -263,7 +263,7 @@ public class IPAddressName implements GeneralNameInterface {
|
||||
if (address.length == 8) {
|
||||
byte[] mask = new byte[4];
|
||||
System.arraycopy(address, 4, mask, 0, 4);
|
||||
name = name + "/" +
|
||||
name = name + '/' +
|
||||
InetAddress.getByAddress(mask).getHostAddress();
|
||||
}
|
||||
} else {
|
||||
@ -285,7 +285,7 @@ public class IPAddressName implements GeneralNameInterface {
|
||||
if (!ba.get(i))
|
||||
break;
|
||||
}
|
||||
name = name + "/" + i;
|
||||
name = name + '/' + i;
|
||||
// Verify remaining bits 0
|
||||
for (; i < 16*8; i++) {
|
||||
if (ba.get(i)) {
|
||||
|
@ -140,17 +140,20 @@ extends Extension implements CertAttrSet<String> {
|
||||
* Returns a printable representation of the IssuerAlternativeName.
|
||||
*/
|
||||
public String toString() {
|
||||
|
||||
String result = super.toString() + "IssuerAlternativeName [\n";
|
||||
if(names == null) {
|
||||
result += " null\n";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(super.toString())
|
||||
.append("IssuerAlternativeName [\n");
|
||||
if (names == null) {
|
||||
sb.append(" null\n");
|
||||
} else {
|
||||
for(GeneralName name: names.names()) {
|
||||
result += " "+name+"\n";
|
||||
for (GeneralName name : names.names()) {
|
||||
sb.append(" ")
|
||||
.append(name)
|
||||
.append('\n');
|
||||
}
|
||||
}
|
||||
result += "]\n";
|
||||
return result;
|
||||
sb.append("]\n");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -441,9 +441,9 @@ public class IssuingDistributionPointExtension extends Extension
|
||||
* Returns the extension as user readable string.
|
||||
*/
|
||||
public String toString() {
|
||||
|
||||
StringBuilder sb = new StringBuilder(super.toString());
|
||||
sb.append("IssuingDistributionPoint [\n ");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(super.toString())
|
||||
.append("IssuingDistributionPoint [\n ");
|
||||
|
||||
if (distributionPoint != null) {
|
||||
sb.append(distributionPoint);
|
||||
@ -453,23 +453,18 @@ public class IssuingDistributionPointExtension extends Extension
|
||||
sb.append(revocationReasons);
|
||||
}
|
||||
|
||||
sb.append((hasOnlyUserCerts)
|
||||
? (" Only contains user certs: true")
|
||||
: (" Only contains user certs: false")).append("\n");
|
||||
|
||||
sb.append((hasOnlyCACerts)
|
||||
? (" Only contains CA certs: true")
|
||||
: (" Only contains CA certs: false")).append("\n");
|
||||
|
||||
sb.append((hasOnlyAttributeCerts)
|
||||
? (" Only contains attribute certs: true")
|
||||
: (" Only contains attribute certs: false")).append("\n");
|
||||
|
||||
sb.append((isIndirectCRL)
|
||||
? (" Indirect CRL: true")
|
||||
: (" Indirect CRL: false")).append("\n");
|
||||
|
||||
sb.append("]\n");
|
||||
sb.append(" Only contains user certs: ")
|
||||
.append(hasOnlyUserCerts)
|
||||
.append('\n')
|
||||
.append(" Only contains CA certs: ")
|
||||
.append(hasOnlyCACerts)
|
||||
.append('\n')
|
||||
.append(" Only contains attribute certs: ")
|
||||
.append(hasOnlyAttributeCerts)
|
||||
.append('\n')
|
||||
.append(" Indirect CRL: ")
|
||||
.append(isIndirectCRL)
|
||||
.append("\n]\n");
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
@ -214,12 +214,19 @@ implements CertAttrSet<String>, Cloneable {
|
||||
* Return the printable string.
|
||||
*/
|
||||
public String toString() {
|
||||
return (super.toString() + "NameConstraints: [" +
|
||||
((permitted == null) ? "" :
|
||||
("\n Permitted:" + permitted.toString())) +
|
||||
((excluded == null) ? "" :
|
||||
("\n Excluded:" + excluded.toString()))
|
||||
+ " ]\n");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(super.toString())
|
||||
.append("NameConstraints: [");
|
||||
if (permitted != null) {
|
||||
sb.append("\n Permitted:")
|
||||
.append(permitted);
|
||||
}
|
||||
if (excluded != null) {
|
||||
sb.append("\n Excluded:")
|
||||
.append(excluded);
|
||||
}
|
||||
sb.append(" ]\n");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -175,19 +175,24 @@ implements CertAttrSet<String> {
|
||||
* Return the extension as user readable string.
|
||||
*/
|
||||
public String toString() {
|
||||
String s;
|
||||
s = super.toString() + "PolicyConstraints: [" + " Require: ";
|
||||
if (require == -1)
|
||||
s += "unspecified;";
|
||||
else
|
||||
s += require + ";";
|
||||
s += "\tInhibit: ";
|
||||
if (inhibit == -1)
|
||||
s += "unspecified";
|
||||
else
|
||||
s += inhibit;
|
||||
s += " ]\n";
|
||||
return s;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(super.toString())
|
||||
.append("PolicyConstraints: [")
|
||||
.append(" Require: ");
|
||||
if (require == -1) {
|
||||
sb.append("unspecified;");
|
||||
} else {
|
||||
sb.append(require)
|
||||
.append(';');
|
||||
}
|
||||
sb.append("\tInhibit: ");
|
||||
if (inhibit == -1) {
|
||||
sb.append("unspecified");
|
||||
} else {
|
||||
sb.append(inhibit);
|
||||
}
|
||||
sb.append(" ]\n");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -258,9 +258,7 @@ public class PolicyInformation {
|
||||
* Return a printable representation of the PolicyInformation.
|
||||
*/
|
||||
public String toString() {
|
||||
StringBuilder s = new StringBuilder(" [" + policyIdentifier.toString());
|
||||
s.append(policyQualifiers + " ]\n");
|
||||
return s.toString();
|
||||
return " [" + policyIdentifier + policyQualifiers + " ]\n";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -175,11 +175,22 @@ implements CertAttrSet<String> {
|
||||
* Return the printable string.
|
||||
*/
|
||||
public String toString() {
|
||||
return(super.toString() +
|
||||
"PrivateKeyUsage: [\n" +
|
||||
((notBefore == null) ? "" : "From: " + notBefore.toString() + ", ")
|
||||
+ ((notAfter == null) ? "" : "To: " + notAfter.toString())
|
||||
+ "]\n");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(super.toString())
|
||||
.append("PrivateKeyUsage: [\n");
|
||||
if (notBefore != null) {
|
||||
sb.append("From: ")
|
||||
.append(notBefore);
|
||||
if (notAfter != null) {
|
||||
sb.append(", ");
|
||||
}
|
||||
}
|
||||
if (notAfter != null) {
|
||||
sb.append("To: ")
|
||||
.append(notAfter);
|
||||
}
|
||||
sb.append("]\n");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -348,14 +348,11 @@ public class RDN {
|
||||
return assertion[0].toString();
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
StringJoiner sj = new StringJoiner(" + ");
|
||||
for (int i = 0; i < assertion.length; i++) {
|
||||
if (i != 0) {
|
||||
sb.append(" + ");
|
||||
}
|
||||
sb.append(assertion[i].toString());
|
||||
sj.add(assertion[i].toString());
|
||||
}
|
||||
return sb.toString();
|
||||
return sj.toString();
|
||||
}
|
||||
|
||||
/*
|
||||
@ -376,14 +373,11 @@ public class RDN {
|
||||
return assertion[0].toRFC1779String(oidMap);
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
StringJoiner sj = new StringJoiner(" + ");
|
||||
for (int i = 0; i < assertion.length; i++) {
|
||||
if (i != 0) {
|
||||
sb.append(" + ");
|
||||
}
|
||||
sb.append(assertion[i].toRFC1779String(oidMap));
|
||||
sj.add(assertion[i].toRFC1779String(oidMap));
|
||||
}
|
||||
return sb.toString();
|
||||
return sj.toString();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -101,7 +101,7 @@ public class SerialNumber {
|
||||
* Return the SerialNumber as user readable string.
|
||||
*/
|
||||
public String toString() {
|
||||
return ("SerialNumber: [" + Debug.toHexString(serialNum) + "]");
|
||||
return "SerialNumber: [" + Debug.toHexString(serialNum) + ']';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -238,8 +238,8 @@ public class SubjectInfoAccessExtension extends Extension
|
||||
* Return the extension as user readable string.
|
||||
*/
|
||||
public String toString() {
|
||||
return super.toString() + "SubjectInfoAccess [\n "
|
||||
+ accessDescriptions + "\n]\n";
|
||||
return super.toString() +
|
||||
"SubjectInfoAccess [\n " + accessDescriptions + "\n]\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -115,8 +115,8 @@ implements CertAttrSet<String> {
|
||||
* Returns a printable representation.
|
||||
*/
|
||||
public String toString() {
|
||||
return super.toString() + "SubjectKeyIdentifier [\n"
|
||||
+ String.valueOf(id) + "]\n";
|
||||
return super.toString() +
|
||||
"SubjectKeyIdentifier [\n" + id + "]\n";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -31,6 +31,7 @@ import java.security.PrivilegedExceptionAction;
|
||||
import java.security.AccessController;
|
||||
import java.security.Principal;
|
||||
import java.util.*;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import sun.security.util.*;
|
||||
import javax.security.auth.x500.X500Principal;
|
||||
@ -689,14 +690,11 @@ public class X500Name implements GeneralNameInterface, Principal {
|
||||
* The encodings of adjoining RelativeDistinguishedNames are separated
|
||||
* by a comma character (',' ASCII 44).
|
||||
*/
|
||||
StringBuilder fullname = new StringBuilder(48);
|
||||
StringJoiner sj = new StringJoiner(",");
|
||||
for (int i = names.length - 1; i >= 0; i--) {
|
||||
if (i < names.length - 1) {
|
||||
fullname.append(',');
|
||||
}
|
||||
fullname.append(names[i].toRFC2253String(oidMap));
|
||||
sj.add(names[i].toRFC2253String(oidMap));
|
||||
}
|
||||
return fullname.toString();
|
||||
return sj.toString();
|
||||
}
|
||||
|
||||
public String getRFC2253CanonicalName() {
|
||||
@ -722,14 +720,11 @@ public class X500Name implements GeneralNameInterface, Principal {
|
||||
* The encodings of adjoining RelativeDistinguishedNames are separated
|
||||
* by a comma character (',' ASCII 44).
|
||||
*/
|
||||
StringBuilder fullname = new StringBuilder(48);
|
||||
StringJoiner sj = new StringJoiner(",");
|
||||
for (int i = names.length - 1; i >= 0; i--) {
|
||||
if (i < names.length - 1) {
|
||||
fullname.append(',');
|
||||
}
|
||||
fullname.append(names[i].toRFC2253String(true));
|
||||
sj.add(names[i].toRFC2253String(true));
|
||||
}
|
||||
canonicalDn = fullname.toString();
|
||||
canonicalDn = sj.toString();
|
||||
return canonicalDn;
|
||||
}
|
||||
|
||||
@ -1064,16 +1059,16 @@ public class X500Name implements GeneralNameInterface, Principal {
|
||||
return;
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder(48);
|
||||
if (names != null) {
|
||||
for (int i = names.length - 1; i >= 0; i--) {
|
||||
if (i != names.length - 1) {
|
||||
sb.append(", ");
|
||||
}
|
||||
sb.append(names[i].toString());
|
||||
}
|
||||
if (names == null) {
|
||||
dn = "";
|
||||
return;
|
||||
}
|
||||
dn = sb.toString();
|
||||
|
||||
StringJoiner sj = new StringJoiner(", ");
|
||||
for (int i = names.length - 1; i >= 0; i--) {
|
||||
sj.add(names[i].toString());
|
||||
}
|
||||
dn = sj.toString();
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1090,16 +1085,15 @@ public class X500Name implements GeneralNameInterface, Principal {
|
||||
return names[0].toRFC1779String(oidMap);
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder(48);
|
||||
if (names != null) {
|
||||
for (int i = names.length - 1; i >= 0; i--) {
|
||||
if (i != names.length - 1) {
|
||||
sb.append(", ");
|
||||
}
|
||||
sb.append(names[i].toRFC1779String(oidMap));
|
||||
}
|
||||
if (names == null) {
|
||||
return "";
|
||||
}
|
||||
return sb.toString();
|
||||
|
||||
StringJoiner sj = new StringJoiner(", ");
|
||||
for (int i = names.length - 1; i >= 0; i--) {
|
||||
sj.add(names[i].toRFC1779String(oidMap));
|
||||
}
|
||||
return sj.toString();
|
||||
}
|
||||
|
||||
/****************************************************************/
|
||||
|
@ -291,40 +291,47 @@ public class X509CRLEntryImpl extends X509CRLEntry
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append(serialNumber.toString());
|
||||
sb.append(" On: " + revocationDate.toString());
|
||||
sb.append(serialNumber)
|
||||
.append(" On: ")
|
||||
.append(revocationDate);
|
||||
if (certIssuer != null) {
|
||||
sb.append("\n Certificate issuer: " + certIssuer);
|
||||
sb.append("\n Certificate issuer: ")
|
||||
.append(certIssuer);
|
||||
}
|
||||
if (extensions != null) {
|
||||
Collection<Extension> allEntryExts = extensions.getAllExtensions();
|
||||
Extension[] exts = allEntryExts.toArray(new Extension[0]);
|
||||
|
||||
sb.append("\n CRL Entry Extensions: " + exts.length);
|
||||
sb.append("\n CRL Entry Extensions: ")
|
||||
.append(exts.length);
|
||||
for (int i = 0; i < exts.length; i++) {
|
||||
sb.append("\n [" + (i+1) + "]: ");
|
||||
sb.append("\n [")
|
||||
.append(i+1)
|
||||
.append("]: ");
|
||||
Extension ext = exts[i];
|
||||
try {
|
||||
if (OIDMap.getClass(ext.getExtensionId()) == null) {
|
||||
sb.append(ext.toString());
|
||||
sb.append(ext);
|
||||
byte[] extValue = ext.getExtensionValue();
|
||||
if (extValue != null) {
|
||||
DerOutputStream out = new DerOutputStream();
|
||||
out.putOctetString(extValue);
|
||||
extValue = out.toByteArray();
|
||||
HexDumpEncoder enc = new HexDumpEncoder();
|
||||
sb.append("Extension unknown: "
|
||||
+ "DER encoded OCTET string =\n"
|
||||
+ enc.encodeBuffer(extValue) + "\n");
|
||||
sb.append("Extension unknown: ")
|
||||
.append("DER encoded OCTET string =\n")
|
||||
.append(enc.encodeBuffer(extValue))
|
||||
.append('\n');
|
||||
}
|
||||
} else
|
||||
sb.append(ext.toString()); //sub-class exists
|
||||
} else {
|
||||
sb.append(ext); //sub-class exists
|
||||
}
|
||||
} catch (Exception e) {
|
||||
sb.append(", Error parsing this extension");
|
||||
}
|
||||
}
|
||||
}
|
||||
sb.append("\n");
|
||||
sb.append('\n');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
@ -537,47 +537,65 @@ public class X509CRLImpl extends X509CRL implements DerEncoder {
|
||||
*/
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("X.509 CRL v" + (version+1) + "\n");
|
||||
sb.append("X.509 CRL v")
|
||||
.append(version+1)
|
||||
.append('\n');
|
||||
if (sigAlgId != null)
|
||||
sb.append("Signature Algorithm: " + sigAlgId.toString() +
|
||||
", OID=" + (sigAlgId.getOID()).toString() + "\n");
|
||||
sb.append("Signature Algorithm: ")
|
||||
.append(sigAlgId)
|
||||
.append(", OID=")
|
||||
.append(sigAlgId.getOID())
|
||||
.append('\n');
|
||||
if (issuer != null)
|
||||
sb.append("Issuer: " + issuer.toString() + "\n");
|
||||
sb.append("Issuer: ")
|
||||
.append(issuer)
|
||||
.append('\n');
|
||||
if (thisUpdate != null)
|
||||
sb.append("\nThis Update: " + thisUpdate.toString() + "\n");
|
||||
sb.append("\nThis Update: ")
|
||||
.append(thisUpdate)
|
||||
.append('\n');
|
||||
if (nextUpdate != null)
|
||||
sb.append("Next Update: " + nextUpdate.toString() + "\n");
|
||||
sb.append("Next Update: ")
|
||||
.append(nextUpdate)
|
||||
.append('\n');
|
||||
if (revokedList.isEmpty())
|
||||
sb.append("\nNO certificates have been revoked\n");
|
||||
else {
|
||||
sb.append("\nRevoked Certificates: " + revokedList.size());
|
||||
sb.append("\nRevoked Certificates: ")
|
||||
.append(revokedList.size());
|
||||
int i = 1;
|
||||
for (X509CRLEntry entry: revokedList) {
|
||||
sb.append("\n[" + i++ + "] " + entry.toString());
|
||||
sb.append("\n[")
|
||||
.append(i++)
|
||||
.append("] ")
|
||||
.append(entry);
|
||||
}
|
||||
}
|
||||
if (extensions != null) {
|
||||
Collection<Extension> allExts = extensions.getAllExtensions();
|
||||
Object[] objs = allExts.toArray();
|
||||
sb.append("\nCRL Extensions: " + objs.length);
|
||||
sb.append("\nCRL Extensions: ")
|
||||
.append(objs.length);
|
||||
for (int i = 0; i < objs.length; i++) {
|
||||
sb.append("\n[" + (i+1) + "]: ");
|
||||
sb.append("\n[").append(i+1).append("]: ");
|
||||
Extension ext = (Extension)objs[i];
|
||||
try {
|
||||
if (OIDMap.getClass(ext.getExtensionId()) == null) {
|
||||
sb.append(ext.toString());
|
||||
byte[] extValue = ext.getExtensionValue();
|
||||
if (extValue != null) {
|
||||
DerOutputStream out = new DerOutputStream();
|
||||
out.putOctetString(extValue);
|
||||
extValue = out.toByteArray();
|
||||
HexDumpEncoder enc = new HexDumpEncoder();
|
||||
sb.append("Extension unknown: "
|
||||
+ "DER encoded OCTET string =\n"
|
||||
+ enc.encodeBuffer(extValue) + "\n");
|
||||
}
|
||||
} else
|
||||
sb.append(ext.toString()); // sub-class exists
|
||||
if (OIDMap.getClass(ext.getExtensionId()) == null) {
|
||||
sb.append(ext);
|
||||
byte[] extValue = ext.getExtensionValue();
|
||||
if (extValue != null) {
|
||||
DerOutputStream out = new DerOutputStream();
|
||||
out.putOctetString(extValue);
|
||||
extValue = out.toByteArray();
|
||||
HexDumpEncoder enc = new HexDumpEncoder();
|
||||
sb.append("Extension unknown: ")
|
||||
.append("DER encoded OCTET string =\n")
|
||||
.append(enc.encodeBuffer(extValue))
|
||||
.append('\n');
|
||||
}
|
||||
} else {
|
||||
sb.append(ext); // sub-class exists
|
||||
}
|
||||
} catch (Exception e) {
|
||||
sb.append(", Error parsing this extension");
|
||||
}
|
||||
@ -585,10 +603,12 @@ public class X509CRLImpl extends X509CRL implements DerEncoder {
|
||||
}
|
||||
if (signature != null) {
|
||||
HexDumpEncoder encoder = new HexDumpEncoder();
|
||||
sb.append("\nSignature:\n" + encoder.encodeBuffer(signature)
|
||||
+ "\n");
|
||||
} else
|
||||
sb.append("\nSignature:\n")
|
||||
.append(encoder.encodeBuffer(signature))
|
||||
.append('\n');
|
||||
} else {
|
||||
sb.append("NOT signed yet\n");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ public class X509CertImpl extends X509Certificate implements DerEncoder {
|
||||
|
||||
private static final long serialVersionUID = -3457612960190864406L;
|
||||
|
||||
private static final String DOT = ".";
|
||||
private static final char DOT = '.';
|
||||
/**
|
||||
* Public attribute names.
|
||||
*/
|
||||
@ -799,17 +799,10 @@ public class X509CertImpl extends X509Certificate implements DerEncoder {
|
||||
if (info == null || algId == null || signature == null)
|
||||
return "";
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append("[\n");
|
||||
sb.append(info.toString() + "\n");
|
||||
sb.append(" Algorithm: [" + algId.toString() + "]\n");
|
||||
|
||||
HexDumpEncoder encoder = new HexDumpEncoder();
|
||||
sb.append(" Signature:\n" + encoder.encodeBuffer(signature));
|
||||
sb.append("\n]");
|
||||
|
||||
return sb.toString();
|
||||
return "[\n" + info + '\n' +
|
||||
" Algorithm: [" + algId + "]\n" +
|
||||
" Signature:\n" + encoder.encodeBuffer(signature) + "\n]";
|
||||
}
|
||||
|
||||
// the strongly typed gets, as per java.security.cert.X509Certificate
|
||||
@ -1941,31 +1934,30 @@ public class X509CertImpl extends X509Certificate implements DerEncoder {
|
||||
* only contains 0-9 and A-F. No small case, no colon.
|
||||
*/
|
||||
private String getCertificateFingerPrint(String mdAlg) {
|
||||
String fingerPrint = "";
|
||||
try {
|
||||
byte[] encCertInfo = getEncoded();
|
||||
MessageDigest md = MessageDigest.getInstance(mdAlg);
|
||||
byte[] digest = md.digest(encCertInfo);
|
||||
StringBuffer buf = new StringBuffer();
|
||||
StringBuilder sb = new StringBuilder(digest.length * 2);
|
||||
for (int i = 0; i < digest.length; i++) {
|
||||
byte2hex(digest[i], buf);
|
||||
byte2hex(digest[i], sb);
|
||||
}
|
||||
fingerPrint = buf.toString();
|
||||
return sb.toString();
|
||||
} catch (NoSuchAlgorithmException | CertificateEncodingException e) {
|
||||
// ignored
|
||||
}
|
||||
return fingerPrint;
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a byte to hex digit and writes to the supplied buffer
|
||||
* Converts a byte to hex digit and writes to the supplied builder
|
||||
*/
|
||||
private static void byte2hex(byte b, StringBuffer buf) {
|
||||
private static void byte2hex(byte b, StringBuilder buf) {
|
||||
char[] hexChars = { '0', '1', '2', '3', '4', '5', '6', '7', '8',
|
||||
'9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
||||
int high = ((b & 0xf0) >> 4);
|
||||
int low = (b & 0x0f);
|
||||
buf.append(hexChars[high]);
|
||||
buf.append(hexChars[low]);
|
||||
buf.append(hexChars[high])
|
||||
.append(hexChars[low]);
|
||||
}
|
||||
}
|
||||
|
@ -299,55 +299,60 @@ public class X509CertInfo implements CertAttrSet<String> {
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append("[\n");
|
||||
sb.append(" " + version.toString() + "\n");
|
||||
sb.append(" Subject: " + subject.toString() + "\n");
|
||||
sb.append(" Signature Algorithm: " + algId.toString() + "\n");
|
||||
sb.append(" Key: " + pubKey.toString() + "\n");
|
||||
sb.append(" " + interval.toString() + "\n");
|
||||
sb.append(" Issuer: " + issuer.toString() + "\n");
|
||||
sb.append(" " + serialNum.toString() + "\n");
|
||||
sb.append("[\n")
|
||||
.append(" ").append(version).append('\n')
|
||||
.append(" Subject: ").append(subject).append('\n')
|
||||
.append(" Signature Algorithm: ").append(algId).append('\n')
|
||||
.append(" Key: ").append(pubKey).append('\n')
|
||||
.append(" ").append(interval).append('\n')
|
||||
.append(" Issuer: ").append(issuer).append('\n')
|
||||
.append(" ").append(serialNum).append('\n');
|
||||
|
||||
// optional v2, v3 extras
|
||||
if (issuerUniqueId != null) {
|
||||
sb.append(" Issuer Id:\n" + issuerUniqueId.toString() + "\n");
|
||||
sb.append(" Issuer Id:\n").append(issuerUniqueId).append('\n');
|
||||
}
|
||||
if (subjectUniqueId != null) {
|
||||
sb.append(" Subject Id:\n" + subjectUniqueId.toString() + "\n");
|
||||
sb.append(" Subject Id:\n").append(subjectUniqueId).append('\n');
|
||||
}
|
||||
if (extensions != null) {
|
||||
Collection<Extension> allExts = extensions.getAllExtensions();
|
||||
Extension[] exts = allExts.toArray(new Extension[0]);
|
||||
sb.append("\nCertificate Extensions: " + exts.length);
|
||||
sb.append("\nCertificate Extensions: ").append(exts.length);
|
||||
for (int i = 0; i < exts.length; i++) {
|
||||
sb.append("\n[" + (i+1) + "]: ");
|
||||
sb.append("\n[").append(i+1).append("]: ");
|
||||
Extension ext = exts[i];
|
||||
try {
|
||||
if (OIDMap.getClass(ext.getExtensionId()) == null) {
|
||||
sb.append(ext.toString());
|
||||
sb.append(ext);
|
||||
byte[] extValue = ext.getExtensionValue();
|
||||
if (extValue != null) {
|
||||
DerOutputStream out = new DerOutputStream();
|
||||
out.putOctetString(extValue);
|
||||
extValue = out.toByteArray();
|
||||
HexDumpEncoder enc = new HexDumpEncoder();
|
||||
sb.append("Extension unknown: "
|
||||
+ "DER encoded OCTET string =\n"
|
||||
+ enc.encodeBuffer(extValue) + "\n");
|
||||
sb.append("Extension unknown: ")
|
||||
.append("DER encoded OCTET string =\n")
|
||||
.append(enc.encodeBuffer(extValue))
|
||||
.append('\n');
|
||||
}
|
||||
} else
|
||||
sb.append(ext.toString()); //sub-class exists
|
||||
} else {
|
||||
sb.append(ext); //sub-class exists
|
||||
}
|
||||
} catch (Exception e) {
|
||||
sb.append(", Error parsing this extension");
|
||||
}
|
||||
}
|
||||
Map<String,Extension> invalid = extensions.getUnparseableExtensions();
|
||||
if (invalid.isEmpty() == false) {
|
||||
sb.append("\nUnparseable certificate extensions: " + invalid.size());
|
||||
sb.append("\nUnparseable certificate extensions: ")
|
||||
.append(invalid.size());
|
||||
int i = 1;
|
||||
for (Extension ext : invalid.values()) {
|
||||
sb.append("\n[" + (i++) + "]: ");
|
||||
sb.append(ext);
|
||||
sb.append("\n[")
|
||||
.append(i++)
|
||||
.append("]: ")
|
||||
.append(ext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user