819
you are viewing a single comment's thread
view the rest of the comments
[-] frezik@midwest.social 4 points 20 hours ago

I'd like it better if things were designed to work together better.

Right now, I'm working on a password storage system using the password_hash crate. You need to provide the salt yourself; this is already a bit silly for not providing a simple default that just gives you 16 bytes from a CSPRNG, but let's continue.

You read the Salt struct documentation, and it talks about UUIDs being pretty good salts (well, using v4, anyway). So that pushes you toward the uuid crate, right? Except no. That crate doesn't produce formats that the functions on the Salt struct will accept, like base64. So maybe the uuid_b64 crate will do it? I don't think so, because that crate uses a URL-safe version of base64, and it's not clear Salt will take that, either.

You're now forced to use a cumbersome interface from the rand crate to make your salt. I'm still working through some of the "size not known at compile time" errors from this approach.

All of which would work better if there was a little thought into connecting the pieces together, or just providing a default salt generator that's going to do the right thing 90% of the time.

Don't get me started on how Actix hasn't thought through how automated testing is supposed to work.

[-] Kushan@lemmy.world 2 points 9 hours ago* (last edited 9 hours ago)

Am I correct in saying that you're used to languages that aren't type safe? Or at least not as strict about it.

Everything you're describing sounds more like you're struggling with type safety in general and I wouldn't say any of those packages are at fault, in fact I'd even go further and say they're like that by design.

The reason you don't actually want any of those separate packages to be more interoperable out of the box is because that would couple them together. That would mean dependencies on those packages, it would mean if it wanted to use something else then you'd be a bit stuck.

Like I'd question using a uuid as a salt, like it's fine and I get why they're suggesting it, but you can use anything as a salt so why couple yourself to a specific uuid library? Why couple yourself to uuids at all.

Side note: I'm guessing the reason the crate expects you to supply your own salt is because you need to also store the salt next to the password hash, if it generated the salt for you there's a chance you might ignore the salt and suddenly not be able to validate passwords.

Anyway....

The only way you could make these separate packages work dramatically together and without coupling them would be to use a universal type - probably a byte array - and at that point you lose most of the benefits of a strong type system. What are currently compile errors become runtime errors, which are much worse and harder to diagnose.

My suggestion to you would be to reframe your thinking a little, think less about how you can make different crates speak to each other and more about how you convert from one type to another - once you crack that, all of these integration problems will go away.

[-] frezik@midwest.social 1 points 4 hours ago* (last edited 4 hours ago)

None of this has much to do with type safety at all. A dynamically typed language might have a Salt object that has a constructor that takes a base64 string. If its common uuid library doesn't output base64, then you can't use it directly.

Nor does a specific uuid library matter much. It just needs to be able to output base64 strings, which is an uncommon uuid encoding, but it's out there.

Nor does type safety prevent providing a sensible default implementation.

The crate uses phc strings, which store the salt together with the hashed password, so no, it can handle it all on its own.

There was just no thought into how components work together.

this post was submitted on 08 Jan 2025
819 points (98.1% liked)

Programmer Humor

19910 readers
2168 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS