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.ASN1Sequence;
022    import org.apache.geronimo.crypto.asn1.ASN1TaggedObject;
023    import org.apache.geronimo.crypto.asn1.DERBoolean;
024    import org.apache.geronimo.crypto.asn1.DERObject;
025    
026    /**
027     * IssuingDistributionPoint ::= SEQUENCE {
028     *      distributionPoint          [0] DistributionPointName OPTIONAL,
029     *      onlyContainsUserCerts      [1] BOOLEAN DEFAULT FALSE,
030     *      onlyContainsCACerts        [2] BOOLEAN DEFAULT FALSE,
031     *      onlySomeReasons            [3] ReasonFlags OPTIONAL,
032     *      indirectCRL                [4] BOOLEAN DEFAULT FALSE,
033     *      onlyContainsAttributeCerts [5] BOOLEAN DEFAULT FALSE }
034     */
035    public class IssuingDistributionPoint
036        extends ASN1Encodable
037    {
038        private boolean         onlyContainsUserCerts;
039        private boolean         onlyContainsCACerts;
040        private boolean         indirectCRL;
041        private boolean         onlyContainsAttributeCerts;
042    
043        private ASN1Sequence    seq;
044    
045        public static IssuingDistributionPoint getInstance(
046            ASN1TaggedObject obj,
047            boolean          explicit)
048        {
049            return getInstance(ASN1Sequence.getInstance(obj, explicit));
050        }
051    
052        public static IssuingDistributionPoint getInstance(
053            Object  obj)
054        {
055            if (obj == null || obj instanceof IssuingDistributionPoint)
056            {
057                return (IssuingDistributionPoint)obj;
058            }
059            else if (obj instanceof ASN1Sequence)
060            {
061                return new IssuingDistributionPoint((ASN1Sequence)obj);
062            }
063    
064            throw new IllegalArgumentException("unknown object in factory");
065        }
066    
067        /**
068         * Constructor from ASN1Sequence
069         */
070        public IssuingDistributionPoint(
071            ASN1Sequence  seq)
072        {
073            this.seq = seq;
074    
075            for (int i = 0; i != seq.size(); i++)
076            {
077                ASN1TaggedObject  o = (ASN1TaggedObject)seq.getObjectAt(i);
078    
079                switch (o.getTagNo())
080                {
081                case 0:
082                    break;
083                case 1:
084                    onlyContainsUserCerts = DERBoolean.getInstance(o, false).isTrue();
085                    break;
086                case 2:
087                    onlyContainsCACerts = DERBoolean.getInstance(o, false).isTrue();
088                    break;
089                case 3:
090                    break;
091                case 4:
092                    indirectCRL = DERBoolean.getInstance(o, false).isTrue();
093                    break;
094                case 5:
095                    onlyContainsAttributeCerts = DERBoolean.getInstance(o, false).isTrue();
096                    break;
097                default:
098                    throw new IllegalArgumentException("unknown tag in IssuingDistributionPoint");
099                }
100            }
101        }
102    
103        public boolean onlyContainsUserCerts()
104        {
105            return onlyContainsUserCerts;
106        }
107    
108        public boolean onlyContainsCACerts()
109        {
110            return onlyContainsCACerts;
111        }
112    
113        public boolean isIndirectCRL()
114        {
115            return indirectCRL;
116        }
117    
118        public boolean onlyContainsAttributeCerts()
119        {
120            return onlyContainsAttributeCerts;
121        }
122    
123        public DERObject toASN1Object()
124        {
125            return seq;
126        }
127    }