001    /**
002     *  Licensed to the Apache Software Foundation (ASF) under one or more
003     *  contributor license agreements.  See the NOTICE file distributed with
004     *  this work for additional information regarding copyright ownership.
005     *  The ASF licenses this file to You under the Apache License, Version 2.0
006     *  (the "License"); you may not use this file except in compliance with
007     *  the License.  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     *  Unless required by applicable law or agreed to in writing, software
012     *  distributed under the License is distributed on an "AS IS" BASIS,
013     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     *  See the License for the specific language governing permissions and
015     *  limitations under the License.
016     */
017    
018    package org.apache.geronimo.crypto.asn1.x509;
019    
020    import org.apache.geronimo.crypto.asn1.ASN1Encodable;
021    import org.apache.geronimo.crypto.asn1.ASN1EncodableVector;
022    import org.apache.geronimo.crypto.asn1.ASN1Sequence;
023    import org.apache.geronimo.crypto.asn1.ASN1TaggedObject;
024    import org.apache.geronimo.crypto.asn1.DERObject;
025    import org.apache.geronimo.crypto.asn1.DERSequence;
026    
027    public class CRLDistPoint
028        extends ASN1Encodable
029    {
030        ASN1Sequence  seq = null;
031    
032        public static CRLDistPoint getInstance(
033            ASN1TaggedObject obj,
034            boolean          explicit)
035        {
036            return getInstance(ASN1Sequence.getInstance(obj, explicit));
037        }
038    
039        public static CRLDistPoint getInstance(
040            Object  obj)
041        {
042            if (obj instanceof CRLDistPoint)
043            {
044                return (CRLDistPoint)obj;
045            }
046            else if (obj instanceof ASN1Sequence)
047            {
048                return new CRLDistPoint((ASN1Sequence)obj);
049            }
050    
051            throw new IllegalArgumentException("unknown object in factory");
052        }
053    
054        public CRLDistPoint(
055            ASN1Sequence seq)
056        {
057            this.seq = seq;
058        }
059    
060        public CRLDistPoint(
061            DistributionPoint[] points)
062        {
063            ASN1EncodableVector  v = new ASN1EncodableVector();
064    
065            for (int i = 0; i != points.length; i++)
066            {
067                v.add(points[i]);
068            }
069    
070            seq = new DERSequence(v);
071        }
072    
073        /**
074         * Return the distribution points making up the sequence.
075         *
076         * @return DistributionPoint[]
077         */
078        public DistributionPoint[] getDistributionPoints()
079        {
080            DistributionPoint[]    dp = new DistributionPoint[seq.size()];
081    
082            for (int i = 0; i != seq.size(); i++)
083            {
084                dp[i] = DistributionPoint.getInstance(seq.getObjectAt(i));
085            }
086    
087            return dp;
088        }
089    
090        /**
091         * Produce an object suitable for an ASN1OutputStream.
092         * <pre>
093         * CRLDistPoint ::= SEQUENCE SIZE {1..MAX} OF DistributionPoint
094         * </pre>
095         */
096        public DERObject toASN1Object()
097        {
098            return seq;
099        }
100    }