• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.bouncycastle.asn1;
2 
3 import java.io.IOException;
4 
5 /**
6  * Carrier class for a DER encoding OCTET STRING
7  */
8 public class DEROctetString
9     extends ASN1OctetString
10 {
11     /**
12      * Base constructor.
13      *
14      * @param string the octets making up the octet string.
15      */
DEROctetString( byte[] string)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      */
DEROctetString( ASN1Encodable obj)27     public DEROctetString(
28         ASN1Encodable obj)
29         throws IOException
30     {
31         super(obj.toASN1Primitive().getEncoded(ASN1Encoding.DER));
32     }
33 
isConstructed()34     boolean isConstructed()
35     {
36         return false;
37     }
38 
encodedLength()39     int encodedLength()
40     {
41         return 1 + StreamUtil.calculateBodyLength(string.length) + string.length;
42     }
43 
encode(ASN1OutputStream out, boolean withTag)44     void encode(ASN1OutputStream out, boolean withTag) throws IOException
45     {
46         out.writeEncoded(withTag, BERTags.OCTET_STRING, string);
47     }
48 
toDERObject()49     ASN1Primitive toDERObject()
50     {
51         return this;
52     }
53 
toDLObject()54     ASN1Primitive toDLObject()
55     {
56         return this;
57     }
58 
encode(ASN1OutputStream derOut, boolean withTag, byte[] buf, int off, int len)59     static void encode(ASN1OutputStream derOut, boolean withTag, byte[] buf, int off, int len) throws IOException
60     {
61         derOut.writeEncoded(withTag, BERTags.OCTET_STRING, buf, off, len);
62     }
63 }
64