Search in sources :

Example 1 with MetaKeyGenerator

use of org.jcryptool.crypto.flexiprovider.descriptors.meta.MetaKeyGenerator in project core by jcryptool.

the class FlexiProviderRootElement method initKeyGenerators.

@SuppressWarnings("unchecked")
private static void initKeyGenerators(RegistryType type, Element keyGeneratorParent) {
    List<Element> keyGeneratorChildren = new ArrayList<Element>(keyGeneratorParent.getChildren());
    Iterator<Element> it = keyGeneratorChildren.iterator();
    while (it.hasNext()) {
        Element current = it.next();
        String className = current.getAttributeValue(AlgorithmsXMLConstants._class);
        IMetaKeyGenerator meta = new MetaKeyGenerator(className);
        // oid
        IMetaOID oid = null;
        if (current.getAttributeValue(AlgorithmsXMLConstants._oid) != null) {
            oid = new MetaOID(current.getAttributeValue(AlgorithmsXMLConstants._oid));
            meta.setOID(oid);
        }
        // names
        List<String> names = new ArrayList<String>();
        if (current.getChild(AlgorithmsXMLConstants._Names) != null) {
            if (current.getChild(AlgorithmsXMLConstants._Names).getText().contains(",")) {
                // $NON-NLS-1$
                StringTokenizer tokenizer = // $NON-NLS-1$
                new StringTokenizer(current.getChild(AlgorithmsXMLConstants._Names).getText(), ",");
                while (tokenizer.hasMoreTokens()) {
                    names.add(tokenizer.nextToken());
                }
            } else {
                names.add(current.getChild(AlgorithmsXMLConstants._Names).getText());
            }
        }
        meta.setNames(names);
        // parameter spec
        if (current.getChild(AlgorithmsXMLConstants._ParameterSpec) != null) {
            meta.setParameterSpecClassName(current.getChild(AlgorithmsXMLConstants._ParameterSpec).getAttributeValue(AlgorithmsXMLConstants._class));
        }
        // parameter generators
        if (current.getChild(AlgorithmsXMLConstants._ParameterGenerator) != null) {
            meta.setParameterGeneratorClassName(current.getChild(AlgorithmsXMLConstants._ParameterGenerator).getAttributeValue(AlgorithmsXMLConstants._class));
            meta.setParamGenParameterSpecClassName(current.getChild(AlgorithmsXMLConstants._ParameterGenerator).getChild(AlgorithmsXMLConstants._ParameterSpec).getAttributeValue(AlgorithmsXMLConstants._class));
        }
        // lengths
        if (current.getChild(AlgorithmsXMLConstants._KeyStrengths) != null) {
            int defaultLength = Integer.valueOf(current.getChild(AlgorithmsXMLConstants._KeyStrengths).getAttributeValue(AlgorithmsXMLConstants._default));
            IMetaLength metaLength = new MetaLength(defaultLength);
            if (current.getChild(AlgorithmsXMLConstants._KeyStrengths).getText() != null) {
                String text = current.getChild(AlgorithmsXMLConstants._KeyStrengths).getText();
                if (text.contains(",")) {
                    // $NON-NLS-1$
                    List<Integer> lengths = new ArrayList<Integer>(2);
                    // $NON-NLS-1$
                    StringTokenizer tokenizer = new StringTokenizer(text, ",");
                    while (tokenizer.hasMoreTokens()) {
                        lengths.add(Integer.valueOf(tokenizer.nextToken()));
                    }
                    metaLength.setLengths(lengths);
                } else if (text.contains("...")) {
                    // $NON-NLS-1$
                    // $NON-NLS-1$
                    int lowerBound = Integer.valueOf(text.substring(0, text.indexOf("...")));
                    // $NON-NLS-1$
                    int upperBound = Integer.valueOf(text.substring(text.indexOf("...") + 3, text.length()));
                    metaLength.setBounds(lowerBound, upperBound);
                }
            }
            meta.setLengths(metaLength);
        }
        add(type, meta);
    }
}
Also used : IMetaOID(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaOID) MetaLength(org.jcryptool.crypto.flexiprovider.descriptors.meta.MetaLength) IMetaLength(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaLength) Element(org.jdom.Element) MetaKeyGenerator(org.jcryptool.crypto.flexiprovider.descriptors.meta.MetaKeyGenerator) IMetaKeyGenerator(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaKeyGenerator) ArrayList(java.util.ArrayList) IMetaKeyGenerator(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaKeyGenerator) MetaOID(org.jcryptool.crypto.flexiprovider.descriptors.meta.MetaOID) IMetaOID(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaOID) IMetaLength(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaLength) StringTokenizer(java.util.StringTokenizer)

Aggregations

ArrayList (java.util.ArrayList)1 StringTokenizer (java.util.StringTokenizer)1 MetaKeyGenerator (org.jcryptool.crypto.flexiprovider.descriptors.meta.MetaKeyGenerator)1 MetaLength (org.jcryptool.crypto.flexiprovider.descriptors.meta.MetaLength)1 MetaOID (org.jcryptool.crypto.flexiprovider.descriptors.meta.MetaOID)1 IMetaKeyGenerator (org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaKeyGenerator)1 IMetaLength (org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaLength)1 IMetaOID (org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaOID)1 Element (org.jdom.Element)1