1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.crypto.password.internal.pbe

File AbstractPBCipher.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart4.png
78% of files have more coverage

Code metrics

0
16
14
1
140
87
14
0.88
1.14
14
1

Classes

Class Line # Actions
AbstractPBCipher 41 16 0% 14 20
0.3333333433.3%
 

Contributing tests

This file is covered by 13 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.crypto.password.internal.pbe;
21   
22    import java.io.FilterInputStream;
23    import java.io.FilterOutputStream;
24    import java.io.InputStream;
25    import java.io.OutputStream;
26    import java.security.GeneralSecurityException;
27   
28    import org.xwiki.crypto.cipher.Cipher;
29    import org.xwiki.crypto.params.cipher.symmetric.SymmetricCipherParameters;
30    import org.xwiki.crypto.password.KeyDerivationFunction;
31    import org.xwiki.crypto.password.PasswordBasedCipher;
32   
33    /**
34    * Abstract base class for Password Based Cipher.
35    *
36    * Delegate cipher operation to the underlying cipher and provide access to function and cipher parameters.
37    *
38    * @version $Id: 8ee9ed561b29c7c739f5e333f7fc3c96718b93da $
39    * @since 5.4M1
40    */
 
41    public abstract class AbstractPBCipher implements PasswordBasedCipher
42    {
43    private KeyDerivationFunction kdf;
44   
45    private SymmetricCipherParameters parameters;
46   
47    private Cipher cipher;
48   
49    /**
50    * New PBE Cipher instance, that wrap the cipher created using the given key derivation function and parameters.
51    *
52    * @param cipher the cipher to wrap.
53    * @param kdf the key derivation function used to derive the key of this cipher.
54    * @param parameters the cipher parameter used.
55    */
 
56  26 toggle public AbstractPBCipher(Cipher cipher, KeyDerivationFunction kdf, SymmetricCipherParameters parameters)
57    {
58  26 this.cipher = cipher;
59  26 this.kdf = kdf;
60  26 this.parameters = parameters;
61    }
62   
 
63  50 toggle @Override
64    public KeyDerivationFunction getKeyDerivationFunction()
65    {
66  50 return this.kdf;
67    }
68   
 
69  25 toggle @Override
70    public SymmetricCipherParameters getParameters()
71    {
72  25 return this.parameters;
73    }
74   
 
75  0 toggle @Override
76    public String getAlgorithmName()
77    {
78  0 return this.cipher.getAlgorithmName();
79    }
80   
 
81  0 toggle @Override
82    public int getInputBlockSize()
83    {
84  0 return this.cipher.getInputBlockSize();
85    }
86   
 
87  0 toggle @Override
88    public int getOutputBlockSize()
89    {
90  0 return this.cipher.getOutputBlockSize();
91    }
92   
 
93  0 toggle @Override
94    public FilterInputStream getInputStream(InputStream is)
95    {
96  0 return this.cipher.getInputStream(is);
97    }
98   
 
99  0 toggle @Override
100    public FilterOutputStream getOutputStream(OutputStream os)
101    {
102  0 return this.cipher.getOutputStream(os);
103    }
104   
 
105  0 toggle @Override
106    public boolean isForEncryption()
107    {
108  0 return this.cipher.isForEncryption();
109    }
110   
 
111  0 toggle @Override
112    public byte[] update(byte[] input)
113    {
114  0 return this.cipher.update(input);
115    }
116   
 
117  0 toggle @Override
118    public byte[] update(byte[] input, int inputOffset, int inputLen)
119    {
120  0 return this.cipher.update(input, inputOffset, inputLen);
121    }
122   
 
123  0 toggle @Override
124    public byte[] doFinal() throws GeneralSecurityException
125    {
126  0 return this.cipher.doFinal();
127    }
128   
 
129  26 toggle @Override
130    public byte[] doFinal(byte[] input) throws GeneralSecurityException
131    {
132  26 return this.cipher.doFinal(input);
133    }
134   
 
135  0 toggle @Override
136    public byte[] doFinal(byte[] input, int inputOffset, int inputLen) throws GeneralSecurityException
137    {
138  0 return this.cipher.doFinal(input, inputOffset, inputLen);
139    }
140    }