1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.crypto.password.internal.kdf.factory; |
21 |
|
|
22 |
|
import javax.inject.Inject; |
23 |
|
import javax.inject.Singleton; |
24 |
|
|
25 |
|
import org.bouncycastle.asn1.ASN1Encodable; |
26 |
|
import org.bouncycastle.asn1.ASN1Sequence; |
27 |
|
import org.bouncycastle.asn1.pkcs.KeyDerivationFunc; |
28 |
|
import org.xwiki.component.annotation.Component; |
29 |
|
import org.xwiki.component.manager.ComponentLookupException; |
30 |
|
import org.xwiki.component.manager.ComponentManager; |
31 |
|
import org.xwiki.crypto.password.KeyDerivationFunction; |
32 |
|
import org.xwiki.crypto.password.KeyDerivationFunctionFactory; |
33 |
|
import org.xwiki.crypto.password.params.KeyDerivationFunctionParameters; |
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
@version |
43 |
|
@since |
44 |
|
|
45 |
|
@Component |
46 |
|
@Singleton |
|
|
| 79.2% |
Uncovered Elements: 5 (24) |
Complexity: 8 |
Complexity Density: 0.53 |
|
47 |
|
public class DefaultKeyDerivationFunctionFactory extends AbstractBcKDFFactory |
48 |
|
{ |
49 |
|
@Inject |
50 |
|
private ComponentManager manager; |
51 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
52 |
15 |
@Override... |
53 |
|
public KeyDerivationFunction getInstance(KeyDerivationFunctionParameters params) |
54 |
|
{ |
55 |
15 |
return getFactory(params.getAlgorithmName()).getInstance(params); |
56 |
|
} |
57 |
|
|
|
|
| 75% |
Uncovered Elements: 2 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
58 |
2 |
@Override... |
59 |
|
public KeyDerivationFunction getInstance(byte[] encoded) |
60 |
|
{ |
61 |
2 |
KeyDerivationFunc func = KeyDerivationFunc.getInstance(ASN1Sequence.getInstance(encoded)); |
62 |
2 |
KeyDerivationFunctionFactory factory = getFactory(func.getAlgorithm().getId()); |
63 |
2 |
KeyDerivationFunction kdf = getBcInstance(factory, func); |
64 |
2 |
if (kdf == null) { |
65 |
0 |
kdf = factory.getInstance(encoded); |
66 |
|
} |
67 |
2 |
return kdf; |
68 |
|
} |
69 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
70 |
13 |
@Override... |
71 |
|
public KeyDerivationFunction getInstance(ASN1Encodable parameters) |
72 |
|
{ |
73 |
13 |
KeyDerivationFunc func = KeyDerivationFunc.getInstance(parameters); |
74 |
13 |
return getBcInstance(getFactory(func.getAlgorithm().getId()), func); |
75 |
|
} |
76 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
77 |
15 |
private KeyDerivationFunction getBcInstance(KeyDerivationFunctionFactory factory, KeyDerivationFunc func)... |
78 |
|
{ |
79 |
15 |
if (factory instanceof AbstractBcKDFFactory) { |
80 |
15 |
return ((AbstractBcKDFFactory) factory).getInstance(func); |
81 |
|
} |
82 |
0 |
return null; |
83 |
|
} |
84 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
85 |
30 |
private KeyDerivationFunctionFactory getFactory(String hint)... |
86 |
|
{ |
87 |
30 |
try { |
88 |
30 |
return this.manager.getInstance(KeyDerivationFunctionFactory.class, hint); |
89 |
|
} catch (ComponentLookupException e) { |
90 |
0 |
throw new UnsupportedOperationException("Key derivation function algorithm not found.", e); |
91 |
|
} |
92 |
|
} |
93 |
|
} |