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

File AbstractBcKDFFactory.java

 

Coverage histogram

../../../../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

4
9
2
1
70
31
5
0.56
4.5
2
2.5

Classes

Class Line # Actions
AbstractBcKDFFactory 36 9 0% 5 3
0.880%
 

Contributing tests

This file is covered by 4 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.kdf.factory;
21   
22    import javax.inject.Named;
23   
24    import org.bouncycastle.asn1.ASN1Encodable;
25    import org.bouncycastle.asn1.ASN1Sequence;
26    import org.xwiki.component.annotation.Component;
27    import org.xwiki.crypto.password.KeyDerivationFunction;
28    import org.xwiki.crypto.password.KeyDerivationFunctionFactory;
29   
30    /**
31    * Abstract base class for key derivation function factory based on Bouncy Castle.
32    *
33    * @version $Id: 6790c3fc1a1fa90f3efb042f4ca09dceef87d642 $
34    * @since 5.4M1
35    */
 
36    public abstract class AbstractBcKDFFactory implements KeyDerivationFunctionFactory
37    {
 
38  2 toggle @Override
39    public String getKDFAlgorithmName()
40    {
41  2 String hint = null;
42  2 Named named = this.getClass().getAnnotation(Named.class);
43  2 if (named != null) {
44  0 hint = named.value();
45    } else {
46  2 Component component = this.getClass().getAnnotation(Component.class);
47  2 if (component != null && component.hints().length > 0) {
48  2 hint = component.hints()[0];
49    }
50    }
51   
52  2 return hint;
53    }
54   
 
55  2 toggle @Override
56    public KeyDerivationFunction getInstance(byte[] encoded)
57    {
58  2 return getInstance(ASN1Sequence.getInstance(encoded));
59    }
60   
61    /**
62    * Get a Bouncy Castle based key derivation function from ASN.1 parameters.
63    *
64    * The ASN.1 parameters will be parsed as a {@link org.bouncycastle.asn1.pkcs.KeyDerivationFunc}.
65    *
66    * @param parameters ASN.1 encodable parameters to initialize the function.
67    * @return a initialized key derivation function.
68    */
69    public abstract KeyDerivationFunction getInstance(ASN1Encodable parameters);
70    }