Home | History | Annotate | Download | only in asn1
      1 package com.android.hotspot2.asn1;
      2 
      3 import java.nio.ByteBuffer;
      4 import java.util.Collection;
      5 
      6 public class Asn1Octets extends Asn1Object {
      7     private final byte[] mOctets;
      8     private final int mBitResidual;
      9 
     10     public Asn1Octets(int tag, Asn1Class asn1Class, int length, ByteBuffer data) {
     11         super(tag, asn1Class, false, length);
     12         mOctets = new byte[length];
     13         data.get(mOctets);
     14         mBitResidual = -1;
     15     }
     16 
     17     public Asn1Octets(int tag, Asn1Class asn1Class, int length, ByteBuffer data, int bitResidual) {
     18         super(tag, asn1Class, false, length);
     19         mOctets = new byte[length - 1];
     20         data.get(mOctets);
     21         mBitResidual = bitResidual;
     22     }
     23 
     24     public byte[] getOctets() {
     25         return mOctets;
     26     }
     27 
     28     @Override
     29     public Collection<Asn1Object> getChildren() {
     30         throw new UnsupportedOperationException();
     31     }
     32 
     33     @Override
     34     public String toString() {
     35         StringBuilder sb = new StringBuilder();
     36         for (byte b : mOctets) {
     37             sb.append(String.format(" %02x", b & Asn1Decoder.ByteMask));
     38         }
     39         if (mBitResidual >= 0) {
     40             return super.toString() + '=' + sb + '/' + mBitResidual;
     41         } else if (getTag() == Asn1Decoder.TAG_NULL && getLength() == 0) {
     42             return super.toString();
     43         } else {
     44             return super.toString() + '=' + sb;
     45         }
     46     }
     47 }
     48