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

File BcPrivateKeyParameters.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart7.png
64% of files have more coverage

Code metrics

2
6
2
1
59
25
4
0.67
3
2
2

Classes

Class Line # Actions
BcPrivateKeyParameters 34 6 0% 4 3
0.770%
 

Contributing tests

This file is covered by 18 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.internal.asymmetric;
21   
22    import java.io.IOException;
23   
24    import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
25    import org.bouncycastle.crypto.util.PrivateKeyInfoFactory;
26    import org.xwiki.crypto.params.cipher.asymmetric.PrivateKeyParameters;
27   
28    /**
29    * Encapsulate a Bouncy Castle asymmetric parameter of a private key.
30    *
31    * @version $Id: c3ba7dd963e4634948fb4231bedd7f8c8e0a7a90 $
32    * @since 5.4M1
33    */
 
34    public class BcPrivateKeyParameters extends AbstractBcAsymmetricKeyParameters implements PrivateKeyParameters
35    {
36    /**
37    * Encapsulate a given Bouncy Castle private key parameter.
38    *
39    * @param parameters a BC private key parameter.
40    */
 
41  39 toggle public BcPrivateKeyParameters(AsymmetricKeyParameter parameters)
42    {
43  39 super(parameters);
44  39 if (!isPrivate()) {
45  0 throw new IllegalArgumentException("Non-private key assigned to a private key: "
46    + parameters.getClass().getName());
47    }
48    }
49   
 
50  16 toggle @Override
51    public byte[] getEncoded()
52    {
53  16 try {
54  16 return PrivateKeyInfoFactory.createPrivateKeyInfo(this.parameters).getEncoded();
55    } catch (IOException e) {
56  0 return null;
57    }
58    }
59    }