Search in sources :

Example 1 with IMetaOID

use of org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaOID 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)

Example 2 with IMetaOID

use of org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaOID 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 3 with IMetaOID

use of org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaOID 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 4 with IMetaOID

use of org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaOID 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)4 StringTokenizer (java.util.StringTokenizer)4 MetaOID (org.jcryptool.crypto.flexiprovider.descriptors.meta.MetaOID)4 IMetaOID (org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaOID)4 Element (org.jdom.Element)4 MetaAlgorithm (org.jcryptool.crypto.flexiprovider.descriptors.meta.MetaAlgorithm)3 IMetaAlgorithm (org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaAlgorithm)3 MetaKeyGenerator (org.jcryptool.crypto.flexiprovider.descriptors.meta.MetaKeyGenerator)1 MetaLength (org.jcryptool.crypto.flexiprovider.descriptors.meta.MetaLength)1 IMetaKeyGenerator (org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaKeyGenerator)1 IMetaLength (org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaLength)1