tink-crypto / tink

Tink is a multi-language, cross-platform, open source library that provides cryptographic APIs that are secure, easy to use correctly, and hard(er) to misuse.
https://developers.google.com/tink
Apache License 2.0
13.47k stars 1.18k forks source link

Support addIntegerClaim in RawJwt #690

Closed ningcng closed 1 year ago

ningcng commented 1 year ago

Is your feature request related to a problem? Yes

I want to add an integer claim 1, not a double claim 1.0. So RawJwt.addNumberclaim is not good.

What sort of feature would you like to see? RawJwt.addIntegerClaim()

Have you considered any alternative solutions? RawJwt.addJsonClaim()

Using RawJwt.addJsonClaim() to add an integer is clumsy.

juergw commented 1 year ago

JSON doesn't really distinguish between integers and floats. That's why we only support double. But I agree with you that it would be preferable to encode 1 as 1 and not as 1.0.

I have tested this in C++, Go and Python, and all of them encode 1 as "1", and not as "1.0". So we really should do the same in Java as well.

I think it would be best to simply overload "addNumberClaim" with a function that takes a long as argument. I tried it out and that works as expected. Would that resolve your issue?

juergw commented 1 year ago

This has now been added here:

https://github.com/tink-crypto/tink-java/commit/5f78d9a1118749cd9b42adcbc7c7e22a5890d69b