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