001    /**
002     *
003     *  Licensed to the Apache Software Foundation (ASF) under one or more
004     *  contributor license agreements.  See the NOTICE file distributed with
005     *  this work for additional information regarding copyright ownership.
006     *  The ASF licenses this file to You under the Apache License, Version 2.0
007     *  (the "License"); you may not use this file except in compliance with
008     *  the License.  You may obtain a copy of the License at
009     *
010     *     http://www.apache.org/licenses/LICENSE-2.0
011     *
012     *  Unless required by applicable law or agreed to in writing, software
013     *  distributed under the License is distributed on an "AS IS" BASIS,
014     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015     *  See the License for the specific language governing permissions and
016     *  limitations under the License.
017     */
018    
019    package org.apache.geronimo.util.asn1.x509;
020    
021    import org.apache.geronimo.util.asn1.ASN1Encodable;
022    import org.apache.geronimo.util.asn1.ASN1Sequence;
023    import org.apache.geronimo.util.asn1.ASN1TaggedObject;
024    import org.apache.geronimo.util.asn1.DERBoolean;
025    import org.apache.geronimo.util.asn1.DERObject;
026    
027    /**
028     * IssuingDistributionPoint ::= SEQUENCE {
029     *      distributionPoint          [0] DistributionPointName OPTIONAL,
030     *      onlyContainsUserCerts      [1] BOOLEAN DEFAULT FALSE,
031     *      onlyContainsCACerts        [2] BOOLEAN DEFAULT FALSE,
032     *      onlySomeReasons            [3] ReasonFlags OPTIONAL,
033     *      indirectCRL                [4] BOOLEAN DEFAULT FALSE,
034     *      onlyContainsAttributeCerts [5] BOOLEAN DEFAULT FALSE }
035     */
036    public class IssuingDistributionPoint
037        extends ASN1Encodable
038    {
039        private boolean         onlyContainsUserCerts;
040        private boolean         onlyContainsCACerts;
041        private boolean         indirectCRL;
042        private boolean         onlyContainsAttributeCerts;
043    
044        private ASN1Sequence    seq;
045    
046        public static IssuingDistributionPoint getInstance(
047            ASN1TaggedObject obj,
048            boolean          explicit)
049        {
050            return getInstance(ASN1Sequence.getInstance(obj, explicit));
051        }
052    
053        public static IssuingDistributionPoint getInstance(
054            Object  obj)
055        {
056            if (obj == null || obj instanceof IssuingDistributionPoint)
057            {
058                return (IssuingDistributionPoint)obj;
059            }
060            else if (obj instanceof ASN1Sequence)
061            {
062                return new IssuingDistributionPoint((ASN1Sequence)obj);
063            }
064    
065            throw new IllegalArgumentException("unknown object in factory");
066        }
067    
068        /**
069         * Constructor from ASN1Sequence
070         */
071        public IssuingDistributionPoint(
072            ASN1Sequence  seq)
073        {
074            this.seq = seq;
075    
076            for (int i = 0; i != seq.size(); i++)
077            {
078                ASN1TaggedObject  o = (ASN1TaggedObject)seq.getObjectAt(i);
079    
080                switch (o.getTagNo())
081                {
082                case 0:
083                    break;
084                case 1:
085                    onlyContainsUserCerts = DERBoolean.getInstance(o, false).isTrue();
086                    break;
087                case 2:
088                    onlyContainsCACerts = DERBoolean.getInstance(o, false).isTrue();
089                    break;
090                case 3:
091                    break;
092                case 4:
093                    indirectCRL = DERBoolean.getInstance(o, false).isTrue();
094                    break;
095                case 5:
096                    onlyContainsAttributeCerts = DERBoolean.getInstance(o, false).isTrue();
097                    break;
098                default:
099                    throw new IllegalArgumentException("unknown tag in IssuingDistributionPoint");
100                }
101            }
102        }
103    
104        public boolean onlyContainsUserCerts()
105        {
106            return onlyContainsUserCerts;
107        }
108    
109        public boolean onlyContainsCACerts()
110        {
111            return onlyContainsCACerts;
112        }
113    
114        public boolean isIndirectCRL()
115        {
116            return indirectCRL;
117        }
118    
119        public boolean onlyContainsAttributeCerts()
120        {
121            return onlyContainsAttributeCerts;
122        }
123    
124        public DERObject toASN1Object()
125        {
126            return seq;
127        }
128    }