I'm trying to work with this Argon2 implementation. I'm implementing an existing protocol, so I don't have any flexibility in design, and the protocol treats various inputs to the function as byte sequences. However, that implementation treats inputs as String
s. Is there any encoding that I can use which will allow me to convert an arbitrary byte sequence to a String
without any validity constraints - that is, such that all possible byte sequences will convert without error?
Asked
Active
Viewed 112 times
1

joshlf
- 21,822
- 11
- 69
- 96
-
You could Base64 your arbitrary unstructured binary data into a valid ut8 representation, and then pass that in. It's odd that they made their algorithm operated on `String` instead of `Data`, but I guess it's acceptable since that hash algorithm is targeted at passwords in particular. – Alexander May 15 '20 at 00:32
-
Also, it looks like this code leaks all of the `cString`s it allocates, could you double check that if you get a chance? Just for my own curiosity – Alexander May 15 '20 at 00:49
-
Unfortunately I can't base64 encode; the protocol relies on the two parties hashing exactly the same data, so base64 encoding would break that. – joshlf May 15 '20 at 01:19
-
As for the leaking, I'm completely new to Swift (this is literally my first project), so I'll take your word on that :) – joshlf May 15 '20 at 01:19
-
Welcome to Swift :) Hmmm I'm afraid you might be SOL here. You could consider modifying the library to accept a `Data`. You can then make convenience methods that bridge to/from `String`, to make the library still act like it does today. You could then submit a pull requset to the repo, could be useful for others, too. Alternatively, you could just look for other implementations that already use a `Data`. – Alexander May 15 '20 at 01:24