1package org.bouncycastle.asn1; 2 3import java.io.IOException; 4 5/** 6 * Carrier class for a DER encoding OCTET STRING 7 */ 8public class DEROctetString 9 extends ASN1OctetString 10{ 11 /** 12 * Base constructor. 13 * 14 * @param string the octets making up the octet string. 15 */ 16 public DEROctetString( 17 byte[] string) 18 { 19 super(string); 20 } 21 22 /** 23 * Constructor from the encoding of an ASN.1 object. 24 * 25 * @param obj the object to be encoded. 26 */ 27 public DEROctetString( 28 ASN1Encodable obj) 29 throws IOException 30 { 31 super(obj.toASN1Primitive().getEncoded(ASN1Encoding.DER)); 32 } 33 34 boolean isConstructed() 35 { 36 return false; 37 } 38 39 int encodedLength() 40 { 41 return 1 + StreamUtil.calculateBodyLength(string.length) + string.length; 42 } 43 44 void encode( 45 ASN1OutputStream out) 46 throws IOException 47 { 48 out.writeEncoded(BERTags.OCTET_STRING, string); 49 } 50 51 static void encode( 52 DEROutputStream derOut, 53 byte[] bytes) 54 throws IOException 55 { 56 derOut.writeEncoded(BERTags.OCTET_STRING, bytes); 57 } 58} 59