Search in sources :

Example 1 with MetaAlgorithm

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

the class FlexiProviderRootElement method initSecretKeyAlgorithms.

@SuppressWarnings("unchecked")
private static void initSecretKeyAlgorithms(RegistryType type, Element secretKeyAlgorithmParent) {
    List<Element> cipherChildren = new ArrayList<Element>(secretKeyAlgorithmParent.getChildren());
    Iterator<Element> it = cipherChildren.iterator();
    while (it.hasNext()) {
        Element current = it.next();
        // replace element with blockCipherElement
        String className = current.getAttributeValue(AlgorithmsXMLConstants._class);
        IMetaOID oid = null;
        if (current.getAttributeValue(AlgorithmsXMLConstants._oid) != null) {
            oid = new MetaOID(current.getAttributeValue(AlgorithmsXMLConstants._oid));
        }
        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());
            }
        }
        IMetaAlgorithm meta = new MetaAlgorithm(type, oid, names, className);
        // parameter specs
        if (current.getChild(AlgorithmsXMLConstants._ParameterSpec) != null) {
            meta.setParameterSpecClassName(current.getChild(AlgorithmsXMLConstants._ParameterSpec).getAttributeValue(AlgorithmsXMLConstants._class));
            if (current.getChild(AlgorithmsXMLConstants._ParameterSpec).getAttribute(AlgorithmsXMLConstants._disabled) == null) {
                meta.setParameterSpecDisabled(true);
            }
        }
        // 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));
        }
        if (current.getChild(AlgorithmsXMLConstants._BlockLengths) != null) {
            meta.setDefaultBlockLength(Integer.valueOf(current.getChild(AlgorithmsXMLConstants._BlockLengths).getAttributeValue(AlgorithmsXMLConstants._default)));
            if (current.getChild(AlgorithmsXMLConstants._BlockLengths).getText() != null) {
                List<Integer> blockLengths = new ArrayList<Integer>(0);
                StringTokenizer tokenizer = // $NON-NLS-1$
                new StringTokenizer(current.getChild(AlgorithmsXMLConstants._BlockLengths).getText(), ",");
                while (tokenizer.hasMoreTokens()) {
                    blockLengths.add(Integer.valueOf(tokenizer.nextToken()));
                }
                meta.setBlockLengths(blockLengths);
            }
        }
        if (current.getChild(AlgorithmsXMLConstants._StandardParameters) != null) {
            StringTokenizer standardParams = // $NON-NLS-1$
            new StringTokenizer(current.getChildText(AlgorithmsXMLConstants._StandardParameters), ",");
            while (standardParams.hasMoreTokens()) {
                meta.addStandardParams(standardParams.nextToken());
            }
        }
        if (type.equals(RegistryType.MAC)) {
            if (current.getChild(AlgorithmsXMLConstants._BlockCipherReference) != null) {
                meta.setBlockCipherName(current.getChild(AlgorithmsXMLConstants._BlockCipherReference).getAttributeValue(AlgorithmsXMLConstants._name));
                if (current.getChild(AlgorithmsXMLConstants._BlockCipherReference).getAttributeValue(AlgorithmsXMLConstants._oid) != null) {
                    meta.setBlockCipherOID(new MetaOID(current.getChild(AlgorithmsXMLConstants._BlockCipherReference).getAttributeValue(AlgorithmsXMLConstants._oid)));
                }
                meta.setBlockCipherMode(current.getChild(AlgorithmsXMLConstants._BlockCipherReference).getAttributeValue(AlgorithmsXMLConstants._mode));
            }
        }
        if (current.getAttribute(AlgorithmsXMLConstants._disabled) == null) {
            add(type, meta);
        }
    }
}
Also used : IMetaOID(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaOID) Element(org.jdom.Element) ArrayList(java.util.ArrayList) MetaOID(org.jcryptool.crypto.flexiprovider.descriptors.meta.MetaOID) IMetaOID(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaOID) StringTokenizer(java.util.StringTokenizer) IMetaAlgorithm(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaAlgorithm) IMetaAlgorithm(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaAlgorithm) MetaAlgorithm(org.jcryptool.crypto.flexiprovider.descriptors.meta.MetaAlgorithm)

Example 2 with MetaAlgorithm

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

the class FlexiProviderRootElement method initAlgorithms.

@SuppressWarnings("unchecked")
private static void initAlgorithms(RegistryType type, Element algorithmParent) {
    List<Element> messageDigestChildren = new ArrayList<Element>(algorithmParent.getChildren());
    Iterator<Element> it = messageDigestChildren.iterator();
    while (it.hasNext()) {
        Element current = it.next();
        // replace element with blockCipherElement
        String className = current.getAttributeValue(AlgorithmsXMLConstants._class);
        IMetaOID oid = null;
        if (current.getAttributeValue(AlgorithmsXMLConstants._oid) != null) {
            oid = new MetaOID(current.getAttributeValue(AlgorithmsXMLConstants._oid));
        }
        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());
            }
        }
        IMetaAlgorithm meta = new MetaAlgorithm(type, oid, names, className);
        // // parameter specs
        if (current.getChild(AlgorithmsXMLConstants._ParameterSpec) != null) {
            meta.setParameterSpecClassName(current.getChild(AlgorithmsXMLConstants._ParameterSpec).getAttributeValue(AlgorithmsXMLConstants._class));
            if (current.getChild(AlgorithmsXMLConstants._ParameterSpec).getAttribute(AlgorithmsXMLConstants._disabled) == null) {
                meta.setParameterSpecDisabled(true);
            }
        }
        // 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));
        }
        if (current.getChild(AlgorithmsXMLConstants._StandardParameters) != null) {
            StringTokenizer standardParams = // $NON-NLS-1$
            new StringTokenizer(current.getChildText(AlgorithmsXMLConstants._StandardParameters), ",");
            while (standardParams.hasMoreTokens()) {
                meta.addStandardParams(standardParams.nextToken());
            }
        }
        if (current.getAttribute(AlgorithmsXMLConstants._disabled) == null) {
            add(type, meta);
        }
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) IMetaOID(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaOID) IMetaAlgorithm(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaAlgorithm) Element(org.jdom.Element) ArrayList(java.util.ArrayList) MetaOID(org.jcryptool.crypto.flexiprovider.descriptors.meta.MetaOID) IMetaOID(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaOID) IMetaAlgorithm(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaAlgorithm) MetaAlgorithm(org.jcryptool.crypto.flexiprovider.descriptors.meta.MetaAlgorithm)

Example 3 with MetaAlgorithm

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

the class FlexiProviderRootElement method initKeyPairAlgorithms.

@SuppressWarnings("unchecked")
private static void initKeyPairAlgorithms(RegistryType type, Element keyPairAlgorithmParent) {
    List<Element> signatureChildren = new ArrayList<Element>(keyPairAlgorithmParent.getChildren());
    Iterator<Element> it = signatureChildren.iterator();
    while (it.hasNext()) {
        Element current = it.next();
        String className = current.getAttributeValue(AlgorithmsXMLConstants._class);
        IMetaOID oid = null;
        if (current.getAttributeValue(AlgorithmsXMLConstants._oid) != null) {
            oid = new MetaOID(current.getAttributeValue(AlgorithmsXMLConstants._oid));
        }
        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());
            }
        }
        IMetaAlgorithm meta = new MetaAlgorithm(type, oid, names, className);
        // parameter specs
        if (current.getChild(AlgorithmsXMLConstants._ParameterSpec) != null) {
            meta.setParameterSpecClassName(current.getChild(AlgorithmsXMLConstants._ParameterSpec).getAttributeValue(AlgorithmsXMLConstants._class));
            if (current.getChild(AlgorithmsXMLConstants._ParameterSpec).getAttribute(AlgorithmsXMLConstants._disabled) == null) {
                meta.setParameterSpecDisabled(true);
            }
        }
        // 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));
        }
        if (current.getChild(AlgorithmsXMLConstants._StandardParameters) != null) {
            StringTokenizer standardParams = // $NON-NLS-1$
            new StringTokenizer(current.getChildText(AlgorithmsXMLConstants._StandardParameters), ",");
            while (standardParams.hasMoreTokens()) {
                meta.addStandardParams(standardParams.nextToken());
            }
        }
        if (current.getAttribute(AlgorithmsXMLConstants._disabled) == null) {
            add(type, meta);
        }
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) IMetaOID(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaOID) IMetaAlgorithm(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaAlgorithm) Element(org.jdom.Element) ArrayList(java.util.ArrayList) MetaOID(org.jcryptool.crypto.flexiprovider.descriptors.meta.MetaOID) IMetaOID(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaOID) IMetaAlgorithm(org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaAlgorithm) MetaAlgorithm(org.jcryptool.crypto.flexiprovider.descriptors.meta.MetaAlgorithm)

Aggregations

ArrayList (java.util.ArrayList)3 StringTokenizer (java.util.StringTokenizer)3 MetaAlgorithm (org.jcryptool.crypto.flexiprovider.descriptors.meta.MetaAlgorithm)3 MetaOID (org.jcryptool.crypto.flexiprovider.descriptors.meta.MetaOID)3 IMetaAlgorithm (org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaAlgorithm)3 IMetaOID (org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaOID)3 Element (org.jdom.Element)3