Skip to content

Comments

refactor(xmss): reduce duplication in leansig FFI layer#69

Open
Itodo-S wants to merge 3 commits intogeanlabs:mainfrom
Itodo-S:refactor/leansig-reduce-duplication
Open

refactor(xmss): reduce duplication in leansig FFI layer#69
Itodo-S wants to merge 3 commits intogeanlabs:mainfrom
Itodo-S:refactor/leansig-reduce-duplication

Conversation

@Itodo-S
Copy link
Collaborator

@Itodo-S Itodo-S commented Feb 20, 2026

Summary

Eliminates repeated boilerplate in the XMSS leansig bindings, both the Rust FFI library and the Go CGo layer, by extracting shared patterns into reusable helpers. Also bumps the genesis time in config.yaml.

Why

Both leansig-ffi/src/lib.rs and leansig/leansig.go had the same structural patterns repeated verbatim across multiple functions. The Rust match-on-deserialization pattern appeared 5 times, and the Go result-code-to-error mapping was duplicated identically in Verify and VerifyWithKeypair. This made the code harder to maintain and obscured the actual logic.

What Changed

xmss/leansig-ffi/src/lib.rs

  • Introduced a try_deserialize! macro that handles the match/Err(_) => return LeansigResult::DeserializationFailed pattern uniformly
  • Replaced 5 repetitive match blocks in leansig_keypair_restore, leansig_verify, and leansig_verify_with_keypair with macro invocations

xmss/leansig/leansig.go

  • Extracted a verifyResult helper that maps a C.LeansigResult code to a Go error
  • Collapsed the duplicated 3-branch if/if/return error translation in both Verify and VerifyWithKeypair into a single return verifyResult(...) call

@devylongs devylongs requested a review from dimka90 February 20, 2026 21:20
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.

1 participant