summaryrefslogtreecommitdiff
path: root/src/cz/crcs/ectester/standalone/consts/KeyPairGeneratorIdent.java
blob: 8e67967bcfd8a311a28a8409c16041f6ea81810e (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
50
package cz.crcs.ectester.standalone.consts;

import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.Provider;
import java.util.LinkedList;
import java.util.List;

public class KeyPairGeneratorIdent extends Ident {
    private static final List<KeyPairGeneratorIdent> ALL = new LinkedList<>();

    static {
        ALL.add(new KeyPairGeneratorIdent("EC"));
        ALL.add(new KeyPairGeneratorIdent("ECDH"));
        ALL.add(new KeyPairGeneratorIdent("ECDSA"));
        ALL.add(new KeyPairGeneratorIdent("ECDHC"));
        ALL.add(new KeyPairGeneratorIdent("ECMQV"));
        ALL.add(new KeyPairGeneratorIdent("ECGOST3410"));
        ALL.add(new KeyPairGeneratorIdent("ECGOST3410-2012"));
        // ECKCDSA? Botan provides.
        ALL.add(new KeyPairGeneratorIdent("ECKCDSA"));
        // ECGDSA? Botan provides.
        ALL.add(new KeyPairGeneratorIdent("ECGDSA"));
    }

    public static KeyPairGeneratorIdent get(String ident) {
        for (KeyPairGeneratorIdent kg : ALL) {
            if (kg.getIdents().contains(ident)) {
                return kg;
            }
        }
        return null;
    }

    public KeyPairGeneratorIdent(String name, String... aliases) {
        super(name, aliases);
    }

    public KeyPairGenerator getInstance(Provider provider) throws NoSuchAlgorithmException {
        KeyPairGenerator instance = getInstance((algorithm, provider1) -> {
            try {
                return KeyPairGenerator.getInstance(algorithm, provider1);
            } catch (NoSuchAlgorithmException e) {
                return null;
            }
        }, provider);
        instance.getProvider();
        return instance;
    }
}