1 package org.bouncycastle.cms; 2 3 import java.io.IOException; 4 import java.io.OutputStream; 5 import java.util.Iterator; 6 7 import org.bouncycastle.asn1.ASN1Encodable; 8 import org.bouncycastle.asn1.ASN1Encoding; 9 import org.bouncycastle.asn1.ASN1ObjectIdentifier; 10 import org.bouncycastle.asn1.ASN1Sequence; 11 12 public class PKCS7ProcessableObject 13 implements CMSTypedData 14 { 15 private final ASN1ObjectIdentifier type; 16 private final ASN1Encodable structure; 17 PKCS7ProcessableObject( ASN1ObjectIdentifier type, ASN1Encodable structure)18 public PKCS7ProcessableObject( 19 ASN1ObjectIdentifier type, 20 ASN1Encodable structure) 21 { 22 this.type = type; 23 this.structure = structure; 24 } 25 getContentType()26 public ASN1ObjectIdentifier getContentType() 27 { 28 return type; 29 } 30 write(OutputStream cOut)31 public void write(OutputStream cOut) 32 throws IOException, CMSException 33 { 34 if (structure instanceof ASN1Sequence) 35 { 36 ASN1Sequence s = ASN1Sequence.getInstance(structure); 37 38 for (Iterator it = s.iterator(); it.hasNext();) 39 { 40 ASN1Encodable enc = (ASN1Encodable)it.next(); 41 42 cOut.write(enc.toASN1Primitive().getEncoded(ASN1Encoding.DER)); 43 } 44 } 45 else 46 { 47 byte[] encoded = structure.toASN1Primitive().getEncoded(ASN1Encoding.DER); 48 int index = 1; 49 50 while ((encoded[index] & 0xff) > 127) 51 { 52 index++; 53 } 54 55 index++; 56 57 cOut.write(encoded, index, encoded.length - index); 58 } 59 } 60 getContent()61 public Object getContent() 62 { 63 return structure; 64 } 65 } 66