< prev index next >

src/java.base/share/classes/sun/security/x509/AlgorithmId.java

Print this page
rev 57532 : 8236470: Deal with ECDSA using ecdsa-with-SHA2 plus hash algorithm as AlgorithmId


 228      * call when you do not need to ensure cross-system portability
 229      * of algorithm names, or need a user friendly name.
 230      */
 231     public final ObjectIdentifier getOID () {
 232         return algid;
 233     }
 234 
 235     /**
 236      * Returns a name for the algorithm which may be more intelligible
 237      * to humans than the algorithm's OID, but which won't necessarily
 238      * be comprehensible on other systems.  For example, this might
 239      * return a name such as "MD5withRSA" for a signature algorithm on
 240      * some systems.  It also returns names like "OID.1.2.3.4", when
 241      * no particular name for the algorithm is known.
 242      */
 243     public String getName() {
 244         String algName = nameTable.get(algid);
 245         if (algName != null) {
 246             return algName;
 247         }
 248         if ((params != null) && algid.equals((Object)specifiedWithECDSA_oid)) {
 249             try {
 250                 AlgorithmId paramsId =
 251                         AlgorithmId.parse(new DerValue(getEncodedParams()));
 252                 String paramsName = paramsId.getName();
 253                 algName = makeSigAlg(paramsName, "EC");
 254             } catch (IOException e) {
 255                 // ignore
 256             }
 257         }
 258         return (algName == null) ? algid.toString() : algName;
 259     }
 260 
 261     public AlgorithmParameters getParameters() {
 262         return algParams;
 263     }
 264 
 265     /**
 266      * Returns the DER encoded parameter, which can then be
 267      * used to initialize java.security.AlgorithmParamters.
 268      *
 269      * @return DER encoded parameters, or null not present.
 270      */
 271     public byte[] getEncodedParams() throws IOException {
 272         return (params == null) ? null : params.toByteArray();
 273     }
 274 
 275     /**
 276      * Returns true iff the argument indicates the same algorithm
 277      * with the same parameters.


 364          * Get the algorithm ID and any parameters.
 365          */
 366         ObjectIdentifier        algid;
 367         DerValue                params;
 368         DerInputStream          in = val.toDerInputStream();
 369 
 370         algid = in.getOID();
 371         if (in.available() == 0) {
 372             params = null;
 373         } else {
 374             params = in.getDerValue();
 375             if (params.tag == DerValue.tag_Null) {
 376                 if (params.length() != 0) {
 377                     throw new IOException("invalid NULL");
 378                 }
 379                 params = null;
 380             }
 381             if (in.available() != 0) {
 382                 throw new IOException("Invalid AlgorithmIdentifier: extra data");
 383             }














 384         }
 385 
 386         return new AlgorithmId(algid, params);
 387     }
 388 
 389     /**
 390      * Returns one of the algorithm IDs most commonly associated
 391      * with this algorithm name.
 392      *
 393      * @param algname the name being used
 394      * @deprecated use the short get form of this method.
 395      * @exception NoSuchAlgorithmException on error.
 396      */
 397     @Deprecated
 398     public static AlgorithmId getAlgorithmId(String algname)
 399             throws NoSuchAlgorithmException {
 400         return get(algname);
 401     }
 402 
 403     /**




 228      * call when you do not need to ensure cross-system portability
 229      * of algorithm names, or need a user friendly name.
 230      */
 231     public final ObjectIdentifier getOID () {
 232         return algid;
 233     }
 234 
 235     /**
 236      * Returns a name for the algorithm which may be more intelligible
 237      * to humans than the algorithm's OID, but which won't necessarily
 238      * be comprehensible on other systems.  For example, this might
 239      * return a name such as "MD5withRSA" for a signature algorithm on
 240      * some systems.  It also returns names like "OID.1.2.3.4", when
 241      * no particular name for the algorithm is known.
 242      */
 243     public String getName() {
 244         String algName = nameTable.get(algid);
 245         if (algName != null) {
 246             return algName;
 247         }










 248         return (algName == null) ? algid.toString() : algName;
 249     }
 250 
 251     public AlgorithmParameters getParameters() {
 252         return algParams;
 253     }
 254 
 255     /**
 256      * Returns the DER encoded parameter, which can then be
 257      * used to initialize java.security.AlgorithmParamters.
 258      *
 259      * @return DER encoded parameters, or null not present.
 260      */
 261     public byte[] getEncodedParams() throws IOException {
 262         return (params == null) ? null : params.toByteArray();
 263     }
 264 
 265     /**
 266      * Returns true iff the argument indicates the same algorithm
 267      * with the same parameters.


 354          * Get the algorithm ID and any parameters.
 355          */
 356         ObjectIdentifier        algid;
 357         DerValue                params;
 358         DerInputStream          in = val.toDerInputStream();
 359 
 360         algid = in.getOID();
 361         if (in.available() == 0) {
 362             params = null;
 363         } else {
 364             params = in.getDerValue();
 365             if (params.tag == DerValue.tag_Null) {
 366                 if (params.length() != 0) {
 367                     throw new IOException("invalid NULL");
 368                 }
 369                 params = null;
 370             }
 371             if (in.available() != 0) {
 372                 throw new IOException("Invalid AlgorithmIdentifier: extra data");
 373             }
 374             // Some implementation uses ecdsa-with-SHA2 as the algorithm and
 375             // specifies the hash algorithm in parameters. Here we convert it
 376             // directly to a signature algorithm including the hash algorithm.
 377             if (algid.equals(specifiedWithECDSA_oid)) {
 378                 try {
 379                     AlgorithmId paramsId = AlgorithmId.parse(params);
 380                     String paramsName = paramsId.getName();
 381                     String algName = makeSigAlg(paramsName, "EC");
 382                     algid = AlgorithmId.get(algName).getOID();
 383                     params = null;
 384                 } catch (Exception e) {
 385                     // ignore
 386                 }
 387             }
 388         }
 389 
 390         return new AlgorithmId(algid, params);
 391     }
 392 
 393     /**
 394      * Returns one of the algorithm IDs most commonly associated
 395      * with this algorithm name.
 396      *
 397      * @param algname the name being used
 398      * @deprecated use the short get form of this method.
 399      * @exception NoSuchAlgorithmException on error.
 400      */
 401     @Deprecated
 402     public static AlgorithmId getAlgorithmId(String algname)
 403             throws NoSuchAlgorithmException {
 404         return get(algname);
 405     }
 406 
 407     /**


< prev index next >