Skip to content

Type key encoding#13

Merged
kaidokert merged 3 commits intoyoutube:mainfrom
backkem:type-key-encoding
Jan 28, 2026
Merged

Type key encoding#13
kaidokert merged 3 commits intoyoutube:mainfrom
backkem:type-key-encoding

Conversation

@backkem
Copy link
Contributor

@backkem backkem commented Jan 25, 2026

Summary

  • Fix message type key encoding to use RFC 9000 varint instead of CBOR
  • Fix hostname encoding to use URL-safe base64 (no padding) for DNS compatibility

Details

Message encoding (Issue #8): The spec requires message format [varint type_key][CBOR body], but we were encoding
as [CBOR array][CBOR u16 type][CBOR body]. Fixed by using quinn_varint for type keys.

Hostname encoding (Issue #9): Standard base64 contains +, /, = which are invalid in DNS labels and TLS SNI.
Changed to URL_SAFE_NO_PAD encoding. See w3c/openscreenprotocol#365.

Type keys were incorrectly encoded as CBOR array [type, body].
Spec requires: [varint type key][CBOR body]
@gemini-code-assist
Copy link

Summary of Changes

Hello @backkem, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the data encoding strategies within the OpenScreen Protocol implementation. It specifically addresses a compatibility concern by adopting URL-safe Base64 for certificate serial numbers, making them suitable for use in DNS labels. Furthermore, it overhauls the network message serialization by introducing RFC 9000 variable-length integer encoding for message type keys, aligning the protocol's message structure more closely with its specification and improving efficiency by removing redundant CBOR array wrappers.

Highlights

  • URL-Safe Base64 for Serial Numbers: Switched certificate serial number encoding from standard Base64 to URL-safe Base64 without padding to ensure compatibility with DNS labels, resolving an identified specification issue.
  • RFC 9000 Variable-Length Integer Encoding: Implemented RFC 9000 variable-length integer encoding for message type keys, replacing the previous CBOR array wrapper structure for network messages.
  • Refactored Message Encoding/Decoding: Updated all authentication message types (AuthCapabilities, AuthSpake2Handshake, AuthSpake2Confirmation, AuthStatus) to use the new variable-length integer type key encoding, streamlining the message format.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the message encoding to use a variable-length integer for the type key, prefixed to the CBOR message body, instead of a CBOR array. It also correctly switches to URL-safe Base64 encoding for certificate serial numbers to ensure they are valid in DNS labels. The changes are logical and well-motivated. I've found one critical issue that will prevent compilation due to an API change in a dependency, and one medium-severity issue related to code structure and efficiency. My detailed feedback is in the comments below.

Standard base64 contains +/= which are invalid in DNS labels.
Use URL_SAFE_NO_PAD encoding per w3c/openscreenprotocol#365.
@backkem
Copy link
Contributor Author

backkem commented Jan 25, 2026

PTAL @kaidokert

@kaidokert
Copy link
Member

Thank you - looks like a good fix.

But that CBOR-array encoding is much more widespread, for all other app level messages too, i'll do a follow-up fix. I had completely misinterpreted the type key encoding

@backkem
Copy link
Contributor Author

backkem commented Jan 26, 2026

Fixed lint & did the application messages while at it.

@backkem
Copy link
Contributor Author

backkem commented Jan 27, 2026

Sorry for the back-n-forth. I realize I normally rely a bit too much on just running the CI a couple times 😅 Will do better.

@kaidokert
Copy link
Member

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly implements two important fixes: using RFC 9000 varint for message type key encoding and URL-safe base64 for hostnames. The changes are well-implemented, especially the refactoring of decode logic into decode_body functions, which fixes a bug in the previous implementation where the full buffer was passed for body decoding. The use of URL_SAFE_NO_PAD for base64 encoding is also correct for DNS compatibility. I have one suggestion to reduce code duplication for the new helper functions.

@kaidokert kaidokert merged commit c70fb2a into youtube:main Jan 28, 2026
4 checks passed
@backkem backkem deleted the type-key-encoding branch January 28, 2026 08:08
@kaidokert
Copy link
Member

Thanks a lot ! This was very off spec

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 this pull request may close these issues.

2 participants