Skip to content

dataconnect(change): Internal refactor to use immutable byte arrays when calculating SHA512 hashes#7957

Merged
dconeybe merged 6 commits into
mainfrom
dconeybe/dataconnect/StructCalculateSha512Immutable
Mar 24, 2026
Merged

dataconnect(change): Internal refactor to use immutable byte arrays when calculating SHA512 hashes#7957
dconeybe merged 6 commits into
mainfrom
dconeybe/dataconnect/StructCalculateSha512Immutable

Conversation

@dconeybe
Copy link
Copy Markdown
Contributor

@dconeybe dconeybe commented Mar 23, 2026

This PR refactors the internal hashing logic within the firebase-dataconnect module by migrating from mutable byte arrays to ImmutableByteArray. This change reinforces the immutability of internally calculated SHA-512 hashes for Protobuf Struct and Value types, which are used to represent query IDs and variable hashes.

Highlights

  • Immutable Hash Representation: Updated the calculateSha512 extension functions for Struct and Value to return ImmutableByteArray instead of primitive ByteArray.
  • LiveQuery Improvements: Changed the type of the variablesHash field in LiveQuery.Key from String to ImmutableByteArray to leverage the new immutable return type.
  • Alphanumeric Conversion Overload: Added a new toAlphaNumericString() extension for ImmutableByteArray in AlphanumericStringUtil and fixed a documentation typo (base-32 instead of base-36).
  • Test Coverage: Expanded AlphanumericStringUtilUnitTest.kt with property-based testing to verify that the new toAlphaNumericString() extension function correctly formats ImmutableByteArrays without mutating the underlying array.
Changelog
  • CHANGELOG.md
    • Added an entry detailing the internal refactor to use immutable byte arrays.
  • DataConnectGrpcRPCs.kt
    • Updated query ID calculation to utilize the modified calculateSha512 function returning an ImmutableByteArray.
  • LiveQueries.kt
    • Updated the hash generation logic for variables to return ImmutableByteArray directly.
  • LiveQuery.kt
    • Changed the data type of variablesHash in LiveQuery.Key from String to ImmutableByteArray.
  • AlphanumericStringUtil.kt
    • Corrected documentation comment noting base-32 instead of base-36.
    • Added toAlphaNumericString() extension function for ImmutableByteArray.
  • ProtoUtil.kt
    • Changed the return type of calculateSha512 for Struct and Value to ImmutableByteArray.
  • AlphanumericStringUtilUnitTest.kt
    • Added unit tests verifying toAlphaNumericString() behavior and array safety for ImmutableByteArray.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

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

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.

@dconeybe
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

@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 refactors the codebase to consistently use ImmutableByteArray for SHA-512 digests and query IDs, enhancing immutability and type safety. This involves updating DataConnectGrpcRPCs, LiveQueries, LiveQuery, and ProtoUtil to directly handle ImmutableByteArray for hash values. New tests were added for ImmutableByteArray's alphanumeric string conversion. Feedback includes updating a changelog placeholder, using named arguments for LiveQuery.Key for improved readability and maintainability, and correcting the documentation for AlphanumericStringUtil.toAlphaNumericString to accurately describe the custom base-32 alphabet used.

Comment thread firebase-dataconnect/CHANGELOG.md Outdated
Base automatically changed from dconeybe/dataconnect/ChangelogMergeFixM178 to main March 23, 2026 21:20
@github-actions
Copy link
Copy Markdown
Contributor

📝 PRs merging into main branch

Our main branch should always be in a releasable state. If you are working on a larger change, or if you don't want this change to see the light of the day just yet, consider using a feature branch first, and only merge into the main branch when the code complete and ready to be released.

@dconeybe dconeybe marked this pull request as ready for review March 24, 2026 16:57
@dconeybe dconeybe merged commit 34f7e47 into main Mar 24, 2026
43 checks passed
@dconeybe dconeybe deleted the dconeybe/dataconnect/StructCalculateSha512Immutable branch March 24, 2026 18:16
@github-actions github-actions Bot mentioned this pull request Mar 26, 2026
@firebase firebase locked and limited conversation to collaborators Apr 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants