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

JSON conversion #349

Open
annevk opened this issue Jun 30, 2023 · 2 comments
Open

JSON conversion #349

annevk opened this issue Jun 30, 2023 · 2 comments

Comments

@annevk
Copy link
Member

annevk commented Jun 30, 2023

Let |bytes| be the byte sequence the results from converting |json|, a JavaScript String comprised of UTF-16 code points, to UTF-8 code points.

There's no such thing as UTF-8 code points.

Maybe you want https://infra.spec.whatwg.org/#serialize-a-javascript-value-to-json-bytes?

(Found while looking at #347.)

@twiss
Copy link
Member

twiss commented Aug 22, 2023

Hello 👋 Apologies for the (very) delayed response.

The spec intentionally doesn't require using JSON.stringify, and notes:

The key wrapping operations for some algorithms place constraints on the payload size. For example AES-KW requires the payload to be a multiple of 8 bytes in length and RSA-OAEP places a restriction on the length. For key formats that offer flexibility in serialization of a given key (for example JWK), implementations may choose to adapt the serialization to the constraints of the wrapping algorithm. This is why JSON.stringify is not normatively required, as otherwise it would prohibit implementations from introducing added padding.

That being said, I'm not aware of any implementation that does so, so we could probably change that.

But, I think the less invasive change to fix the issue you noted would be to just use https://encoding.spec.whatwg.org/#utf-8-encode for now, so I'll start by making a PR for that 😊

@annevk
Copy link
Member Author

annevk commented Aug 22, 2023

Sounds reasonable, but I'd very much appreciate the follow-up issue/discussion as well as I don't think we should have multiple JSON serializers in the platform. If we want to add padding we should mandate it across implementations and define where it happens relative to JSON serialization.

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