001package org.apache.commons.ssl.org.bouncycastle.asn1.ess; 002 003import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1EncodableVector; 004import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Object; 005import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Primitive; 006import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Sequence; 007import org.apache.commons.ssl.org.bouncycastle.asn1.DERSequence; 008import org.apache.commons.ssl.org.bouncycastle.asn1.x509.PolicyInformation; 009 010public class OtherSigningCertificate 011 extends ASN1Object 012{ 013 ASN1Sequence certs; 014 ASN1Sequence policies; 015 016 public static OtherSigningCertificate getInstance(Object o) 017 { 018 if (o instanceof OtherSigningCertificate) 019 { 020 return (OtherSigningCertificate) o; 021 } 022 else if (o != null) 023 { 024 return new OtherSigningCertificate(ASN1Sequence.getInstance(o)); 025 } 026 027 return null; 028 } 029 030 /** 031 * constructeurs 032 */ 033 private OtherSigningCertificate(ASN1Sequence seq) 034 { 035 if (seq.size() < 1 || seq.size() > 2) 036 { 037 throw new IllegalArgumentException("Bad sequence size: " 038 + seq.size()); 039 } 040 041 this.certs = ASN1Sequence.getInstance(seq.getObjectAt(0)); 042 043 if (seq.size() > 1) 044 { 045 this.policies = ASN1Sequence.getInstance(seq.getObjectAt(1)); 046 } 047 } 048 049 public OtherSigningCertificate( 050 OtherCertID otherCertID) 051 { 052 certs = new DERSequence(otherCertID); 053 } 054 055 public OtherCertID[] getCerts() 056 { 057 OtherCertID[] cs = new OtherCertID[certs.size()]; 058 059 for (int i = 0; i != certs.size(); i++) 060 { 061 cs[i] = OtherCertID.getInstance(certs.getObjectAt(i)); 062 } 063 064 return cs; 065 } 066 067 public PolicyInformation[] getPolicies() 068 { 069 if (policies == null) 070 { 071 return null; 072 } 073 074 PolicyInformation[] ps = new PolicyInformation[policies.size()]; 075 076 for (int i = 0; i != policies.size(); i++) 077 { 078 ps[i] = PolicyInformation.getInstance(policies.getObjectAt(i)); 079 } 080 081 return ps; 082 } 083 084 /** 085 * The definition of OtherSigningCertificate is 086 * <pre> 087 * OtherSigningCertificate ::= SEQUENCE { 088 * certs SEQUENCE OF OtherCertID, 089 * policies SEQUENCE OF PolicyInformation OPTIONAL 090 * } 091 * </pre> 092 * id-aa-ets-otherSigCert OBJECT IDENTIFIER ::= { iso(1) 093 * member-body(2) us(840) rsadsi(113549) pkcs(1) pkcs9(9) 094 * smime(16) id-aa(2) 19 } 095 */ 096 public ASN1Primitive toASN1Primitive() 097 { 098 ASN1EncodableVector v = new ASN1EncodableVector(); 099 100 v.add(certs); 101 102 if (policies != null) 103 { 104 v.add(policies); 105 } 106 107 return new DERSequence(v); 108 } 109}