1package org.bouncycastle.cert.ocsp;
2
3import java.util.ArrayList;
4import java.util.Arrays;
5import java.util.Collections;
6import java.util.Date;
7import java.util.HashSet;
8import java.util.List;
9import java.util.Set;
10
11import org.bouncycastle.asn1.ASN1GeneralizedTime;
12import org.bouncycastle.asn1.x509.Extensions;
13import org.bouncycastle.cert.X509CertificateHolder;
14
15class OCSPUtils
16{
17    static final X509CertificateHolder[] EMPTY_CERTS = new X509CertificateHolder[0];
18
19    static Set EMPTY_SET = Collections.unmodifiableSet(new HashSet());
20    static List EMPTY_LIST = Collections.unmodifiableList(new ArrayList());
21
22    static Date extractDate(ASN1GeneralizedTime time)
23    {
24        try
25        {
26            return time.getDate();
27        }
28        catch (Exception e)
29        {
30            throw new IllegalStateException("exception processing GeneralizedTime: " + e.getMessage());
31        }
32    }
33
34    static Set getCriticalExtensionOIDs(Extensions extensions)
35    {
36        if (extensions == null)
37        {
38            return EMPTY_SET;
39        }
40
41        return Collections.unmodifiableSet(new HashSet(Arrays.asList(extensions.getCriticalExtensionOIDs())));
42    }
43
44    static Set getNonCriticalExtensionOIDs(Extensions extensions)
45    {
46        if (extensions == null)
47        {
48            return EMPTY_SET;
49        }
50
51        // TODO: should probably produce a set that imposes correct ordering
52        return Collections.unmodifiableSet(new HashSet(Arrays.asList(extensions.getNonCriticalExtensionOIDs())));
53    }
54
55    static List getExtensionOIDs(Extensions extensions)
56    {
57        if (extensions == null)
58        {
59            return EMPTY_LIST;
60        }
61
62        return Collections.unmodifiableList(Arrays.asList(extensions.getExtensionOIDs()));
63    }
64}
65