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.ASN1EncodableVector; 023 import org.apache.geronimo.util.asn1.ASN1Sequence; 024 import org.apache.geronimo.util.asn1.ASN1TaggedObject; 025 import org.apache.geronimo.util.asn1.DERBitString; 026 import org.apache.geronimo.util.asn1.DERObject; 027 import org.apache.geronimo.util.asn1.DERSequence; 028 import org.apache.geronimo.util.asn1.DERTaggedObject; 029 030 /** 031 * The DistributionPoint object. 032 * <pre> 033 * DistributionPoint ::= SEQUENCE { 034 * distributionPoint [0] DistributionPointName OPTIONAL, 035 * reasons [1] ReasonFlags OPTIONAL, 036 * cRLIssuer [2] GeneralNames OPTIONAL 037 * } 038 * </pre> 039 */ 040 public class DistributionPoint 041 extends ASN1Encodable 042 { 043 DistributionPointName distributionPoint; 044 ReasonFlags reasons; 045 GeneralNames cRLIssuer; 046 047 public static DistributionPoint getInstance( 048 ASN1TaggedObject obj, 049 boolean explicit) 050 { 051 return getInstance(ASN1Sequence.getInstance(obj, explicit)); 052 } 053 054 public static DistributionPoint getInstance( 055 Object obj) 056 { 057 if(obj == null || obj instanceof DistributionPoint) 058 { 059 return (DistributionPoint)obj; 060 } 061 062 if(obj instanceof ASN1Sequence) 063 { 064 return new DistributionPoint((ASN1Sequence)obj); 065 } 066 067 throw new IllegalArgumentException("Invalid DistributionPoint: " + obj.getClass().getName()); 068 } 069 070 public DistributionPoint( 071 ASN1Sequence seq) 072 { 073 for (int i = 0; i != seq.size(); i++) 074 { 075 ASN1TaggedObject t = (ASN1TaggedObject)seq.getObjectAt(i); 076 switch (t.getTagNo()) 077 { 078 case 0: 079 distributionPoint = DistributionPointName.getInstance(t, true); 080 break; 081 case 1: 082 reasons = new ReasonFlags(DERBitString.getInstance(t, false)); 083 break; 084 case 2: 085 cRLIssuer = GeneralNames.getInstance(t, false); 086 } 087 } 088 } 089 090 public DistributionPoint( 091 DistributionPointName distributionPoint, 092 ReasonFlags reasons, 093 GeneralNames cRLIssuer) 094 { 095 this.distributionPoint = distributionPoint; 096 this.reasons = reasons; 097 this.cRLIssuer = cRLIssuer; 098 } 099 100 public DistributionPointName getDistributionPoint() 101 { 102 return distributionPoint; 103 } 104 105 public ReasonFlags getReasons() 106 { 107 return reasons; 108 } 109 110 public GeneralNames getCRLIssuer() 111 { 112 return cRLIssuer; 113 } 114 115 public DERObject toASN1Object() 116 { 117 ASN1EncodableVector v = new ASN1EncodableVector(); 118 119 if (distributionPoint != null) 120 { 121 // 122 // as this is a CHOICE it must be explicitly tagged 123 // 124 v.add(new DERTaggedObject(0, distributionPoint)); 125 } 126 127 if (reasons != null) 128 { 129 v.add(new DERTaggedObject(false, 1, reasons)); 130 } 131 132 if (cRLIssuer != null) 133 { 134 v.add(new DERTaggedObject(false, 2, cRLIssuer)); 135 } 136 137 return new DERSequence(v); 138 } 139 }