Security.java (loadProviders): Removed unused `pname' variable.

* java/security/Security.java (loadProviders): Removed unused
	`pname' variable.  Don't create `File' object.  Don't update
	`providerCount'.
	(providerCount): Removed.
	(insertProviderAt): Don't use `providerCount'.
	(addProvider(Provider,int)): Likewise.
	(removeProvider): Likewise.
	(addProvider(Provider)): Rewrote.
	(getProviders): Rewrote.
	(getProvider): Don't use `providerCount'.

From-SVN: r46332
This commit is contained in:
Tom Tromey 2001-10-18 17:51:47 +00:00 committed by Tom Tromey
parent bf911a9a73
commit c586d12794
2 changed files with 27 additions and 38 deletions

View file

@ -1,3 +1,16 @@
2001-10-18 Tom Tromey <tromey@redhat.com>
* java/security/Security.java (loadProviders): Removed unused
`pname' variable. Don't create `File' object. Don't update
`providerCount'.
(providerCount): Removed.
(insertProviderAt): Don't use `providerCount'.
(addProvider(Provider,int)): Likewise.
(removeProvider): Likewise.
(addProvider(Provider)): Rewrote.
(getProviders): Rewrote.
(getProvider): Don't use `providerCount'.
2001-10-17 Tom Tromey <tromey@redhat.com> 2001-10-17 Tom Tromey <tromey@redhat.com>
* gnu/java/security/provider/SHA1PRNG.java (engineNextBytes): * gnu/java/security/provider/SHA1PRNG.java (engineNextBytes):

View file

@ -44,7 +44,6 @@ import java.util.Properties;
public final class Security extends Object public final class Security extends Object
{ {
private static Vector providers = new Vector(); private static Vector providers = new Vector();
private static int providerCount = 0;
private static Properties secprops; private static Properties secprops;
static static
@ -69,17 +68,14 @@ public final class Security extends Object
separator + "security" + separator + "security" +
separator + vendor + ".security"); separator + vendor + ".security");
providerCount = 0;
try try
{ {
File secFile = new File(secfilestr); FileInputStream fin = new FileInputStream(secfilestr);
FileInputStream fin = new FileInputStream(secFile);
secprops = new Properties(); secprops = new Properties();
secprops.load(fin); secprops.load(fin);
int i = 1; int i = 1;
String name; String name;
StringBuffer pname = new StringBuffer("security.provider.");
while ((name = secprops.getProperty("security.provider." + i++)) != while ((name = secprops.getProperty("security.provider." + i++)) !=
null) null)
@ -89,7 +85,6 @@ public final class Security extends Object
try try
{ {
providers.addElement(Class.forName(name).newInstance()); providers.addElement(Class.forName(name).newInstance());
providerCount++;
i++; i++;
} }
catch (ClassNotFoundException x) catch (ClassNotFoundException x)
@ -162,7 +157,8 @@ public final class Security extends Object
if (sm != null) if (sm != null)
sm.checkSecurityAccess("insertProvider." + provider.getName()); sm.checkSecurityAccess("insertProvider." + provider.getName());
for (int i = 0; i < providerCount; i++) int max = providers.size ();
for (int i = 0; i < max; i++)
{ {
if (((Provider) providers.elementAt(i)).getName() == if (((Provider) providers.elementAt(i)).getName() ==
provider.getName()) provider.getName())
@ -170,12 +166,11 @@ public final class Security extends Object
} }
if (position < 0) if (position < 0)
position = 0; position = 0;
if (position > providerCount) if (position > max)
position = providerCount; position = max;
providers.insertElementAt(provider, position); providers.insertElementAt(provider, position);
providerCount++;
return position; return position;
} }
@ -199,22 +194,7 @@ public final class Security extends Object
*/ */
public static int addProvider(Provider provider) public static int addProvider(Provider provider)
{ {
SecurityManager sm = System.getSecurityManager(); return insertProviderAt (provider, providers.size ());
if (sm != null)
sm.checkSecurityAccess("insertProvider." + provider.getName());
for (int i = 0; i < providerCount; i++)
{
if (((Provider) providers.elementAt(i)).getName() ==
provider.getName())
return -1;
}
providers.addElement(provider);
providerCount++;
return providerCount - 1;
} }
/** /**
@ -238,19 +218,15 @@ public final class Security extends Object
sm.checkSecurityAccess("removeProvider." + name); sm.checkSecurityAccess("removeProvider." + name);
Provider p = null; Provider p = null;
for (int i = 0; i < providerCount; i++) int max = providers.size ();
for (int i = 0; i < max; i++)
{ {
if (((Provider) providers.elementAt(i)).getName() == name) if (((Provider) providers.elementAt(i)).getName() == name)
{ {
p = (Provider) providers.elementAt(i); providers.remove(i);
break; break;
} }
} }
if (p != null)
if (providers.removeElement(p))
providerCount--;
} }
/** /**
@ -261,9 +237,8 @@ public final class Security extends Object
*/ */
public static Provider[] getProviders() public static Provider[] getProviders()
{ {
Provider array[] = new Provider[providerCount]; Provider array[] = new Provider[providers.size ()];
for (int i = 0; i < providerCount; i++) providers.copyInto (array);
array[i] = (Provider) providers.elementAt(i);
return array; return array;
} }
@ -278,7 +253,8 @@ public final class Security extends Object
public static Provider getProvider(String name) public static Provider getProvider(String name)
{ {
Provider p = null; Provider p = null;
for (int i = 0; i < providerCount; i++) int max = providers.size ();
for (int i = 0; i < max; i++)
{ {
p = (Provider) providers.elementAt(i); p = (Provider) providers.elementAt(i);
if (p.getName() == name) if (p.getName() == name)