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.pbe.factory; |
21 |
|
|
22 |
|
import javax.inject.Inject; |
23 |
|
|
24 |
|
import org.bouncycastle.asn1.ASN1Encodable; |
25 |
|
import org.bouncycastle.asn1.ASN1Sequence; |
26 |
|
import org.xwiki.crypto.cipher.CipherFactory; |
27 |
|
import org.xwiki.crypto.params.cipher.symmetric.SymmetricCipherParameters; |
28 |
|
import org.xwiki.crypto.password.KeyDerivationFunctionFactory; |
29 |
|
import org.xwiki.crypto.password.PasswordBasedCipher; |
30 |
|
import org.xwiki.crypto.password.PasswordBasedCipherFactory; |
31 |
|
import org.xwiki.crypto.password.params.KeyDerivationFunctionParameters; |
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
@version |
37 |
|
@since |
38 |
|
|
|
|
| 55% |
Uncovered Elements: 9 (20) |
Complexity: 10 |
Complexity Density: 0.91 |
|
39 |
|
public abstract class AbstractBcPBCipherFactory implements PasswordBasedCipherFactory |
40 |
|
{ |
41 |
|
private static final RuntimeException UNSUPPORTED = |
42 |
|
new UnsupportedOperationException("Sorry, this factory does implement any concrete cipher."); |
43 |
|
|
44 |
|
@Inject |
45 |
|
private KeyDerivationFunctionFactory kdfFactory; |
46 |
|
|
47 |
|
|
48 |
|
@return |
49 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
50 |
26 |
protected KeyDerivationFunctionFactory getKDFFactory()... |
51 |
|
{ |
52 |
26 |
return this.kdfFactory; |
53 |
|
} |
54 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
55 |
20 |
private CipherFactory safeGetCipherFactory()... |
56 |
|
{ |
57 |
20 |
try { |
58 |
20 |
return getCipherFactory(); |
59 |
|
} catch (UnsupportedOperationException e) { |
60 |
0 |
throw UNSUPPORTED; |
61 |
|
} |
62 |
|
} |
63 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
64 |
0 |
@Override... |
65 |
|
public String getCipherAlgorithmName() |
66 |
|
{ |
67 |
0 |
return safeGetCipherFactory().getCipherAlgorithmName(); |
68 |
|
} |
69 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
70 |
2 |
@Override... |
71 |
|
public int getIVSize() |
72 |
|
{ |
73 |
2 |
return safeGetCipherFactory().getIVSize(); |
74 |
|
} |
75 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
76 |
8 |
@Override... |
77 |
|
public int getKeySize() |
78 |
|
{ |
79 |
8 |
return safeGetCipherFactory().getKeySize(); |
80 |
|
} |
81 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
82 |
0 |
@Override... |
83 |
|
public int[] getSupportedKeySizes() |
84 |
|
{ |
85 |
0 |
return safeGetCipherFactory().getSupportedKeySizes(); |
86 |
|
} |
87 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
88 |
10 |
@Override... |
89 |
|
public boolean isSupportedKeySize(int keySize) |
90 |
|
{ |
91 |
10 |
return safeGetCipherFactory().isSupportedKeySize(keySize); |
92 |
|
} |
93 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
94 |
0 |
@Override... |
95 |
|
public PasswordBasedCipher getInstance(boolean forEncryption, SymmetricCipherParameters password, |
96 |
|
KeyDerivationFunctionParameters parameters) |
97 |
|
{ |
98 |
0 |
throw new UnsupportedOperationException("Sorry, no concrete implementation to create an instance."); |
99 |
|
} |
100 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
101 |
0 |
@Override... |
102 |
|
public PasswordBasedCipher getInstance(boolean forEncryption, byte[] password, byte[] encoded) |
103 |
|
{ |
104 |
0 |
return getInstance(forEncryption, password, ASN1Sequence.getInstance(encoded)); |
105 |
|
} |
106 |
|
|
107 |
|
|
108 |
|
@return |
109 |
|
|
110 |
|
protected abstract CipherFactory getCipherFactory(); |
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
@param |
119 |
|
@param |
120 |
|
@param |
121 |
|
@return |
122 |
|
|
123 |
|
public abstract PasswordBasedCipher getInstance(boolean forEncryption, byte[] password, ASN1Encodable parameters); |
124 |
|
} |