src/java.base/share/classes/sun/security/ssl/SupportedEllipticCurvesExtension.java

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


  96 
  97     @Override
  98     int length() {
  99         return 6 + (curveIds.length << 1);
 100     }
 101 
 102     @Override
 103     void send(HandshakeOutStream s) throws IOException {
 104         s.putInt16(type.id);
 105         int k = curveIds.length << 1;
 106         s.putInt16(k + 2);
 107         s.putInt16(k);
 108         for (int curveId : curveIds) {
 109             s.putInt16(curveId);
 110         }
 111     }
 112 
 113     @Override
 114     public String toString() {
 115         StringBuilder sb = new StringBuilder();
 116         sb.append("Extension " + type + ", curve names: {");
 117         boolean first = true;
 118         for (int curveId : curveIds) {
 119             if (first) {
 120                 first = false;
 121             } else {
 122                 sb.append(", ");
 123             }
 124             // first check if it is a known named curve, then try other cases.
 125             String oid = getCurveOid(curveId);
 126             if (oid != null) {
 127                 ECParameterSpec spec = JsseJce.getECParameterSpec(oid);
 128                 // this toString() output will look nice for the current
 129                 // implementation of the ECParameterSpec class in the Sun
 130                 // provider, but may not look good for other implementations.
 131                 if (spec != null) {
 132                     sb.append(spec.toString().split(" ")[0]);
 133                 } else {
 134                     sb.append(oid);
 135                 }
 136             } else if (curveId == ARBITRARY_PRIME) {
 137                 sb.append("arbitrary_explicit_prime_curves");
 138             } else if (curveId == ARBITRARY_CHAR2) {
 139                 sb.append("arbitrary_explicit_char2_curves");
 140             } else {
 141                 sb.append("unknown curve " + curveId);
 142             }
 143         }
 144         sb.append("}");
 145         return sb.toString();
 146     }
 147 
 148     // Test whether we support the curve with the given index.
 149     static boolean isSupported(int index) {
 150         if ((index <= 0) || (index >= NAMED_CURVE_OID_TABLE.length)) {
 151             return false;
 152         }
 153         if (fips == false) {
 154             // in non-FIPS mode, we support all valid indices
 155             return true;
 156         }
 157         return DEFAULT.contains(index);
 158     }
 159 
 160     static int getCurveIndex(ECParameterSpec params) {
 161         String oid = JsseJce.getNamedCurveOid(params);




  96 
  97     @Override
  98     int length() {
  99         return 6 + (curveIds.length << 1);
 100     }
 101 
 102     @Override
 103     void send(HandshakeOutStream s) throws IOException {
 104         s.putInt16(type.id);
 105         int k = curveIds.length << 1;
 106         s.putInt16(k + 2);
 107         s.putInt16(k);
 108         for (int curveId : curveIds) {
 109             s.putInt16(curveId);
 110         }
 111     }
 112 
 113     @Override
 114     public String toString() {
 115         StringBuilder sb = new StringBuilder();
 116         sb.append("Extension ").append(type).append(", curve names: {");
 117         boolean first = true;
 118         for (int curveId : curveIds) {
 119             if (first) {
 120                 first = false;
 121             } else {
 122                 sb.append(", ");
 123             }
 124             // first check if it is a known named curve, then try other cases.
 125             String oid = getCurveOid(curveId);
 126             if (oid != null) {
 127                 ECParameterSpec spec = JsseJce.getECParameterSpec(oid);
 128                 // this toString() output will look nice for the current
 129                 // implementation of the ECParameterSpec class in the Sun
 130                 // provider, but may not look good for other implementations.
 131                 if (spec != null) {
 132                     sb.append(spec.toString().split(" ")[0]);
 133                 } else {
 134                     sb.append(oid);
 135                 }
 136             } else if (curveId == ARBITRARY_PRIME) {
 137                 sb.append("arbitrary_explicit_prime_curves");
 138             } else if (curveId == ARBITRARY_CHAR2) {
 139                 sb.append("arbitrary_explicit_char2_curves");
 140             } else {
 141                 sb.append("unknown curve ").append(curveId);
 142             }
 143         }
 144         sb.append("}");
 145         return sb.toString();
 146     }
 147 
 148     // Test whether we support the curve with the given index.
 149     static boolean isSupported(int index) {
 150         if ((index <= 0) || (index >= NAMED_CURVE_OID_TABLE.length)) {
 151             return false;
 152         }
 153         if (fips == false) {
 154             // in non-FIPS mode, we support all valid indices
 155             return true;
 156         }
 157         return DEFAULT.contains(index);
 158     }
 159 
 160     static int getCurveIndex(ECParameterSpec params) {
 161         String oid = JsseJce.getNamedCurveOid(params);