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

File CertifyingSigner.java

 

Coverage histogram

../../../../img/srcFileCovDistChart5.png
74% of files have more coverage

Code metrics

0
20
19
1
189
112
19
0.95
1.05
19
1

Classes

Class Line # Actions
CertifyingSigner 41 20 0% 19 22
0.4358974443.6%
 

Contributing tests

This file is covered by 10 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.pkix;
21   
22    import java.io.FilterInputStream;
23    import java.io.InputStream;
24    import java.io.OutputStream;
25    import java.security.GeneralSecurityException;
26   
27    import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
28    import org.bouncycastle.operator.ContentSigner;
29    import org.xwiki.crypto.pkix.internal.BcUtils;
30    import org.xwiki.crypto.pkix.params.CertifiedKeyPair;
31    import org.xwiki.crypto.pkix.params.CertifiedPublicKey;
32    import org.xwiki.crypto.signer.Signer;
33    import org.xwiki.crypto.signer.SignerFactory;
34   
35    /**
36    * A signer for certifying certificate.
37    *
38    * @version $Id: 7b3842f11eda55c622fb0a3327ea6aa2445dc7fd $
39    * @since 5.4
40    */
 
41    public final class CertifyingSigner implements Signer, ContentSigner
42    {
43    private final CertifiedPublicKey certifier;
44   
45    private final Signer signer;
46   
47    /**
48    * Private constructor.
49    *
50    * @param certifier the certifier certified public key.
51    * @param signer the signer initialized with the certifier private key.
52    */
 
53  11 toggle private CertifyingSigner(CertifiedPublicKey certifier, Signer signer)
54    {
55  11 this.certifier = certifier;
56  11 this.signer = signer;
57    }
58   
59    /**
60    * Get a certifying signer instance from the given signer factory for a given certifier.
61    *
62    * @param forSigning true for signing, and false for verifying.
63    * @param certifier the certified key pair of the certifier.
64    * @param factory a signer factory to create the signer.
65    * @return a certifying signer.
66    */
 
67  11 toggle public static CertifyingSigner getInstance(boolean forSigning, CertifiedKeyPair certifier, SignerFactory factory)
68    {
69  11 return new CertifyingSigner(certifier.getCertificate(),
70    factory.getInstance(forSigning, certifier.getPrivateKey()));
71    }
72   
73    /**
74    * @return the certified public key of the certifier.
75    */
 
76  11 toggle public CertifiedPublicKey getCertifier()
77    {
78  11 return this.certifier;
79    }
80   
 
81  0 toggle @Override
82    public String getAlgorithmName()
83    {
84  0 return this.signer.getAlgorithmName();
85    }
86   
 
87  4 toggle @Override
88    public boolean isForSigning()
89    {
90  4 return this.signer.isForSigning();
91    }
92   
 
93  0 toggle @Override
94    public FilterInputStream getInputStream(InputStream is)
95    {
96  0 return this.signer.getInputStream(is);
97    }
98   
 
99  11 toggle @Override
100    public OutputStream getOutputStream()
101    {
102  11 return this.signer.getOutputStream();
103    }
104   
 
105  0 toggle @Override
106    public void update(byte input)
107    {
108  0 this.signer.update(input);
109    }
110   
 
111  0 toggle @Override
112    public void update(byte[] input)
113    {
114  0 this.signer.update(input);
115    }
116   
 
117  0 toggle @Override
118    public void update(byte[] input, int inputOffset, int inputLen)
119    {
120  0 this.signer.update(input, inputOffset, inputLen);
121    }
122   
 
123  4 toggle @Override
124    public byte[] generate() throws GeneralSecurityException
125    {
126  4 return this.signer.generate();
127    }
128   
 
129  0 toggle @Override
130    public byte[] generate(byte[] input) throws GeneralSecurityException
131    {
132  0 return this.signer.generate(input);
133    }
134   
 
135  0 toggle @Override
136    public byte[] generate(byte[] input, int inputOffset, int inputLen) throws GeneralSecurityException
137    {
138  0 return this.signer.generate(input, inputOffset, inputLen);
139    }
140   
 
141  0 toggle @Override
142    public boolean verify(byte[] signature) throws GeneralSecurityException
143    {
144  0 return this.signer.verify(signature);
145    }
146   
 
147  0 toggle @Override
148    public boolean verify(byte[] signature, byte[] input) throws GeneralSecurityException
149    {
150  0 return this.signer.verify(signature, input);
151    }
152   
 
153  0 toggle @Override
154    public boolean verify(byte[] signature, int signOffset, int signLen, byte[] input, int inputOffset, int inputLen)
155    throws GeneralSecurityException
156    {
157  0 return this.signer.verify(signature, signOffset, signLen, input, inputOffset, inputLen);
158    }
159   
 
160  0 toggle @Override
161    public byte[] getEncoded()
162    {
163  0 return this.signer.getEncoded();
164    }
165   
166    // ContentSigner interface
167   
168    /**
169    * {@inheritDoc}
170    *
171    * @since 6.0M1
172    */
 
173  25 toggle @Override
174    public AlgorithmIdentifier getAlgorithmIdentifier()
175    {
176  25 return BcUtils.getSignerAlgoritmIdentifier(this.signer);
177    }
178   
179    /**
180    * {@inheritDoc}
181    *
182    * @since 6.0M1
183    */
 
184  7 toggle @Override
185    public byte[] getSignature()
186    {
187  7 return ((ContentSigner) this.signer).getSignature();
188    }
189    }