Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to get the byte representation of constructed tags #1

Open
martinpaljak opened this issue Oct 24, 2017 · 7 comments
Open

Comments

@martinpaljak
Copy link

No description provided.

@evsinev
Copy link
Owner

evsinev commented Oct 26, 2017

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));

@martinpaljak
Copy link
Author

OK, but maybe it would make sense to do this transparently, rather than throw when calling getBytes on a constructed tag?

@evsinev
Copy link
Owner

evsinev commented Nov 13, 2017

@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.

@martinpaljak
Copy link
Author

Some options:

  1. as the name implies, getBytes does not refer to value, rather "encoding". It would be OK to let the *Value methods to keep throwing
  2. Have a new method getByteEncoding()
  3. ... ?

@evsinev
Copy link
Owner

evsinev commented Nov 13, 2017

May be it would be better to create another method only for a constructed tag: getConstructedBytes()?

@martinpaljak
Copy link
Author

getContentBytes() could be universal for both types, no ?

@martinpaljak
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants