1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.crypto.internal.symmetric.generator; |
21 |
|
|
22 |
|
import java.security.SecureRandom; |
23 |
|
|
24 |
|
import javax.inject.Inject; |
25 |
|
import javax.inject.Provider; |
26 |
|
import javax.inject.Singleton; |
27 |
|
|
28 |
|
import org.bouncycastle.crypto.CipherKeyGenerator; |
29 |
|
import org.xwiki.component.annotation.Component; |
30 |
|
import org.xwiki.crypto.KeyGenerator; |
31 |
|
import org.xwiki.crypto.params.generator.KeyGenerationParameters; |
32 |
|
import org.xwiki.crypto.params.generator.symmetric.GenericKeyGenerationParameters; |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
@version |
38 |
|
@since |
39 |
|
|
40 |
|
@Component |
41 |
|
@Singleton |
|
|
| 84.6% |
Uncovered Elements: 2 (13) |
Complexity: 4 |
Complexity Density: 0.5 |
|
42 |
|
public class DefaultKeyGenerator implements KeyGenerator |
43 |
|
{ |
44 |
|
@Inject |
45 |
|
private Provider<SecureRandom> random; |
46 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
47 |
1 |
@Override... |
48 |
|
public byte[] generate() |
49 |
|
{ |
50 |
1 |
throw new UnsupportedOperationException("Knowing the key strength is required to generate a key."); |
51 |
|
} |
52 |
|
|
|
|
| 75% |
Uncovered Elements: 2 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
53 |
13 |
@Override... |
54 |
|
public byte[] generate(KeyGenerationParameters parameters) |
55 |
|
{ |
56 |
13 |
if (!(parameters instanceof GenericKeyGenerationParameters)) { |
57 |
0 |
throw new IllegalArgumentException("Invalid parameters for generic key generator: " |
58 |
|
+ parameters.getClass().getName()); |
59 |
|
} |
60 |
|
|
61 |
13 |
GenericKeyGenerationParameters params = (GenericKeyGenerationParameters) parameters; |
62 |
|
|
63 |
13 |
CipherKeyGenerator generator = getKeyGenerator(); |
64 |
13 |
generator.init(new org.bouncycastle.crypto.KeyGenerationParameters(this.random.get(), |
65 |
|
params.getStrength() * 8)); |
66 |
13 |
return generator.generateKey(); |
67 |
|
} |
68 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
69 |
3 |
protected CipherKeyGenerator getKeyGenerator()... |
70 |
|
{ |
71 |
3 |
return new CipherKeyGenerator(); |
72 |
|
} |
73 |
|
} |