1 /**
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one or more
4 * contributor license agreements. See the NOTICE file distributed with
5 * this work for additional information regarding copyright ownership.
6 * The ASF licenses this file to You under the Apache License, Version 2.0
7 * (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 package org.apache.geronimo.util.asn1.x509;
20
21 import org.apache.geronimo.util.asn1.ASN1Encodable;
22 import org.apache.geronimo.util.asn1.ASN1EncodableVector;
23 import org.apache.geronimo.util.asn1.ASN1Sequence;
24 import org.apache.geronimo.util.asn1.ASN1TaggedObject;
25 import org.apache.geronimo.util.asn1.DERBitString;
26 import org.apache.geronimo.util.asn1.DERInteger;
27 import org.apache.geronimo.util.asn1.DERObject;
28 import org.apache.geronimo.util.asn1.DERSequence;
29
30 public class IssuerSerial
31 extends ASN1Encodable
32 {
33 GeneralNames issuer;
34 DERInteger serial;
35 DERBitString issuerUID;
36
37 public static IssuerSerial getInstance(
38 Object obj)
39 {
40 if (obj == null || obj instanceof GeneralNames)
41 {
42 return (IssuerSerial)obj;
43 }
44
45 if (obj instanceof ASN1Sequence)
46 {
47 return new IssuerSerial((ASN1Sequence)obj);
48 }
49
50 throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
51 }
52
53 public static IssuerSerial getInstance(
54 ASN1TaggedObject obj,
55 boolean explicit)
56 {
57 return getInstance(ASN1Sequence.getInstance(obj, explicit));
58 }
59
60 public IssuerSerial(
61 ASN1Sequence seq)
62 {
63 issuer = GeneralNames.getInstance(seq.getObjectAt(0));
64 serial = (DERInteger)seq.getObjectAt(1);
65
66 if (seq.size() == 3)
67 {
68 issuerUID = (DERBitString)seq.getObjectAt(2);
69 }
70 }
71
72 public IssuerSerial(
73 GeneralNames issuer,
74 DERInteger serial)
75 {
76 this.issuer = issuer;
77 this.serial = serial;
78 }
79
80 public GeneralNames getIssuer()
81 {
82 return issuer;
83 }
84
85 public DERInteger getSerial()
86 {
87 return serial;
88 }
89
90 public DERBitString getIssuerUID()
91 {
92 return issuerUID;
93 }
94
95 /**
96 * Produce an object suitable for an ASN1OutputStream.
97 * <pre>
98 * IssuerSerial ::= SEQUENCE {
99 * issuer GeneralNames,
100 * serial CertificateSerialNumber,
101 * issuerUID UniqueIdentifier OPTIONAL
102 * }
103 * </pre>
104 */
105 public DERObject toASN1Object()
106 {
107 ASN1EncodableVector v = new ASN1EncodableVector();
108
109 v.add(issuer);
110 v.add(serial);
111
112 if (issuerUID != null)
113 {
114 v.add(issuerUID);
115 }
116
117 return new DERSequence(v);
118 }
119 }