forslund / combo-lock

Apache License 2.0
4 stars 1 forks source link

Use base64 url and filename safe encoding as filename for named lock #6

Closed forslund closed 3 years ago

forslund commented 3 years ago

This will allow strings with weird characters, including paths to be used as names for NamedLock instances. Implementation uses the sha1 hex-digest of the name as filename. Resolves #5

JarbasAl commented 3 years ago

why not create the paths instead? ensures uniqueness and seems to be what the user intended

bad characters are also an issue, but is that something we should solve or "blame the user" and fail loudly?

not saying i oppose this change, it makes a lot of sense to me, just considering alternatives

forslund commented 3 years ago

Creating the paths could be quite elegant as well. The thing against it I can think of is handling of .. and . in the path. A name ../myLock would be created outside of the detected ram-disk folder and we can't know if there is write access...

NeonDaniel commented 3 years ago

why not create the paths instead? ensures uniqueness and seems to be what the user intended

bad characters are also an issue, but is that something we should solve or "blame the user" and fail loudly?

not saying i oppose this change, it makes a lot of sense to me, just considering alternatives

I like that the hashing is essentially a one-line change; the path would still require filtering invalid characters which could cause name conflicts with any attempt at static substitution... This could be changed to Base64 encoding instead of hashing if there was reason to get the original name out of the final path..

forslund commented 3 years ago

Hmm base64 is probably the better choice here. Will change the PR to that using "Base 64 Encoding with URL and Filename Safe Alphabet" which should be altchars='-_'