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

Util.fromHex() fails to reject invalid hex characters #67

Closed
15characterlimi opened this issue Jun 4, 2022 · 0 comments · Fixed by #68
Closed

Util.fromHex() fails to reject invalid hex characters #67

15characterlimi opened this issue Jun 4, 2022 · 0 comments · Fixed by #68

Comments

@15characterlimi
Copy link
Contributor

Expected Behavior

Util.fromHex("XX") throws IllegalArgumentException

Actual Behavior

Util.fromHex("XX") returns -17 (= 0xEF)

This is because Util.fromHex() is built on top of Character.digit(), and Character.digit('X', 16) returns -1.

I already have a commit to fix this, I'm just filing this issue first so I can reference it from my fix commit.

15characterlimi added a commit to 15characterlimi/identity-credential that referenced this issue Jun 4, 2022
This is because Character.digit('X', 16) returns -1 rather than throwing.

This commit changes the behavior to throw instead, by building on top of Integer.parseInt(). Note that Byte.parseByte() wouldn't work because it doesn't accept unsigned values >= 0x80.

While I was add it, I tweaked the check for odd numbers to be (what I consider) more idiomatic, and quote the offending length.

This commit fixes openwallet-foundation-labs#67
15characterlimi added a commit to 15characterlimi/identity-credential that referenced this issue Jun 4, 2022
This is because Character.digit('X', 16) returns -1 rather than throwing.

This commit changes the behavior to throw instead, by building on top of Integer.parseInt(). Note that Byte.parseByte() wouldn't work because it doesn't accept unsigned values >= 0x80.

While I was add it, I tweaked the check for odd numbers to be (what I consider) more idiomatic, and quote the offending length.

This commit fixes openwallet-foundation-labs#67
15characterlimi added a commit to 15characterlimi/identity-credential that referenced this issue Jun 8, 2022
This is because Character.digit('X', 16) returns -1 rather than throwing.

This commit changes the behavior to throw instead, by building on top of Integer.parseInt(). Note that Byte.parseByte() wouldn't work because it doesn't accept unsigned values >= 0x80.

While I was add it, I tweaked the check for odd numbers to be (what I consider) more idiomatic, and quote the offending length.

This commit fixes openwallet-foundation-labs#67
15characterlimi added a commit to 15characterlimi/identity-credential that referenced this issue Jun 8, 2022
This is because Character.digit('X', 16) returns -1 rather than throwing.

This commit changes the behavior to throw instead, by building on top of Integer.parseInt(). Note that Byte.parseByte() wouldn't work because it doesn't accept unsigned values >= 0x80.

While I was add it, I tweaked the check for odd numbers to be (what I consider) more idiomatic, and quote the offending length.

This commit fixes openwallet-foundation-labs#67
sethmoo pushed a commit that referenced this issue Jun 9, 2022
This is because Character.digit('X', 16) returns -1 rather than throwing.

This commit changes the behavior to throw instead, by building on top of Integer.parseInt(). Note that Byte.parseByte() wouldn't work because it doesn't accept unsigned values >= 0x80.

While I was add it, I tweaked the check for odd numbers to be (what I consider) more idiomatic, and quote the offending length.

This commit fixes #67
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

Successfully merging a pull request may close this issue.

1 participant