8323624: ProviderList.ServiceList does not need to be a list

Reviewed-by: mullan
This commit is contained in:
Weijun Wang 2024-03-29 15:23:26 +00:00
parent 418deaf5a1
commit 59c2aff1ed
12 changed files with 70 additions and 131 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -539,10 +539,9 @@ public class Cipher {
for (Transform transform : transforms) {
cipherServices.add(new ServiceId("Cipher", transform.transform));
}
List<Service> services = GetInstance.getServices(cipherServices);
// make sure there is at least one service from a signed provider
// and that it can use the specified mode and padding
Iterator<Service> t = services.iterator();
Iterator<Service> t = GetInstance.getServices(cipherServices);
Exception failure = null;
while (t.hasNext()) {
Service s = t.next();

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -154,9 +154,10 @@ final class JceSecurity {
static Instance getInstance(String type, Class<?> clazz, String algorithm)
throws NoSuchAlgorithmException {
List<Service> services = GetInstance.getServices(type, algorithm);
Iterator<Service> t = GetInstance.getServices(type, algorithm);
NoSuchAlgorithmException failure = null;
for (Service s : services) {
while (t.hasNext()) {
Service s = t.next();
if (canUseProvider(s.getProvider()) == false) {
// allow only signed providers
continue;

View file

@ -30,6 +30,7 @@ import java.security.*;
import java.security.InvalidAlgorithmParameterException;
import java.security.spec.AlgorithmParameterSpec;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
@ -537,11 +538,12 @@ public final class KEM {
*/
public static KEM getInstance(String algorithm)
throws NoSuchAlgorithmException {
List<Provider.Service> list = GetInstance.getServices(
Iterator<Provider.Service> t = GetInstance.getServices(
"KEM",
Objects.requireNonNull(algorithm, "null algorithm name"));
List<Provider.Service> allowed = new ArrayList<>();
for (Provider.Service s : list) {
while (t.hasNext()) {
Provider.Service s = t.next();
if (!JceSecurity.canUseProvider(s.getProvider())) {
continue;
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -180,10 +180,8 @@ public class KeyAgreement {
public static final KeyAgreement getInstance(String algorithm)
throws NoSuchAlgorithmException {
Objects.requireNonNull(algorithm, "null algorithm name");
List<Service> services =
GetInstance.getServices("KeyAgreement", algorithm);
// make sure there is at least one service from a signed provider
Iterator<Service> t = services.iterator();
Iterator<Service> t = GetInstance.getServices("KeyAgreement", algorithm);
while (t.hasNext()) {
Service s = t.next();
if (!JceSecurity.canUseProvider(s.getProvider())) {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -167,9 +167,7 @@ public class KeyGenerator {
private KeyGenerator(String algorithm) throws NoSuchAlgorithmException {
this.algorithm = algorithm;
List<Service> list =
GetInstance.getServices("KeyGenerator", algorithm);
serviceIterator = list.iterator();
serviceIterator = GetInstance.getServices("KeyGenerator", algorithm);
initType = I_NONE;
// fetch and instantiate initial spi
if (nextSpi(null, false) == null) {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -177,9 +177,8 @@ public class Mac implements Cloneable {
public static final Mac getInstance(String algorithm)
throws NoSuchAlgorithmException {
Objects.requireNonNull(algorithm, "null algorithm name");
List<Service> services = GetInstance.getServices("Mac", algorithm);
// make sure there is at least one service from a signed provider
Iterator<Service> t = services.iterator();
Iterator<Service> t = GetInstance.getServices("Mac", algorithm);
while (t.hasNext()) {
Service s = t.next();
if (!JceSecurity.canUseProvider(s.getProvider())) {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -110,9 +110,7 @@ public class SecretKeyFactory {
private SecretKeyFactory(String algorithm) throws NoSuchAlgorithmException {
this.algorithm = algorithm;
List<Service> list =
GetInstance.getServices("SecretKeyFactory", algorithm);
serviceIterator = list.iterator();
serviceIterator = GetInstance.getServices("SecretKeyFactory", algorithm);
// fetch and instantiate initial spi
if (nextSpi(null) == null) {
throw new NoSuchAlgorithmException