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