x11_dehexify.c 626 B

123456789101112131415161718192021222324252627282930
  1. /*
  2. * Utility function to convert a textual representation of an X11
  3. * auth hex cookie into binary auth data.
  4. */
  5. #include "putty.h"
  6. #include "ssh.h"
  7. void *x11_dehexify(ptrlen hexpl, int *outlen)
  8. {
  9. int len, i;
  10. unsigned char *ret;
  11. len = hexpl.len / 2;
  12. ret = snewn(len, unsigned char);
  13. for (i = 0; i < len; i++) {
  14. char bytestr[3];
  15. unsigned val = 0;
  16. bytestr[0] = ((const char *)hexpl.ptr)[2*i];
  17. bytestr[1] = ((const char *)hexpl.ptr)[2*i+1];
  18. bytestr[2] = '\0';
  19. sscanf(bytestr, "%x", &val);
  20. ret[i] = val;
  21. }
  22. *outlen = len;
  23. return ret;
  24. }