FileDocCategorySizeDatePackage
AlgNameMapper.javaAPI DocAndroid 1.5 API9551Wed May 06 22:41:06 BST 2009org.apache.harmony.security.utils

AlgNameMapper

public class AlgNameMapper extends Object
Provides Algorithm Name to OID and OID to Algorithm Name mappings. Some known mappings are hardcoded. Tries to obtain additional mappings from installed providers during initialization. Hardcoded mappings (source: http://asn1.elibel.tm.fr): 1.2.840.10040.4.1 -> DSA 1.2.840.113549.1.1.1 -> RSA 1.2.840.113549.1.3.1 -> DiffieHellman 1.2.840.113549.1.5.3 -> PBEWithMD5AndDES 1.2.840.113549.1.12.1.3 -> pbeWithSHAAnd3-KeyTripleDES-CBC 1.2.840.113549.1.12.1.3 -> PBEWithSHA1AndDESede 1.2.840.113549.1.12.1.3 -> PBEWithSHA1AndTripleDES 1.2.840.113549.1.12.1.6 -> pbeWithSHAAnd40BitRC2-CBC 1.2.840.113549.1.12.1.6 -> PBEWithSHA1AndRC2_40 1.2.840.113549.3.2 -> RC2-CBC 1.2.840.113549.3.3 -> RC2-EBC 1.2.840.113549.3.4 -> RC4 1.2.840.113549.3.5 -> RC4WithMAC 1.2.840.113549.3.6 -> DESx-CBC 1.2.840.113549.3.7 -> TripleDES-CBC 1.2.840.113549.3.8 -> rc5CBC 1.2.840.113549.3.9 -> RC5-CBC 1.2.840.113549.3.10 -> DESCDMF (CDMFCBCPad)

Fields Summary
private static final String[]
serviceName
private static final String[]
knownAlgMappings
private static final Map
alg2OidMap
private static final Map
oid2AlgMap
private static final Map
algAliasesMap
Constructors Summary
private AlgNameMapper()


     
        for (String[] element : knownAlgMappings) {
            String algUC = element[1].toUpperCase();
            alg2OidMap.put(algUC, element[0]);
            oid2AlgMap.put(element[0], algUC);
            // map upper case alg name to its original name
            algAliasesMap.put(algUC, element[1]);
        }
        //
        // Now search providers for mappings like
        // Alg.Alias.<service>.<OID-INTS-DOT-SEPARATED>=<alg-name>
        //  or
        // Alg.Alias.<service>.OID.<OID-INTS-DOT-SEPARATED>=<alg-name>
        //
        Provider[] pl = Security.getProviders();
        for (Provider element : pl) {
            selectEntries(element);
        }
    
    
Methods Summary
public static java.lang.Stringdump()
Present all internal maps as formatted string

return
Internal maps String representation

        StringBuffer sb = new StringBuffer("alg2OidMap: "); //$NON-NLS-1$
        sb.append(alg2OidMap);
        sb.append("\noid2AlgMap: "); //$NON-NLS-1$
        sb.append(oid2AlgMap);
        sb.append("\nalgAliasesMap: "); //$NON-NLS-1$
        sb.append(algAliasesMap);
        return sb.toString();
    
public static java.lang.StringgetStandardName(java.lang.String algName)
Returns Algorithm name for given algorithm alias

param
algName - alias
return
algorithm name

        return algAliasesMap.get(algName.toUpperCase());
    
public static booleanisOID(java.lang.String alias)
Checks if parameter represents OID

param
alias alias to be checked
return
'true' if parameter represents OID

        // BEGIN android-changed
        return ObjectIdentifier.isOID(normalize(alias));
        // END android-changed
    
public static java.lang.Stringmap2AlgName(java.lang.String oid)
Returns algName for OID

param
oid OID to be mapped
return
algorithm name

        // oid2AlgMap map contains upper case values
        String algUC = oid2AlgMap.get(oid);
        // if not null there is always map UC->Orig
        return algUC == null ? null : algAliasesMap.get(algUC);
    
public static java.lang.Stringmap2OID(java.lang.String algName)
Returns OID for algName

param
algName algorithm name to be mapped
return
OID as String

        // alg2OidMap map contains upper case keys
        return alg2OidMap.get(algName.toUpperCase());
    
public static java.lang.Stringnormalize(java.lang.String oid)
Removes leading "OID." from oid String passed

param
oid string that may contain leading "OID."
return
string passed without leading "OID."

        return oid.startsWith("OID.") //$NON-NLS-1$
            ? oid.substring(4)
            : oid;
    
private static voidselectEntries(java.security.Provider p)

        Set<Map.Entry<Object, Object>> entrySet = p.entrySet();
        for (String service : serviceName) {
            String keyPrfix2find = "Alg.Alias." + service + ".";  //$NON-NLS-1$ //$NON-NLS-2$
            for (Entry<Object, Object> me : entrySet) {
                String key = (String)me.getKey();
                if (key.startsWith(keyPrfix2find)) {
                    String alias = key.substring(keyPrfix2find.length());
                    String alg = (String)me.getValue();
                    String algUC = alg.toUpperCase();
                    if (isOID(alias)) {
                        if (alias.startsWith("OID.")) { //$NON-NLS-1$
                            alias = alias.substring(4);
                        }
                        // Do not overwrite already known mappings
                        boolean oid2AlgContains = oid2AlgMap.containsKey(alias);
                        boolean alg2OidContains = alg2OidMap.containsKey(algUC);
                        if (!oid2AlgContains || !alg2OidContains) {
                            if (!oid2AlgContains) {
                                oid2AlgMap.put(alias, algUC);
                            } 
                            if (!alg2OidContains) {
                                alg2OidMap.put(algUC, alias);
                            }
                            // map upper case alg name to its original name
                            algAliasesMap.put(algUC, alg);
                        }
                           // Do not override known standard names
                    } else if (!algAliasesMap.containsKey(alias.toUpperCase())) {
                        algAliasesMap.put(alias.toUpperCase(), alg);
                    }
                }
            }
        }