|There's more than one way to do things|
Perl strings questionsby bliako (Monsignor)
|on Jun 02, 2021 at 07:58 UTC||Need Help??|
bliako has asked for the wisdom of the Perl Monks concerning the following question:
I know that in a Perl string the 0x0 character has no special meaning (unlike C) and so one can mix binary data (range 0-255, i.e. it may contain 0x0) with a "normal printed" string (i.e. with chars in 1-127) and unicode strings. So, the following will work(?):
1) Is this the correct way to do this?
2) Also, I have a question about why I need to encode in "UTF-8". Does that make sure that the "double-bytes" and possible "single-bytes" are all becoming a stream of "single-bytes"?
3) How do I treat the $buffer, in Perl, before I do a POST and GET, assuming the receiver is liberal in what it accepts? Obviously a base64 is safe but under what conditions can I send $unicode_string as is. Will sending $buffer (as is, after treated with Encode) work?
4) Is Encode::encode("UTF-8", $sha256) altering my binary data? Is it harmful on strings with binary data?
(please correct my terminology and feel free to correct it, I tried to avoid encodings for too long - note also that I am trying to find the safe way to do things when strings are mixed, i don't have a particular requirement)
EDIT: Actually, I am trying to translate some python code into Perl (see https://docs.kraken.com/rest/#section/Authentication/Headers-and-Signature):
And (@haj) I wanted to mix binary and non-binary strings like they do in message. I ended up with: