< prev index next >

src/java.base/share/classes/javax/crypto/Mac.java

Print this page
rev 15967 : [mq]: GetInstance


 149      * MacSpi implementation from the first
 150      * Provider that supports the specified algorithm is returned.
 151      *
 152      * <p> Note that the list of registered providers may be retrieved via
 153      * the {@link Security#getProviders() Security.getProviders()} method.
 154      *
 155      * @implNote
 156      * The JDK Reference Implementation additionally uses the
 157      * {@code jdk.security.provider.preferred}
 158      * {@link Security#getProperty(String) Security} property to determine
 159      * the preferred provider order for the specified algorithm. This
 160      * may be different than the order of providers returned by
 161      * {@link Security#getProviders() Security.getProviders()}.
 162      *
 163      * @param algorithm the standard name of the requested MAC algorithm.
 164      * See the Mac section in the <a href=
 165      *   "{@docRoot}/../technotes/guides/security/StandardNames.html#Mac">
 166      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 167      * for information about standard algorithm names.
 168      *
 169      * @return the new {@code Mac} object.
 170      *
 171      * @exception NoSuchAlgorithmException if no Provider supports a
 172      *          MacSpi implementation for the
 173      *          specified algorithm.

 174      *
 175      * @see java.security.Provider
 176      */
 177     public static final Mac getInstance(String algorithm)
 178             throws NoSuchAlgorithmException {
 179         List<Service> services = GetInstance.getServices("Mac", algorithm);
 180         // make sure there is at least one service from a signed provider
 181         Iterator<Service> t = services.iterator();
 182         while (t.hasNext()) {
 183             Service s = t.next();
 184             if (JceSecurity.canUseProvider(s.getProvider()) == false) {
 185                 continue;
 186             }
 187             return new Mac(s, t, algorithm);
 188         }
 189         throw new NoSuchAlgorithmException
 190                                 ("Algorithm " + algorithm + " not available");
 191     }
 192 
 193     /**
 194      * Returns a {@code Mac} object that implements the
 195      * specified MAC algorithm.
 196      *
 197      * <p> A new Mac object encapsulating the
 198      * MacSpi implementation from the specified provider
 199      * is returned.  The specified provider must be registered
 200      * in the security provider list.
 201      *
 202      * <p> Note that the list of registered providers may be retrieved via
 203      * the {@link Security#getProviders() Security.getProviders()} method.
 204      *
 205      * @param algorithm the standard name of the requested MAC algorithm.
 206      * See the Mac section in the <a href=
 207      *   "{@docRoot}/../technotes/guides/security/StandardNames.html#Mac">
 208      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 209      * for information about standard algorithm names.
 210      *
 211      * @param provider the name of the provider.
 212      *
 213      * @return the new {@code Mac} object.



 214      *
 215      * @exception NoSuchAlgorithmException if a MacSpi
 216      *          implementation for the specified algorithm is not
 217      *          available from the specified provider.
 218      *
 219      * @exception NoSuchProviderException if the specified provider is not
 220      *          registered in the security provider list.
 221      *
 222      * @exception IllegalArgumentException if the {@code provider}
 223      *          is null or empty.
 224      *
 225      * @see java.security.Provider
 226      */
 227     public static final Mac getInstance(String algorithm, String provider)
 228             throws NoSuchAlgorithmException, NoSuchProviderException {
 229         Instance instance = JceSecurity.getInstance
 230                 ("Mac", MacSpi.class, algorithm, provider);
 231         return new Mac((MacSpi)instance.impl, instance.provider, algorithm);
 232     }
 233 
 234     /**
 235      * Returns a {@code Mac} object that implements the
 236      * specified MAC algorithm.
 237      *
 238      * <p> A new Mac object encapsulating the
 239      * MacSpi implementation from the specified Provider
 240      * object is returned.  Note that the specified Provider object
 241      * does not have to be registered in the provider list.
 242      *
 243      * @param algorithm the standard name of the requested MAC algorithm.
 244      * See the Mac section in the <a href=
 245      *   "{@docRoot}/../technotes/guides/security/StandardNames.html#Mac">
 246      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 247      * for information about standard algorithm names.
 248      *
 249      * @param provider the provider.
 250      *
 251      * @return the new {@code Mac} object.



 252      *
 253      * @exception NoSuchAlgorithmException if a MacSpi
 254      *          implementation for the specified algorithm is not available
 255      *          from the specified Provider object.
 256      *
 257      * @exception IllegalArgumentException if the {@code provider}
 258      *          is null.
 259      *
 260      * @see java.security.Provider
 261      */
 262     public static final Mac getInstance(String algorithm, Provider provider)
 263             throws NoSuchAlgorithmException {
 264         Instance instance = JceSecurity.getInstance
 265                 ("Mac", MacSpi.class, algorithm, provider);
 266         return new Mac((MacSpi)instance.impl, instance.provider, algorithm);
 267     }
 268 
 269     // max number of debug warnings to print from chooseFirstProvider()
 270     private static int warnCount = 10;
 271 
 272     /**
 273      * Choose the Spi from the first provider available. Used if
 274      * delayed provider selection is not possible because init()
 275      * is not the first method called.
 276      */
 277     void chooseFirstProvider() {
 278         if ((spi != null) || (serviceIterator == null)) {




 149      * MacSpi implementation from the first
 150      * Provider that supports the specified algorithm is returned.
 151      *
 152      * <p> Note that the list of registered providers may be retrieved via
 153      * the {@link Security#getProviders() Security.getProviders()} method.
 154      *
 155      * @implNote
 156      * The JDK Reference Implementation additionally uses the
 157      * {@code jdk.security.provider.preferred}
 158      * {@link Security#getProperty(String) Security} property to determine
 159      * the preferred provider order for the specified algorithm. This
 160      * may be different than the order of providers returned by
 161      * {@link Security#getProviders() Security.getProviders()}.
 162      *
 163      * @param algorithm the standard name of the requested MAC algorithm.
 164      * See the Mac section in the <a href=
 165      *   "{@docRoot}/../technotes/guides/security/StandardNames.html#Mac">
 166      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 167      * for information about standard algorithm names.
 168      *
 169      * @return the new {@code Mac} object
 170      *
 171      * @throws NoSuchAlgorithmException if no {@code Provider} supports a
 172      *         {@code MacSpi} implementation for the specified algorithm
 173      *
 174      * @throws NullPointerException if {@code algorithm} is {@code null}
 175      *
 176      * @see java.security.Provider
 177      */
 178     public static final Mac getInstance(String algorithm)
 179             throws NoSuchAlgorithmException {
 180         List<Service> services = GetInstance.getServices("Mac", algorithm);
 181         // make sure there is at least one service from a signed provider
 182         Iterator<Service> t = services.iterator();
 183         while (t.hasNext()) {
 184             Service s = t.next();
 185             if (JceSecurity.canUseProvider(s.getProvider()) == false) {
 186                 continue;
 187             }
 188             return new Mac(s, t, algorithm);
 189         }
 190         throw new NoSuchAlgorithmException
 191                                 ("Algorithm " + algorithm + " not available");
 192     }
 193 
 194     /**
 195      * Returns a {@code Mac} object that implements the
 196      * specified MAC algorithm.
 197      *
 198      * <p> A new Mac object encapsulating the
 199      * MacSpi implementation from the specified provider
 200      * is returned.  The specified provider must be registered
 201      * in the security provider list.
 202      *
 203      * <p> Note that the list of registered providers may be retrieved via
 204      * the {@link Security#getProviders() Security.getProviders()} method.
 205      *
 206      * @param algorithm the standard name of the requested MAC algorithm.
 207      * See the Mac section in the <a href=
 208      *   "{@docRoot}/../technotes/guides/security/StandardNames.html#Mac">
 209      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 210      * for information about standard algorithm names.
 211      *
 212      * @param provider the name of the provider.
 213      *
 214      * @return the new {@code Mac} object
 215      *
 216      * @throws IllegalArgumentException if the {@code provider}
 217      *         is {@code null} or empty
 218      *
 219      * @throws NoSuchAlgorithmException if a {@code MacSpi}
 220      *         implementation for the specified algorithm is not
 221      *         available from the specified provider
 222      *
 223      * @throws NoSuchProviderException if the specified provider is not
 224      *         registered in the security provider list
 225      *
 226      * @throws NullPointerException if {@code algorithm} is {@code null}

 227      *
 228      * @see java.security.Provider
 229      */
 230     public static final Mac getInstance(String algorithm, String provider)
 231             throws NoSuchAlgorithmException, NoSuchProviderException {
 232         Instance instance = JceSecurity.getInstance
 233                 ("Mac", MacSpi.class, algorithm, provider);
 234         return new Mac((MacSpi)instance.impl, instance.provider, algorithm);
 235     }
 236 
 237     /**
 238      * Returns a {@code Mac} object that implements the
 239      * specified MAC algorithm.
 240      *
 241      * <p> A new Mac object encapsulating the
 242      * MacSpi implementation from the specified Provider
 243      * object is returned.  Note that the specified Provider object
 244      * does not have to be registered in the provider list.
 245      *
 246      * @param algorithm the standard name of the requested MAC algorithm.
 247      * See the Mac section in the <a href=
 248      *   "{@docRoot}/../technotes/guides/security/StandardNames.html#Mac">
 249      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 250      * for information about standard algorithm names.
 251      *
 252      * @param provider the provider.
 253      *
 254      * @return the new {@code Mac} object
 255      *
 256      * @throws IllegalArgumentException if the {@code provider} is
 257      *         {@code null}
 258      *
 259      * @throws NoSuchAlgorithmException if a {@code MacSpi}
 260      *         implementation for the specified algorithm is not available
 261      *         from the specified {@code Provider} object
 262      *
 263      * @throws NullPointerException if {@code algorithm} is {@code null}

 264      *
 265      * @see java.security.Provider
 266      */
 267     public static final Mac getInstance(String algorithm, Provider provider)
 268             throws NoSuchAlgorithmException {
 269         Instance instance = JceSecurity.getInstance
 270                 ("Mac", MacSpi.class, algorithm, provider);
 271         return new Mac((MacSpi)instance.impl, instance.provider, algorithm);
 272     }
 273 
 274     // max number of debug warnings to print from chooseFirstProvider()
 275     private static int warnCount = 10;
 276 
 277     /**
 278      * Choose the Spi from the first provider available. Used if
 279      * delayed provider selection is not possible because init()
 280      * is not the first method called.
 281      */
 282     void chooseFirstProvider() {
 283         if ((spi != null) || (serviceIterator == null)) {


< prev index next >