001package org.apache.commons.ssl.org.bouncycastle.asn1.dvcs; 002 003import java.math.BigInteger; 004 005import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Encodable; 006import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1EncodableVector; 007import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1GeneralizedTime; 008import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Integer; 009import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Object; 010import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Primitive; 011import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Sequence; 012import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1TaggedObject; 013import org.apache.commons.ssl.org.bouncycastle.asn1.DERSequence; 014import org.apache.commons.ssl.org.bouncycastle.asn1.DERTaggedObject; 015import org.apache.commons.ssl.org.bouncycastle.asn1.x509.Extensions; 016import org.apache.commons.ssl.org.bouncycastle.asn1.x509.GeneralNames; 017import org.apache.commons.ssl.org.bouncycastle.asn1.x509.PolicyInformation; 018 019/** 020 * <pre> 021 * DVCSRequestInformation ::= SEQUENCE { 022 * version INTEGER DEFAULT 1 , 023 * service ServiceType, 024 * nonce Nonce OPTIONAL, 025 * requestTime DVCSTime OPTIONAL, 026 * requester [0] GeneralNames OPTIONAL, 027 * requestPolicy [1] PolicyInformation OPTIONAL, 028 * dvcs [2] GeneralNames OPTIONAL, 029 * dataLocations [3] GeneralNames OPTIONAL, 030 * extensions [4] IMPLICIT Extensions OPTIONAL 031 * } 032 * </pre> 033 */ 034 035public class DVCSRequestInformation 036 extends ASN1Object 037{ 038 private int version = DEFAULT_VERSION; 039 private ServiceType service; 040 private BigInteger nonce; 041 private DVCSTime requestTime; 042 private GeneralNames requester; 043 private PolicyInformation requestPolicy; 044 private GeneralNames dvcs; 045 private GeneralNames dataLocations; 046 private Extensions extensions; 047 048 private static final int DEFAULT_VERSION = 1; 049 private static final int TAG_REQUESTER = 0; 050 private static final int TAG_REQUEST_POLICY = 1; 051 private static final int TAG_DVCS = 2; 052 private static final int TAG_DATA_LOCATIONS = 3; 053 private static final int TAG_EXTENSIONS = 4; 054 055 private DVCSRequestInformation(ASN1Sequence seq) 056 { 057 int i = 0; 058 059 if (seq.getObjectAt(0) instanceof ASN1Integer) 060 { 061 ASN1Integer encVersion = ASN1Integer.getInstance(seq.getObjectAt(i++)); 062 this.version = encVersion.getValue().intValue(); 063 } 064 else 065 { 066 this.version = 1; 067 } 068 069 this.service = ServiceType.getInstance(seq.getObjectAt(i++)); 070 071 while (i < seq.size()) 072 { 073 ASN1Encodable x = seq.getObjectAt(i); 074 075 if (x instanceof ASN1Integer) 076 { 077 this.nonce = ASN1Integer.getInstance(x).getValue(); 078 } 079 else if (x instanceof ASN1GeneralizedTime) 080 { 081 this.requestTime = DVCSTime.getInstance(x); 082 } 083 else if (x instanceof ASN1TaggedObject) 084 { 085 ASN1TaggedObject t = ASN1TaggedObject.getInstance(x); 086 int tagNo = t.getTagNo(); 087 088 switch (tagNo) 089 { 090 case TAG_REQUESTER: 091 this.requester = GeneralNames.getInstance(t, false); 092 break; 093 case TAG_REQUEST_POLICY: 094 this.requestPolicy = PolicyInformation.getInstance(ASN1Sequence.getInstance(t, false)); 095 break; 096 case TAG_DVCS: 097 this.dvcs = GeneralNames.getInstance(t, false); 098 break; 099 case TAG_DATA_LOCATIONS: 100 this.dataLocations = GeneralNames.getInstance(t, false); 101 break; 102 case TAG_EXTENSIONS: 103 this.extensions = Extensions.getInstance(t, false); 104 break; 105 } 106 } 107 else 108 { 109 this.requestTime = DVCSTime.getInstance(x); 110 } 111 112 i++; 113 } 114 } 115 116 public static DVCSRequestInformation getInstance(Object obj) 117 { 118 if (obj instanceof DVCSRequestInformation) 119 { 120 return (DVCSRequestInformation)obj; 121 } 122 else if (obj != null) 123 { 124 return new DVCSRequestInformation(ASN1Sequence.getInstance(obj)); 125 } 126 127 return null; 128 } 129 130 public static DVCSRequestInformation getInstance( 131 ASN1TaggedObject obj, 132 boolean explicit) 133 { 134 return getInstance(ASN1Sequence.getInstance(obj, explicit)); 135 } 136 137 public ASN1Primitive toASN1Primitive() 138 { 139 ASN1EncodableVector v = new ASN1EncodableVector(); 140 141 if (version != DEFAULT_VERSION) 142 { 143 v.add(new ASN1Integer(version)); 144 } 145 v.add(service); 146 if (nonce != null) 147 { 148 v.add(new ASN1Integer(nonce)); 149 } 150 if (requestTime != null) 151 { 152 v.add(requestTime); 153 } 154 155 int[] tags = new int[]{ 156 TAG_REQUESTER, 157 TAG_REQUEST_POLICY, 158 TAG_DVCS, 159 TAG_DATA_LOCATIONS, 160 TAG_EXTENSIONS 161 }; 162 ASN1Encodable[] taggedObjects = new ASN1Encodable[]{ 163 requester, 164 requestPolicy, 165 dvcs, 166 dataLocations, 167 extensions 168 }; 169 for (int i = 0; i < tags.length; i++) 170 { 171 int tag = tags[i]; 172 ASN1Encodable taggedObject = taggedObjects[i]; 173 if (taggedObject != null) 174 { 175 v.add(new DERTaggedObject(false, tag, taggedObject)); 176 } 177 } 178 179 return new DERSequence(v); 180 } 181 182 public String toString() 183 { 184 185 StringBuffer s = new StringBuffer(); 186 187 s.append("DVCSRequestInformation {\n"); 188 189 if (version != DEFAULT_VERSION) 190 { 191 s.append("version: " + version + "\n"); 192 } 193 s.append("service: " + service + "\n"); 194 if (nonce != null) 195 { 196 s.append("nonce: " + nonce + "\n"); 197 } 198 if (requestTime != null) 199 { 200 s.append("requestTime: " + requestTime + "\n"); 201 } 202 if (requester != null) 203 { 204 s.append("requester: " + requester + "\n"); 205 } 206 if (requestPolicy != null) 207 { 208 s.append("requestPolicy: " + requestPolicy + "\n"); 209 } 210 if (dvcs != null) 211 { 212 s.append("dvcs: " + dvcs + "\n"); 213 } 214 if (dataLocations != null) 215 { 216 s.append("dataLocations: " + dataLocations + "\n"); 217 } 218 if (extensions != null) 219 { 220 s.append("extensions: " + extensions + "\n"); 221 } 222 223 s.append("}\n"); 224 return s.toString(); 225 } 226 227 public int getVersion() 228 { 229 return version; 230 } 231 232 public ServiceType getService() 233 { 234 return service; 235 } 236 237 public BigInteger getNonce() 238 { 239 return nonce; 240 } 241 242 public DVCSTime getRequestTime() 243 { 244 return requestTime; 245 } 246 247 public GeneralNames getRequester() 248 { 249 return requester; 250 } 251 252 public PolicyInformation getRequestPolicy() 253 { 254 return requestPolicy; 255 } 256 257 public GeneralNames getDVCS() 258 { 259 return dvcs; 260 } 261 262 public GeneralNames getDataLocations() 263 { 264 return dataLocations; 265 } 266 267 public Extensions getExtensions() 268 { 269 return extensions; 270 } 271}