Skip to content

The documentation should show an example of typical correct usage #122

@dpc

Description

@dpc

While it might seem obvious to people familiar with this crate, I am actually confused how to use this crate after just landing on it looking for a constant comparison crate.

What I want to do is:

if password_in_request != password_in_the_config {
   bail!("Wrong password");
}

for usual reasons.

I open https://docs.rs/subtle/ , I can see ConstantTimeEq and it is clear I should use ct_eq. But then ... why is it returning Choice? Am I supposed to call .into() on it? It seems so... ? But why can't ct_eq return bool right away by doing that .into() under the hood? Unclear.

So, it seems to me that the documentation can be improved in two ways:

  • Please add an idiomatic example on a front page of a correct usage. It will take one short paragraph and give an immediate answer to developers that are just looking for a solution.
  • Please somewhere early in the documentation of Choice explain why: Why does it exist, why can't ct_eq just return bool.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions