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

File DefaultX509ExtensionBuilder.java

 

Coverage histogram

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

Code metrics

14
24
10
1
139
95
19
0.79
2.4
10
1.9

Classes

Class Line # Actions
DefaultX509ExtensionBuilder 46 24 0% 19 18
0.62562.5%
 

Contributing tests

This file is covered by 3 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.extension;
21   
22    import java.util.EnumSet;
23   
24    import org.bouncycastle.asn1.x509.BasicConstraints;
25    import org.bouncycastle.asn1.x509.Extension;
26    import org.bouncycastle.cert.bc.BcX509ExtensionUtils;
27    import org.xwiki.component.annotation.Component;
28    import org.xwiki.component.annotation.InstantiationStrategy;
29    import org.xwiki.component.descriptor.ComponentInstantiationStrategy;
30    import org.xwiki.crypto.params.cipher.asymmetric.PublicKeyParameters;
31    import org.xwiki.crypto.pkix.X509ExtensionBuilder;
32    import org.xwiki.crypto.pkix.internal.BcUtils;
33    import org.xwiki.crypto.pkix.params.CertifiedPublicKey;
34    import org.xwiki.crypto.pkix.params.x509certificate.extension.ExtendedKeyUsages;
35    import org.xwiki.crypto.pkix.params.x509certificate.extension.KeyUsage;
36    import org.xwiki.crypto.pkix.params.x509certificate.extension.X509GeneralName;
37   
38    /**
39    * X.509 extension set builder.
40    *
41    * @version $Id: 03237f82fb229907ea607b0a5c90489e7d57e994 $
42    * @since 5.4
43    */
44    @Component
45    @InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP)
 
46    public class DefaultX509ExtensionBuilder extends AbstractBcX509ExtensionBuilder
47    {
 
48  3 toggle @Override
49    public X509ExtensionBuilder addBasicConstraints(boolean isCertificateAuthority)
50    {
51  3 return addExtension(Extension.basicConstraints, true, new BasicConstraints(isCertificateAuthority));
52    }
53   
 
54  1 toggle @Override
55    public X509ExtensionBuilder addBasicConstraints(int pathLen)
56    {
57  1 return addExtension(Extension.basicConstraints, true, new BasicConstraints(pathLen));
58    }
59   
 
60  3 toggle @Override
61    public X509ExtensionBuilder addKeyUsage(EnumSet<KeyUsage> usages)
62    {
63  3 return addKeyUsage(true, usages);
64    }
65   
 
66  6 toggle @Override
67    public X509ExtensionBuilder addKeyUsage(boolean critical, EnumSet<KeyUsage> usages)
68    {
69  6 if (usages == null || usages.isEmpty()) {
70  0 return this;
71    }
72   
73  6 return addExtension(Extension.keyUsage, critical, BcExtensionUtils.getKeyUsage(usages));
74    }
75   
 
76  2 toggle @Override
77    public X509ExtensionBuilder addExtendedKeyUsage(boolean critical, ExtendedKeyUsages usages)
78    {
79  2 if (usages == null || usages.isEmpty()) {
80  0 return this;
81    }
82   
83  2 return addExtension(Extension.extendedKeyUsage, critical,
84    BcExtensionUtils.getExtendedKeyUsage(usages.getAll()));
85    }
86   
 
87  3 toggle @Override
88    public X509ExtensionBuilder addAuthorityKeyIdentifier(CertifiedPublicKey issuer)
89    {
90  3 if (issuer == null) {
91  0 return this;
92    }
93   
94  3 return addExtension(Extension.authorityKeyIdentifier, false,
95    new BcX509ExtensionUtils().createAuthorityKeyIdentifier(BcUtils.getX509CertificateHolder(issuer)));
96    }
97   
 
98  3 toggle @Override
99    public X509ExtensionBuilder addAuthorityKeyIdentifier(PublicKeyParameters subject)
100    {
101  3 if (subject == null) {
102  0 return this;
103    }
104   
105  3 return addExtension(Extension.authorityKeyIdentifier, false,
106    new BcX509ExtensionUtils().createAuthorityKeyIdentifier(BcUtils.getSubjectPublicKeyInfo(subject)));
107    }
108   
 
109  6 toggle @Override
110    public X509ExtensionBuilder addSubjectKeyIdentifier(PublicKeyParameters subject)
111    {
112  6 if (subject == null) {
113  0 return this;
114    }
115   
116  6 return addExtension(Extension.subjectKeyIdentifier, false,
117    new BcX509ExtensionUtils().createSubjectKeyIdentifier(BcUtils.getSubjectPublicKeyInfo(subject)));
118    }
119   
 
120  2 toggle @Override
121    public X509ExtensionBuilder addSubjectAltName(boolean critical, X509GeneralName[] names)
122    {
123  2 if (names == null) {
124  0 return this;
125    }
126   
127  2 return addExtension(Extension.subjectAlternativeName, false, BcExtensionUtils.getGeneralNames(names));
128    }
129   
 
130  0 toggle @Override
131    public X509ExtensionBuilder addIssuerAltName(X509GeneralName[] names)
132    {
133  0 if (names == null) {
134  0 return this;
135    }
136   
137  0 return addExtension(Extension.issuerAlternativeName, false, BcExtensionUtils.getGeneralNames(names));
138    }
139    }