Make parse_token_uri_attr() use _pkcs11h_util_hexToBinary()

This requires removing the check for NUL termination, since that function
currently expects to convert *full* strings from hex to binary. But since
there is precisely one other caller, it's easy enough to make it check
for itself.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Add table of token ID fields for easier processing

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Use __token_fields table for serialization too

We were going through the same set of fields twice; once to calculate the
size of the string needed and a second time to actually generate it. This
way it's a whole lot less likely that the two will get out of sync.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Clean up legacy deserialization code paths

Remove the duplication and make the parse_pkcs11_url() function symmetrical
with the legacy parsing functions for token and certificate. This makes it
take the overall code paths for both types of string, which is nicer.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Remove hexchars[] array. Just use sprintf("%%02x"…) instead

Not quite sure what I was thinking... :)

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Merge token_attr_escaped_len() into token_attr_escape() and rename it

These functions were almost entirely duplication, and the previous commit
to make it use sprintf() made it clear that the differences were entirely
trivial. Just use a NULL string if we only want to count the amount of
space we'll need.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>