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

File AbstractBcPBES2Cipher.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

2
7
2
1
70
31
3
0.43
3.5
2
1.5

Classes

Class Line # Actions
AbstractBcPBES2Cipher 39 7 0% 3 2
0.818181881.8%
 

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.IOException;
23   
24    import org.bouncycastle.asn1.pkcs.EncryptionScheme;
25    import org.bouncycastle.asn1.pkcs.KeyDerivationFunc;
26    import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
27    import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
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.internal.kdf.AbstractBcKDF;
32    import org.xwiki.crypto.password.internal.kdf.PBES2Parameters;
33   
34    /**
35    * Abstract base class for PBES2 Password Based Cipher using Bouncy Castle as the underlying implementation.
36    *
37    * @version $Id: 94029707ab58bd995b8f30363d3e69f699a75f31 $
38    */
 
39    public abstract class AbstractBcPBES2Cipher extends AbstractBcPBCipher
40    {
41    /**
42    * New PBE Cipher instance, that wrap the cipher created using the given key derivation function and parameters.
43    *
44    * @param cipher the cipher to wrap.
45    * @param kdf the key derivation function used to derive the key of this cipher.
46    * @param parameters the cipher parameter used.
47    */
 
48  26 toggle public AbstractBcPBES2Cipher(Cipher cipher, KeyDerivationFunction kdf, SymmetricCipherParameters parameters)
49    {
50  26 super(cipher, kdf, parameters);
51    }
52   
53    protected abstract EncryptionScheme getScheme(SymmetricCipherParameters parameters);
54   
 
55  25 toggle @Override
56    public AlgorithmIdentifier getPBEParameters() throws IOException
57    {
58  25 KeyDerivationFunc kdfParams;
59   
60  25 if (getKeyDerivationFunction() instanceof AbstractBcKDF) {
61  25 kdfParams = ((AbstractBcKDF) getKeyDerivationFunction()).getKeyDerivationFunction();
62    } else {
63  0 kdfParams = KeyDerivationFunc.getInstance(getKeyDerivationFunction().getEncoded());
64    }
65   
66  25 EncryptionScheme scheme = getScheme(getParameters());
67   
68  25 return new AlgorithmIdentifier(PKCSObjectIdentifiers.id_PBES2, new PBES2Parameters(kdfParams, scheme));
69    }
70    }