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

File BcX509CertificateGeneratorFactory.java

 

Coverage histogram

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

Code metrics

4
12
1
1
78
43
5
0.42
12
1
5

Classes

Class Line # Actions
BcX509CertificateGeneratorFactory 46 12 0% 5 6
0.6470588464.7%
 

Contributing tests

This file is covered by 6 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.internal;
21   
22    import java.security.SecureRandom;
23   
24    import javax.inject.Inject;
25    import javax.inject.Named;
26    import javax.inject.Provider;
27    import javax.inject.Singleton;
28   
29    import org.xwiki.component.annotation.Component;
30    import org.xwiki.crypto.pkix.CertificateGenerator;
31    import org.xwiki.crypto.pkix.CertificateGeneratorFactory;
32    import org.xwiki.crypto.pkix.params.CertificateGenerationParameters;
33    import org.xwiki.crypto.pkix.params.x509certificate.X509CertificateGenerationParameters;
34    import org.xwiki.crypto.signer.Signer;
35    import org.xwiki.crypto.signer.SignerFactory;
36   
37    /**
38    * X.509 certificate generator factory.
39    *
40    * @version $Id: 318d5597342da4bf42e927332fde534e811ed4c1 $
41    * @since 5.4
42    */
43    @Component
44    @Named("X509")
45    @Singleton
 
46    public class BcX509CertificateGeneratorFactory implements CertificateGeneratorFactory
47    {
48   
49    @Inject
50    private SignerFactory signerFactory;
51   
52    @Inject
53    private Provider<SecureRandom> randomProvider;
54   
 
55  10 toggle @Override
56    public CertificateGenerator getInstance(Signer signer, CertificateGenerationParameters parameters)
57    {
58  10 if (!(parameters instanceof X509CertificateGenerationParameters)) {
59  0 throw new IllegalArgumentException("Invalid parameters for X.509 certificate: "
60    + parameters.getClass().getName());
61    }
62   
63  10 if (!signer.isForSigning()) {
64  0 throw new IllegalArgumentException("Verifying signer used for signing certificates.");
65    }
66   
67  10 X509CertificateGenerationParameters params = (X509CertificateGenerationParameters) parameters;
68   
69  10 switch (params.getX509Version()) {
70  3 case V1:
71  3 return new BcX509v1CertificateGenerator(signer, params, this.signerFactory, this.randomProvider.get());
72  7 case V3:
73  7 return new BcX509v3CertificateGenerator(signer, params, this.signerFactory, this.randomProvider.get());
74  0 default:
75  0 throw new IllegalArgumentException("Unknown X.509 certificate version: " + params.getX509Version());
76    }
77    }
78    }