예제 #1
0
  void encode(ASN1OutputStream out) throws IOException {
    if (!empty) {
      ASN1Primitive primitive = obj.toASN1Primitive().toDERObject();

      if (explicit) {
        out.writeTag(BERTags.CONSTRUCTED | BERTags.TAGGED, tagNo);
        out.writeLength(primitive.encodedLength());
        out.writeObject(primitive);
      } else {
        //
        // need to mark constructed types...
        //
        int flags;
        if (primitive.isConstructed()) {
          flags = BERTags.CONSTRUCTED | BERTags.TAGGED;
        } else {
          flags = BERTags.TAGGED;
        }

        out.writeTag(flags, tagNo);
        out.writeImplicitObject(primitive);
      }
    } else {
      out.writeEncoded(BERTags.CONSTRUCTED | BERTags.TAGGED, tagNo, ZERO_BYTES);
    }
  }
예제 #2
0
  boolean isConstructed() {
    if (!empty) {
      if (explicit) {
        return true;
      } else {
        ASN1Primitive primitive = obj.toASN1Primitive().toDERObject();

        return primitive.isConstructed();
      }
    } else {
      return true;
    }
  }
예제 #3
0
 void writeImplicitObject(ASN1Primitive obj) throws IOException {
   if (obj != null) {
     obj.encode(new ImplicitOutputStream(os));
   } else {
     throw new IOException("null object detected");
   }
 }
예제 #4
0
  int encodedLength() throws IOException {
    if (!empty) {
      ASN1Primitive primitive = obj.toASN1Primitive().toDERObject();
      int length = primitive.encodedLength();

      if (explicit) {
        return StreamUtil.calculateTagLength(tagNo)
            + StreamUtil.calculateBodyLength(length)
            + length;
      } else {
        // header length already in calculation
        length = length - 1;

        return StreamUtil.calculateTagLength(tagNo) + length;
      }
    } else {
      return StreamUtil.calculateTagLength(tagNo) + 1;
    }
  }