]> WPIA git - gigi.git/blob - tests/club/wpia/gigi/crypto/key/KeyCheckTest.java
add: public key check searching for small primes (less than 10k)
[gigi.git] / tests / club / wpia / gigi / crypto / key / KeyCheckTest.java
1 package club.wpia.gigi.crypto.key;
2
3 import static org.junit.Assert.*;
4
5 import java.io.IOException;
6 import java.security.GeneralSecurityException;
7 import java.security.PublicKey;
8
9 import org.junit.Test;
10
11 import sun.security.util.DerValue;
12 import sun.security.x509.X509Key;
13 import club.wpia.gigi.GigiApiException;
14 import club.wpia.gigi.util.PEM;
15
16 public class KeyCheckTest {
17
18     public static PublicKey pkFromString(String pub) throws GeneralSecurityException, IOException {
19         byte[] data = PEM.decode("PUBLIC KEY", pub);
20         DerValue der = new DerValue(data);
21         PublicKey key = X509Key.parse(der);
22
23         return key;
24     }
25
26     @Test
27     public void testNullKey() {
28         try {
29             KeyCheck.checkKey(null);
30             fail("Providing a null key should fail!");
31         } catch (GigiApiException gae) {
32             // Expected failure
33         }
34
35         // Check that at least one key check has been loaded
36         assertFalse(KeyCheck.getChecks().isEmpty());
37     }
38
39 }