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

File ExtendedKeyUsages.java

 

Coverage histogram

../../../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

0
5
5
1
109
38
5
1
1
5
1

Classes

Class Line # Actions
ExtendedKeyUsages 35 5 0% 5 0
1.0100%
 

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.params.x509certificate.extension;
21   
22    import java.util.Collection;
23    import java.util.Collections;
24    import java.util.HashSet;
25    import java.util.Set;
26   
27    import org.bouncycastle.asn1.x509.Extension;
28   
29    /**
30    * Extended Key Usage.
31    *
32    * @version $Id: fc97855d077ea46159fea9394a5a3794c4f81b18 $
33    * @since 5.4
34    */
 
35    public class ExtendedKeyUsages
36    {
37    /** OID of ExtendedKeyUsage. */
38    public static final String OID = Extension.extendedKeyUsage.getId();
39   
40    /** { 2 5 29 37 0 }. */
41    public static final String ANY_EXTENDED_KEY_USAGE = "2.5.29.37.0";
42   
43    /** Server authentication { 1 3 6 1 5 5 7 3 1 }. */
44    public static final String SERVER_AUTH = "1.3.6.1.5.5.7.3.1";
45   
46    /** Client authentication { 1 3 6 1 5 5 7 3 2 }. */
47    public static final String CLIENT_AUTH = "1.3.6.1.5.5.7.3.2";
48   
49    /** Code signing { 1 3 6 1 5 5 7 3 3 }. */
50    public static final String CODE_SIGNING = "1.3.6.1.5.5.7.3.3";
51   
52    /** Email protection { 1 3 6 1 5 5 7 3 4 }. */
53    public static final String EMAIL_PROTECTION = "1.3.6.1.5.5.7.3.4";
54   
55    /** Timestamping { 1 3 6 1 5 5 7 3 8 }. */
56    public static final String TIME_STAMPING = "1.3.6.1.5.5.7.3.8";
57   
58    /** OCSP Signing { 1 3 6 1 5 5 7 3 9 }. */
59    public static final String OCSP_SIGNING = "1.3.6.1.5.5.7.3.9";
60   
61    private Set<String> usages = new HashSet<String>();
62   
63    /**
64    * Constructor from string array.
65    *
66    * @param usages array of usage OID to add.
67    */
 
68  2 toggle public ExtendedKeyUsages(String[] usages)
69    {
70  2 Collections.addAll(this.usages, usages);
71    }
72   
73    /**
74    * Constructor from string array.
75    *
76    * @param usages list of usage OID to add.
77    */
 
78  4 toggle public ExtendedKeyUsages(Collection<String> usages)
79    {
80  4 this.usages.addAll(usages);
81    }
82   
83    /**
84    * Check if a given usage is authorized.
85    *
86    * @param usage the usage oid to check.
87    * @return true if the usage is authorized.
88    */
 
89  2 toggle public boolean hasUsage(String usage)
90    {
91  2 return this.usages.contains(usage);
92    }
93   
94    /**
95    * @return all extended usage oid.
96    */
 
97  4 toggle public Set<String> getAll()
98    {
99  4 return Collections.unmodifiableSet(this.usages);
100    }
101   
102    /**
103    * @return true if no extended usage has been added.
104    */
 
105  2 toggle public boolean isEmpty()
106    {
107  2 return this.usages.isEmpty();
108    }
109    }