src/java.base/share/classes/java/security/cert/X509CertSelector.java

Print this page
rev 10552 : 8055723[core]: Replace concat String to append in StringBuilder parameters
Contributed-by: Otavio Santana <otaviojava@java.net>


1797      * @return a {@code Collection} of names (or {@code null})
1798      * @see #setPathToNames
1799      */
1800     public Collection<List<?>> getPathToNames() {
1801         if (pathToNames == null) {
1802             return null;
1803         }
1804         return cloneNames(pathToNames);
1805     }
1806 
1807     /**
1808      * Return a printable representation of the {@code CertSelector}.
1809      *
1810      * @return a {@code String} describing the contents of the
1811      *         {@code CertSelector}
1812      */
1813     public String toString() {
1814         StringBuilder sb = new StringBuilder();
1815         sb.append("X509CertSelector: [\n");
1816         if (x509Cert != null) {
1817             sb.append("  Certificate: " + x509Cert.toString() + "\n");

1818         }
1819         if (serialNumber != null) {
1820             sb.append("  Serial Number: " + serialNumber.toString() + "\n");

1821         }
1822         if (issuer != null) {
1823             sb.append("  Issuer: " + getIssuerAsString() + "\n");
1824         }
1825         if (subject != null) {
1826             sb.append("  Subject: " + getSubjectAsString() + "\n");
1827         }
1828         sb.append("  matchAllSubjectAltNames flag: "
1829                   + String.valueOf(matchAllSubjectAltNames) + "\n");
1830         if (subjectAlternativeNames != null) {
1831             sb.append("  SubjectAlternativeNames:\n");
1832             Iterator<List<?>> i = subjectAlternativeNames.iterator();
1833             while (i.hasNext()) {
1834                 List<?> list = i.next();
1835                 sb.append("    type " + list.get(0) +
1836                           ", name " + list.get(1) + "\n");
1837             }
1838         }
1839         if (subjectKeyID != null) {
1840             HexDumpEncoder enc = new HexDumpEncoder();
1841             sb.append("  Subject Key Identifier: " +
1842                       enc.encodeBuffer(subjectKeyID) + "\n");
1843         }
1844         if (authorityKeyID != null) {
1845             HexDumpEncoder enc = new HexDumpEncoder();
1846             sb.append("  Authority Key Identifier: " +
1847                       enc.encodeBuffer(authorityKeyID) + "\n");
1848         }
1849         if (certificateValid != null) {
1850             sb.append("  Certificate Valid: " +
1851                       certificateValid.toString() + "\n");
1852         }
1853         if (privateKeyValid != null) {
1854             sb.append("  Private Key Valid: " +
1855                       privateKeyValid.toString() + "\n");
1856         }
1857         if (subjectPublicKeyAlgID != null) {
1858             sb.append("  Subject Public Key AlgID: " +
1859                       subjectPublicKeyAlgID.toString() + "\n");
1860         }
1861         if (subjectPublicKey != null) {
1862             sb.append("  Subject Public Key: " +
1863                       subjectPublicKey.toString() + "\n");
1864         }
1865         if (keyUsage != null) {
1866             sb.append("  Key Usage: " + keyUsageToString(keyUsage) + "\n");

1867         }
1868         if (keyPurposeSet != null) {
1869             sb.append("  Extended Key Usage: " +
1870                       keyPurposeSet.toString() + "\n");
1871         }
1872         if (policy != null) {
1873             sb.append("  Policy: " + policy.toString() + "\n");
1874         }
1875         if (pathToGeneralNames != null) {
1876             sb.append("  Path to names:\n");
1877             Iterator<GeneralNameInterface> i = pathToGeneralNames.iterator();
1878             while (i.hasNext()) {
1879                 sb.append("    " + i.next() + "\n");
1880             }
1881         }
1882         sb.append("]");
1883         return sb.toString();
1884     }
1885 
1886     // Copied from sun.security.x509.KeyUsageExtension
1887     // (without calling the superclass)
1888     /**
1889      * Returns a printable representation of the KeyUsage.
1890      */
1891     private static String keyUsageToString(boolean[] k) {
1892         String s = "KeyUsage [\n";
1893         try {
1894             if (k[0]) {
1895                 s += "  DigitalSignature\n";
1896             }
1897             if (k[1]) {
1898                 s += "  Non_repudiation\n";
1899             }
1900             if (k[2]) {
1901                 s += "  Key_Encipherment\n";
1902             }




1797      * @return a {@code Collection} of names (or {@code null})
1798      * @see #setPathToNames
1799      */
1800     public Collection<List<?>> getPathToNames() {
1801         if (pathToNames == null) {
1802             return null;
1803         }
1804         return cloneNames(pathToNames);
1805     }
1806 
1807     /**
1808      * Return a printable representation of the {@code CertSelector}.
1809      *
1810      * @return a {@code String} describing the contents of the
1811      *         {@code CertSelector}
1812      */
1813     public String toString() {
1814         StringBuilder sb = new StringBuilder();
1815         sb.append("X509CertSelector: [\n");
1816         if (x509Cert != null) {
1817             sb.append("  Certificate: ").append(x509Cert)
1818                     .append('\n');
1819         }
1820         if (serialNumber != null) {
1821             sb.append("  Serial Number: ").append(serialNumber)
1822                     .append('\n');
1823         }
1824         if (issuer != null) {
1825             sb.append("  Issuer: ").append(getIssuerAsString()).append('\n');
1826         }
1827         if (subject != null) {
1828             sb.append("  Subject: ").append(getSubjectAsString()).append('\n');
1829         }
1830         sb.append("  matchAllSubjectAltNames flag: ")
1831                 .append(matchAllSubjectAltNames).append('\n');
1832         if (subjectAlternativeNames != null) {
1833             sb.append("  SubjectAlternativeNames:\n");
1834             Iterator<List<?>> i = subjectAlternativeNames.iterator();
1835             while (i.hasNext()) {
1836                 List<?> list = i.next();
1837                 sb.append("    type ").append(list.get(0)).append(", name ")
1838                         .append(list.get(1)).append('\n');
1839             }
1840         }
1841         if (subjectKeyID != null) {
1842             HexDumpEncoder enc = new HexDumpEncoder();
1843             sb.append("  Subject Key Identifier: ")
1844                     .append(enc.encodeBuffer(subjectKeyID)).append('\n');
1845         }
1846         if (authorityKeyID != null) {
1847             HexDumpEncoder enc = new HexDumpEncoder();
1848             sb.append("  Authority Key Identifier: ")
1849                     .append(enc.encodeBuffer(authorityKeyID)).append('\n');
1850         }
1851         if (certificateValid != null) {
1852             sb.append("  Certificate Valid: ").append(certificateValid)
1853                     .append('\n');
1854         }
1855         if (privateKeyValid != null) {
1856             sb.append("  Private Key Valid: ").append(privateKeyValid)
1857                     .append('\n');
1858         }
1859         if (subjectPublicKeyAlgID != null) {
1860             sb.append("  Subject Public Key AlgID: ")
1861                     .append(subjectPublicKeyAlgID).append('\n');
1862         }
1863         if (subjectPublicKey != null) {
1864             sb.append("  Subject Public Key: ").append(subjectPublicKey)
1865                     .append('\n');
1866         }
1867         if (keyUsage != null) {
1868             sb.append("  Key Usage: ").append(keyUsageToString(keyUsage))
1869                     .append('\n');
1870         }
1871         if (keyPurposeSet != null) {
1872             sb.append("  Extended Key Usage: ").append(keyPurposeSet)
1873                     .append('\n');
1874         }
1875         if (policy != null) {
1876             sb.append("  Policy: ").append(policy).append('\n');
1877         }
1878         if (pathToGeneralNames != null) {
1879             sb.append("  Path to names:\n");
1880             Iterator<GeneralNameInterface> i = pathToGeneralNames.iterator();
1881             while (i.hasNext()) {
1882                 sb.append("    ").append(i.next()).append('\n');
1883             }
1884         }
1885         sb.append(']');
1886         return sb.toString();
1887     }
1888 
1889     // Copied from sun.security.x509.KeyUsageExtension
1890     // (without calling the superclass)
1891     /**
1892      * Returns a printable representation of the KeyUsage.
1893      */
1894     private static String keyUsageToString(boolean[] k) {
1895         String s = "KeyUsage [\n";
1896         try {
1897             if (k[0]) {
1898                 s += "  DigitalSignature\n";
1899             }
1900             if (k[1]) {
1901                 s += "  Non_repudiation\n";
1902             }
1903             if (k[2]) {
1904                 s += "  Key_Encipherment\n";
1905             }