ber-tlv
ber-tlv copied to clipboard
Add a way to get the byte representation of constructed tags
Hi,
You can use BerTlvBuilder for this. For example,
BerTlv constructedTag = new BerTlv(new BerTag(0xE4)
, Arrays.asList(new BerTlv(new BerTag(0x86), HexUtil.parseHex("ED3C3B8B03928D0E0012")))
);
BerTlvBuilder builder = new BerTlvBuilder();
builder.addBerTlv(constructedTag);
byte[] bytes = builder.buildArray();
System.out.println("bytes = " + HexUtil.toFormattedHexString(bytes));
OK, but maybe it would make sense to do this transparently, rather than throw when calling getBytes on a constructed tag?
@martinpaljak If we add getBytes() to constructed tags what should we do with other methods: getHexValue(), getTextValue(), getIntValue()? I've added this throw to prevent my errors when working with constructed/primitive tags.
Some options:
- as the name implies, getBytes does not refer to value, rather "encoding". It would be OK to let the *Value methods to keep throwing
- Have a new method getByteEncoding()
- ... ?
May be it would be better to create another method only for a constructed tag: getConstructedBytes()?
getContentBytes() could be universal for both types, no ?
Still getting back to this - the main reason for this is to be able to re-show the binary representation of what was parsed in a debug log, which would need to include the length of constructed tags. Would love to use your project in GlobalPlatformPro for this.