Welcome to mirror list, hosted at ThFree Co, Russian Federation.

JceTestUtil.java « test « provider « jce « spongycastle « org « java « test « src « prov - gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 271a27f8259ad9e62ee07ddb9f8a2059e59a8286 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package org.spongycastle.jce.provider.test;

import java.security.Security;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

import org.spongycastle.jce.provider.BouncyCastleProvider;

abstract class JceTestUtil
{
    private JceTestUtil()
    {
    }

    static String[] getRegisteredAlgorithms(String prefix, String[] exclusionPatterns)
    {
        final BouncyCastleProvider prov = (BouncyCastleProvider)Security.getProvider("SC");

        List matches = new ArrayList();
        Enumeration algos = prov.keys();
        while (algos.hasMoreElements())
        {
            String algo = (String)algos.nextElement();
            if (!algo.startsWith(prefix))
            {
                continue;
            }
            String algoName = algo.substring(prefix.length());
            if (!isExcluded(algoName, exclusionPatterns))
            {
                matches.add(algoName);
            }
        }
        return (String[])matches.toArray(new String[matches.size()]);
    }

    private static boolean isExcluded(String algoName, String[] exclusionPatterns)
    {
        for (int i = 0; i < exclusionPatterns.length; i++)
        {
            if (algoName.contains(exclusionPatterns[i]))
            {
                return true;
            }
        }
        return false;
    }
}