The original implementation was converting to hex, whereas all we needed to do was to convert to characters and ensure ASCII-8BIT encoding.
ZATCA expects ASCII, the original implementation was assuming they were expecting hexadecimal versions of numbers, but the desired values are in ASCII.
This change ensures that the whole thing is forced to be ASCII-8BIT.
It was unclear from ZATCA if the value should be left as Unicode or not, but this presents a challenge because we would have to concatenate an ASCII string with a UTF-8 string and that's not possible.
We use String.force_encoding to ASCII-8BIT to get around those errors and avoid String#encode because it will throw an exception because you can't convert UTF-8 to ASCII-8BIT because there is no point of reference for what each character maps to.
This approach generates the same output as ZATCA's SDK does.
Summary
[x] Get character values of tag ID and value length
[x] Force TLV to be encoded in ASCII-8BIT (to work with Unicode strings)
Description
The original implementation was converting to hex, whereas all we needed to do was to convert to characters and ensure ASCII-8BIT encoding.
ZATCA expects ASCII, the original implementation was assuming they were expecting hexadecimal versions of numbers, but the desired values are in ASCII.
This change ensures that the whole thing is forced to be ASCII-8BIT.
It was unclear from ZATCA if the
value
should be left as Unicode or not, but this presents a challenge because we would have to concatenate an ASCII string with a UTF-8 string and that's not possible.We use
String.force_encoding
to ASCII-8BIT to get around those errors and avoidString#encode
because it will throw an exception because you can't convert UTF-8 to ASCII-8BIT because there is no point of reference for what each character maps to.This approach generates the same output as ZATCA's SDK does.
Summary
ASCII-8BIT
(to work with Unicode strings)