On Mon, 2006-07-10 at 13:45 -0700, Casey Marshall wrote:
> On Jul 10, 2006, at 12:16 PM, Matthew Wringe wrote:
>
> > On Mon, 2006-07-10 at 10:08 -0600, Tom Tromey wrote:
> >>>>>>> "Matthew" == Matthew Wringe <[EMAIL PROTECTED]> writes:
> >>
> >> Matthew> If this patch is approved, I can commit it.
> >>
> >> Matthew> - // If there is no property "service.algorithm"
> >> Matthew> - if (provider.getProperty(service + "." + algorithm)
> >> == null)
> >>
> >> There's something here I don't understand.
> >>
> >> Looking at java.security.Provider, I see that it tries to
> >> canonicalize the keys -- see toCanonicalKey().
> >>
> >> Would just changing this to use get() fix the problem?
> >> Or perhaps it would be better to override getProperty in Provider?
> >
> > Changing it to get() does fix the problem if the user only ever
> > uses the
> > classpath provider. If they were to use any other provider, it will
> > fail.
> >
> > The classpath provider overwrites the hashtable's get() method to
> > ignore
> > the case (I have no idea why this is being done). Other providers
> > do not
> > do this, nor is it expected behaviour.
> >
> > The original patch I submitted does interact with other providers
> > without a problem.
> >
>
> I think putting the case-insensitive logic in Engine is best; it will
> work for providers that don't just use `put,' like you say, and with
> it we can do away with toCanonicalKey in Provider, which I don't like
> very much (it makes every key upper case, which is an ugly way to do
> it).
>
> I think your approach (and patch) is good, and that we should
> additionally remove toCanonicalKey.
>
I have attached two patches. One patch added case-insensitivity to
algorithm names in java.security.engine. The other patch removes the
toCanonicalKey from java.security.Provider.
If there are no objections to these patches, I would like to commit
them.
Thanks, and sorry for the long delay in replying
Matt Wringe
Changelog:
2006-07-28 Matt Wringe <[EMAIL PROTECTED]>
* gnu/java/security/Engine.java
(getInstance): Add case insentivity to algorithm names
* java/security/Provider.java
(put): Stop using canonical key naming
(remove): Likewise
(toCanonicalKey): Method removed
(get): Method removed, no longer needs to overwrite
parent implementation
Index: Engine.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/java/security/Engine.java,v
retrieving revision 1.3
diff -u -r1.3 Engine.java
--- Engine.java 1 Jan 2006 14:03:45 -0000 1.3
+++ Engine.java 28 Jul 2006 15:59:36 -0000
@@ -42,6 +42,7 @@
import java.security.NoSuchAlgorithmException;
import java.security.Provider;
+import java.util.Enumeration;
/**
* Generic implementation of the getInstance methods in the various
@@ -141,26 +142,46 @@
|| provider == null || initArgs == null)
throw new IllegalArgumentException();
- // If there is no property "service.algorithm"
- if (provider.getProperty(service + "." + algorithm) == null)
+
+ Enumeration enumer = provider.propertyNames();
+ String key;
+ String alias;
+ int count = 0;
+ boolean algorithmFound = false;
+
+ while (enumer.hasMoreElements())
{
- // Iterate through aliases, until we find the class name or resolve
- // too many aliases.
- String alias = null;
- int count = 0;
- while ((alias = provider.getProperty(
- ALG_ALIAS + service + "." + algorithm)) != null)
+ key = (String) enumer.nextElement();
+
+ if (key.equalsIgnoreCase(service + "." + algorithm))
+ {
+ // remove the service portion from the key
+ algorithm = key.substring(service.length() + 1);
+
+ algorithmFound = true;
+ break;
+
+ }
+ else if (key.equalsIgnoreCase(ALG_ALIAS + service + "." + algorithm))
{
- if (algorithm.equals(alias)) // Refers to itself!
- break;
+
+ alias = (String) provider.getProperty(key);
algorithm = alias;
if (count++ > MAX_ALIASES)
throw new NoSuchAlgorithmException("too many aliases");
+
+ // need to reset enumeration to now look for the alias
+ enumer = provider.propertyNames();
+
}
- if (provider.getProperty(service + "." + algorithm) == null)
- throw new NoSuchAlgorithmException(algorithm);
}
-
+
+ if (! algorithmFound)
+ {
+ throw new NoSuchAlgorithmException(algorithm);
+ }
+
+
// Find and instantiate the implementation.
Class clazz = null;
ClassLoader loader = provider.getClass().getClassLoader();
Index: Provider.java
===================================================================
RCS file: /sources/classpath/classpath/java/security/Provider.java,v
retrieving revision 1.11
diff -u -r1.11 Provider.java
--- Provider.java 2 Jul 2005 20:32:40 -0000 1.11
+++ Provider.java 28 Jul 2006 18:02:45 -0000
@@ -146,15 +146,9 @@
*/
public Object put(Object key, Object value)
{
- return super.put(toCanonicalKey(key), value);
+ return super.put(key, value);
}
- // overrides same in java.util.Hashtable
- public Object get(Object key)
- {
- return super.get(toCanonicalKey(key));
- }
-
/**
* This method removes the specified key entry (and its associated value)
* from the property mapping list.
@@ -166,7 +160,7 @@
*/
public Object remove(Object key)
{
- return super.remove(toCanonicalKey(key));
+ return super.remove(key);
}
/**
@@ -192,11 +186,4 @@
version);
}
- private Object toCanonicalKey(Object key)
- {
- if (key.getClass().isAssignableFrom(String.class)) // is it ours?
- return ((String) key).toUpperCase(); // use default locale
- else
- return key;
- }
}