8000 style: spell out constants used in crypto interfaces by ppannuto · Pull Request #4443 · tock/tock · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

style: spell out constants used in crypto interfaces #4443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ppannuto
Copy link
Member

Pull Request Overview

This is inspired by the impending addition of yet one more _L constant. I was going to suggest writing things out as a clearer alternative on that PR, but realized it was really just following the existing style.

While it is generally [*] convention to use single letters for trait bounds, the same isn't quite as universal for const generics. Our Style Guide prefers descriptive names. This feels like a use case where there isn't huge overhead in physical space on the screen from writing these out, and there is much more clarity in reading standalone use, especially as uses get further from the defining/explaining site in the HIL. I went _LEN in favor of _LENGTH following a general preference for len in Rust.

[*] In my ever-so-humble-opinion, a terrible convention

Testing Strategy

This pull request was tested by compiling.

TODO or Help Wanted

Vibes check? Am I just being curmudgeonly about a Rust-ism with single-letter nonsense, or do others also feel this improves the readability? [Again, especially with an expectation of yet more _L constants coming]

Documentation Updated

  • Updated the relevant files in /docs, or no updates are required.

Formatting

  • Ran make prepush.

@bradjc
Copy link
Contributor
bradjc commented May 21, 2025

I personally don't mind the H + HL convention. I do think HASH_LEN is more clear. We also need to decide what to do in the digest and entropy HILs.

@ppannuto
Copy link
Member Author

Here's what things look like if you expand H to HashKind and S to SignatureKind as well: https://github.com/tock/tock/compare/write-out-crypto-types-too?expand=1

I do favor that, though I cede the point that it is more verbose

lschuermann
lschuermann previously approved these changes Jun 16, 2025
Copy link
Member
@lschuermann lschuermann left a comment

Choose a reason for hiding this comment

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

I think this is a solid improvement.

While it is generally [*] convention to use single letters for trait bounds

I believe I've seen a fair share of examples where trait bounds were camel-case identifiers, esp. where there is ambiguity. In the diff most trait implementations or type definitions that contain generic trait bounds are split over multiple lines anyways, so I'd be totally happy to see these be expanded as well.

But this alone is a good improvement in on itself, and I don't feel particularly strongly about the single-letter trait bounds.

ppannuto added 2 commits June 16, 2025 14:41
In accordance with the [Style Guide](doc/Style.md#using-descriptive-names),
replace the two-letter constants with spelled out versions for `HASH_LEN`
and `SIGNATURE_LEN` in crypto interfaces. `_LEN` is chosen in favor of
`_LENGTH` following a general prefernce for `len` in Rust.
10000
@ppannuto ppannuto force-pushed the write-out-crypto-constants branch from eef0110 to 7af2dbe Compare June 16, 2025 21:50
@github-actions github-actions bot added the HIL This affects a Tock HIL interface. label Jun 16, 2025
@ppannuto
Copy link
Member Author

Rebased and pulled in the changes from the branch which updates the types too.


We also need to decide what to do in the digest and entropy HILs.

I updated the digest HIL to match, I don't think there's anything relevant in the entropy HIL at the moment.

Comment on lines +31 to +32
SignatureKind,
HashKind,
Copy link
Member

Choose a reason for hiding this comment

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

Might be nitpicky, but these fields don't really refer to a SignatureKind "marker" as much as they refer to a Signer "component" that actually does work, right? Same for HashKind -> Hasher?

I'm slightly confused by the Kind part in the generic's name, but it's not a big deal either way.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a good nitpick to discuss, the whole point is clarity from more explicit names.

This is also definitely a case of Pat might be learning Rust via PR discussions... but my rationale for the current naming was that, IIUC, this is ultimately the placeholder label for a type. E.g., looking at the documentation explaining bounds this would be a "generic type SignatureKind". I used "Kind" in lieu of "Type" as I thought that was a common convention for avoiding complexity around "Type" as a keyword, though maybe it is not needed here.

Would SignerType (and HasherType) make more sense?

Copy link
Member
@lschuermann lschuermann Jun 17, 2025

Choose a reason for hiding this comment

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

Ah, yes, this clears up some confusion on my end. In short:

Would SignerType (and HasherType) make more sense?

Yes, but I think the Type-part is redundant.

While type is massively overloaded, I don't believe kind qualifies as a good substitute in this case. When I read SignatureKind, I'm thinking of "Ed25519 vs. RSA Signatures". Which is kind of what we're allowing to be switched out here, except it misses the point. The generic placeholder name will be filled in with an actual component Type computing a signature of a given "kind", and not just a Type that indicates a "kind" of an asymmetric signature. (re-reading this, it's still confusing, sorry!)

As for Type being overloaded: I think it's fairly obvious to most experienced Rust developers that these CamelCase placeholders (perhaps maybe less so than non-single-character names) are generic placeholders for types. These are also easily distinguishable from const generics, which are conventionally spelled out in MACRO_CASE. Adding an explicit Type or Kind suffix, to me, confuses more than it helps.

Copy link
Contributor
@bradjc bradjc left a comment

Choose a reason for hiding this comment

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

I understand spelling out the constants (per the title) but why are the type names changing?

@lschuermann
Copy link
Member

I don't think any type names are changing, just constants and generics placeholders.

But yes, this now goes beyond constants, and thus the PR title / description no longer accurately matches this changeset.

@bradjc
Copy link
Contributor
bradjc commented Jun 19, 2025

I don't think any type names are changing, just constants and generics placeholders.

I guess I'm referring to the generics placeholders, which I don't think we should start changing now.

@lschuermann
Copy link
Member

Do you object to these changes at all, or just as part of this PR mixed in with the other changes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component HIL This affects a Tock HIL interface. kernel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0