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.util.asn1.x509;
019
020 import org.apache.geronimo.util.asn1.ASN1Encodable;
021 import org.apache.geronimo.util.asn1.ASN1EncodableVector;
022 import org.apache.geronimo.util.asn1.ASN1Sequence;
023 import org.apache.geronimo.util.asn1.ASN1TaggedObject;
024 import org.apache.geronimo.util.asn1.DERBitString;
025 import org.apache.geronimo.util.asn1.DERInteger;
026 import org.apache.geronimo.util.asn1.DERObject;
027 import org.apache.geronimo.util.asn1.DERSequence;
028
029 public class IssuerSerial
030 extends ASN1Encodable
031 {
032 GeneralNames issuer;
033 DERInteger serial;
034 DERBitString issuerUID;
035
036 public static IssuerSerial getInstance(
037 Object obj)
038 {
039 if (obj == null || obj instanceof GeneralNames)
040 {
041 return (IssuerSerial)obj;
042 }
043
044 if (obj instanceof ASN1Sequence)
045 {
046 return new IssuerSerial((ASN1Sequence)obj);
047 }
048
049 throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
050 }
051
052 public static IssuerSerial getInstance(
053 ASN1TaggedObject obj,
054 boolean explicit)
055 {
056 return getInstance(ASN1Sequence.getInstance(obj, explicit));
057 }
058
059 public IssuerSerial(
060 ASN1Sequence seq)
061 {
062 issuer = GeneralNames.getInstance(seq.getObjectAt(0));
063 serial = (DERInteger)seq.getObjectAt(1);
064
065 if (seq.size() == 3)
066 {
067 issuerUID = (DERBitString)seq.getObjectAt(2);
068 }
069 }
070
071 public IssuerSerial(
072 GeneralNames issuer,
073 DERInteger serial)
074 {
075 this.issuer = issuer;
076 this.serial = serial;
077 }
078
079 public GeneralNames getIssuer()
080 {
081 return issuer;
082 }
083
084 public DERInteger getSerial()
085 {
086 return serial;
087 }
088
089 public DERBitString getIssuerUID()
090 {
091 return issuerUID;
092 }
093
094 /**
095 * Produce an object suitable for an ASN1OutputStream.
096 * <pre>
097 * IssuerSerial ::= SEQUENCE {
098 * issuer GeneralNames,
099 * serial CertificateSerialNumber,
100 * issuerUID UniqueIdentifier OPTIONAL
101 * }
102 * </pre>
103 */
104 public DERObject toASN1Object()
105 {
106 ASN1EncodableVector v = new ASN1EncodableVector();
107
108 v.add(issuer);
109 v.add(serial);
110
111 if (issuerUID != null)
112 {
113 v.add(issuerUID);
114 }
115
116 return new DERSequence(v);
117 }
118 }