Skip to content

Rewrite AutocryptHeader and AutocryptGossipHeader in Kotlin instead of Java#9759

Merged
rafaeltonholo merged 5 commits intothunderbird:mainfrom
shamim-emon:fix-issue-9758
Sep 9, 2025
Merged

Rewrite AutocryptHeader and AutocryptGossipHeader in Kotlin instead of Java#9759
rafaeltonholo merged 5 commits intothunderbird:mainfrom
shamim-emon:fix-issue-9758

Conversation

@shamim-emon
Copy link
Collaborator

@shamim-emon shamim-emon commented Sep 8, 2025

  • Fixes Rewrite AutocryptHeader and AutocryptGossipHeader in Kotlin instead of Java #9758
  • Summary : This PR refactors the existing AutocryptHeader and AutocryptGossipHeader classes from Java into idiomatic Kotlin. The conversion simplifies code, enhances null safety, and leverages Kotlin’s modern language features.
  • Implementation Highlights:
    • AutocryptHeader.kt:
      • Rewritten as a Kotlin class with primary constructor parameters:
        • parameters: Map<String, String>
        • addr: String
        • keyData: ByteArray
        • isPreferEncryptMutual: Boolean
      • toRawHeaderString() method builds the header string with support for folding base64 key data.
      • Overridden equals() and hashCode() methods based on Kotlin's conventions.
      • Companion object defines constants such as AUTOCRYPT_HEADER, AUTOCRYPT_PARAM_ADDR, and a helper createFoldedBase64KeyData() method for formatting
    • AutocryptGossipHeader.kt :
      • Defined as an internal data class:
        • Fields: addr: String, keyData: ByteArray
        • toRawHeaderString() method similar to AutocryptHeader
        • equals() and hashCode() override using contentEquals() and contentHashCode() for byte arrays
        • Companion object includes constants: AUTOCRYPT_GOSSIP_HEADER, AUTOCRYPT_PARAM_ADDR, AUTOCRYPT_PARAM_KEY_DATA
    • Updated references in codebase:
      • Minor adjustments in AutocryptOperations.java to accommodate Kotlin properties instead of Java getters: moved from autocryptHeader.getKeyData() to Kotlin-style property access autocryptHeader.keyData, and similarly for other fields
    • Test updates: Refactored AutocryptHeaderParserTest.java to reflect Kotlin property access instead of Java getter methods, ensuring test compatibility:
      • Replaced autocryptHeader.getAddr(), .getKeyData(), .getParameters() with Kotlin property access autocryptHeader.addr, .keyData, .parameters
      • Adjusted input stream handling for test resource loading (readFromResourceFile) to account for simpler method signature

Copy link
Member

@rafaeltonholo rafaeltonholo left a comment

Choose a reason for hiding this comment

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

Thanks for this contribution, there is just one point to address (spread operator) before merging this.

Copy link
Member

@rafaeltonholo rafaeltonholo left a comment

Choose a reason for hiding this comment

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

LGTM

@rafaeltonholo rafaeltonholo merged commit 4820dae into thunderbird:main Sep 9, 2025
4 checks passed
@shamim-emon shamim-emon deleted the fix-issue-9758 branch September 9, 2025 18:10
@thunderbird-botmobile thunderbird-botmobile bot added this to the Thunderbird 14 milestone Sep 9, 2025
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.

Rewrite AutocryptHeader and AutocryptGossipHeader in Kotlin instead of Java

2 participants