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); } }
boolean isConstructed() { if (!empty) { if (explicit) { return true; } else { ASN1Primitive primitive = obj.toASN1Primitive().toDERObject(); return primitive.isConstructed(); } } else { return true; } }
void writeImplicitObject(ASN1Primitive obj) throws IOException { if (obj != null) { obj.encode(new ImplicitOutputStream(os)); } else { throw new IOException("null object detected"); } }
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; } }