Ejemplo n.º 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);
    }
  }
Ejemplo n.º 2
0
  /**
   * A note on the implementation:
   *
   * <p>As DL requires the constructed, definite-length model to be used for structured types, this
   * varies slightly from the ASN.1 descriptions given. Rather than just outputting SEQUENCE, we
   * also have to specify CONSTRUCTED, and the objects length.
   */
  void encode(ASN1OutputStream out) throws IOException {
    ASN1OutputStream dOut = out.getDLSubStream();
    int length = getBodyLength();

    out.write(BERTags.SEQUENCE | BERTags.CONSTRUCTED);
    out.writeLength(length);

    for (Enumeration e = this.getObjects(); e.hasMoreElements(); ) {
      Object obj = e.nextElement();

      dOut.writeObject((ASN1Encodable) obj);
    }
  }