Skip to content

Add new feature use_sha for opt-in sha2 dependency - #2111

Open
jaewan-github wants to merge 1 commit into
Smithay:masterfrom
jaewan-github:feature/use_sha
Open

Add new feature use_sha for opt-in sha2 dependency#2111
jaewan-github wants to merge 1 commit into
Smithay:masterfrom
jaewan-github:feature/use_sha

Conversation

@jaewan-github

Copy link
Copy Markdown

Introduce a new opt-in feature 'use_sha' to enable the 'sha2' dependency and use Sha256 for keymap hashing.

When 'use_sha' is disabled (default), a custom hash function using built-in DefaultHasher is used instead, without 'sha2' dependency.

BREAKING CHANGE: If you want to keep the old behavior (using Sha256), you must explicitly enable the 'use_sha' feature. This breaking change is necessary because Cargo does not support excluding dependencies when a feature is enabled (features are strictly additive), so the dependency must be opt-in.

Tested:

  • cargo test --lib --no-default-features --features wayland_frontend (default, using builtin hash)
  • cargo test --lib --no-default-features --features wayland_frontend,use_sha (using Sha256)
  • Added 'test_keymap_file_creation' test to verify KeymapFile works.

Description

This adds a new use_sha feature and change default keymap id generation with chaining DefaultHasher.
To keep the old behavior explicit feature use_sha is required.

Note

This introduces breaking change. Tell me if you prefer not doing this, or completely remove the sha2 dependency

Motivation

sha2 crates brings huge dependency while smithay only uses it for generating good hash value.

It would be helpful to provide an option to opt-in the sha2 crate usage.

Existing Issue

#2110

I created the issue with bit more details.

Disclaimer about the AI uses

I haven't used AI for writing CL, but only used to proofread my commit message.

Checklist

@kelnos

kelnos commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Not sure what you mean about the feature situation. use_sha could be in default features, and then if you don't want it, pass --no-default-features (and then explicitly pass the features you do want). Or are you saying that even that won't remove the dependency? If so, that feels like a cargo bug...

@jaewan-github

Copy link
Copy Markdown
Author

Not sure what you mean about the feature situation. use_sha could be in default features, and then if you don't want it, pass --no-default-features (and then explicitly pass the features you do want). Or are you saying that even that won't remove the dependency? If so, that feels like a cargo bug...

Your understanding is correct. I'll follow your suggest to make use_sha as default.

@jaewan-github

Copy link
Copy Markdown
Author

Done as you suggested. It would be a great help if you take another look on this.

Introduce a new opt-in feature 'use_sha' to enable the 'sha2' dependency
and use Sha256 for keymap hashing. It's enabled by default to keep the
existing behavior.

When 'use_sha' is disabled, a custom hash function using DefaultHasher
is used instead, removing the dependency on 'sha2' crate.

BREAKING CHANGE: If you're not using default feature (i.e. Use
`--no-default-features`), then new hasing with built-in DefaultHasher
would be used. Explicitly specify 'use_sha' feature to keep the old
behavior.

Tested:
- cargo test --lib --no-default-features --features wayland_frontend (default, using builtin hash)
- cargo test --lib --no-default-features --features wayland_frontend,use_sha (using Sha256)
- Added 'test_keymap_file_creation' test to verify KeymapFile works.
@ids1024

ids1024 commented Jul 29, 2026

Copy link
Copy Markdown
Member

We might not need a use_sha2 feature here, if this method of hashing is effective for preventing unintentional collisions. I used sha2 since SipHash technically shouldn't be sufficient for that, and sha2 just seemed to be the most common hash crate (and was already in cosmic-comp's dependency tree).

Technically maybe a maliciously constructed keymap could be sent with virtual-keyboard-unstable-v1, but I'm not sure what that would achieve, and a client using that is already privileged.

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.

3 participants