1b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallampackage org.bouncycastle.asn1.x509;
2b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
3b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport org.bouncycastle.asn1.ASN1EncodableVector;
44c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstromimport org.bouncycastle.asn1.ASN1Object;
54c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstromimport org.bouncycastle.asn1.ASN1Primitive;
6b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport org.bouncycastle.asn1.ASN1Sequence;
7b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport org.bouncycastle.asn1.ASN1TaggedObject;
8b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport org.bouncycastle.asn1.DERSequence;
9b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
10b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallampublic class CRLDistPoint
114c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom    extends ASN1Object
12b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam{
13b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    ASN1Sequence  seq = null;
14b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
15b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    public static CRLDistPoint getInstance(
16b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        ASN1TaggedObject obj,
17b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        boolean          explicit)
18b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    {
19b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        return getInstance(ASN1Sequence.getInstance(obj, explicit));
20b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    }
21b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
22b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    public static CRLDistPoint getInstance(
23b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        Object  obj)
24b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    {
254c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom        if (obj instanceof CRLDistPoint)
26b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        {
27b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            return (CRLDistPoint)obj;
28b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        }
294c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom        else if (obj != null)
30b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        {
314c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom            return new CRLDistPoint(ASN1Sequence.getInstance(obj));
32b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        }
33b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
344c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom        return null;
35b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    }
36b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
374c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom    private CRLDistPoint(
38b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        ASN1Sequence seq)
39b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    {
40b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        this.seq = seq;
41b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    }
42b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
43b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    public CRLDistPoint(
44b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        DistributionPoint[] points)
45b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    {
46b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        ASN1EncodableVector  v = new ASN1EncodableVector();
47b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
48b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        for (int i = 0; i != points.length; i++)
49b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        {
50b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            v.add(points[i]);
51b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        }
52b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
53b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        seq = new DERSequence(v);
54b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    }
55b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
56b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    /**
57b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * Return the distribution points making up the sequence.
58b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     *
59b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * @return DistributionPoint[]
60b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     */
61b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    public DistributionPoint[] getDistributionPoints()
62b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    {
63b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        DistributionPoint[]    dp = new DistributionPoint[seq.size()];
64b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
65b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        for (int i = 0; i != seq.size(); i++)
66b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        {
67b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            dp[i] = DistributionPoint.getInstance(seq.getObjectAt(i));
68b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        }
69b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
70b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        return dp;
71b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    }
72b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
73b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    /**
74b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * Produce an object suitable for an ASN1OutputStream.
75b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * <pre>
76b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * CRLDistPoint ::= SEQUENCE SIZE {1..MAX} OF DistributionPoint
77b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * </pre>
78b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     */
794c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom    public ASN1Primitive toASN1Primitive()
80b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    {
81b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        return seq;
82b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    }
83c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom
84c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom    public String toString()
85c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom    {
86c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom        StringBuffer buf = new StringBuffer();
87c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom        String       sep = System.getProperty("line.separator");
88c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom
89c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom        buf.append("CRLDistPoint:");
90c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom        buf.append(sep);
91c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom        DistributionPoint dp[] = getDistributionPoints();
92c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom        for (int i = 0; i != dp.length; i++)
93c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom        {
94c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom            buf.append("    ");
95c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom            buf.append(dp[i]);
96c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom            buf.append(sep);
97c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom        }
98c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom        return buf.toString();
99c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom    }
100b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam}
101