File: x11_dehexify.c

package info (click to toggle)
xtruss 0.0~git20241011.27fafffe-1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,172 kB
  • sloc: ansic: 17,121; sh: 20; makefile: 2
file content (28 lines) | stat: -rw-r--r-- 609 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
 * Utility function to convert a textual representation of an X11
 * auth hex cookie into binary auth data.
 */

#include "putty.h"

void *x11_dehexify(ptrlen hexpl, int *outlen)
{
    int len, i;
    unsigned char *ret;

    len = hexpl.len / 2;
    ret = snewn(len, unsigned char);

    for (i = 0; i < len; i++) {
        char bytestr[3];
        unsigned val = 0;
        bytestr[0] = ((const char *)hexpl.ptr)[2*i];
        bytestr[1] = ((const char *)hexpl.ptr)[2*i+1];
        bytestr[2] = '\0';
        sscanf(bytestr, "%x", &val);
        ret[i] = val;
    }

    *outlen = len;
    return ret;
}