From: Nikos Mavrogiannopoulos Date: Mon, 6 Dec 2010 16:12:44 +0000 (+0100) Subject: simplified escape and unescape. X-Git-Tag: gnutls_2_11_5~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=29902dcbbb9925cc0f4e3b4a2e8593717466fd95;p=thirdparty%2Fgnutls.git simplified escape and unescape. --- diff --git a/lib/gnutls_str.c b/lib/gnutls_str.c index c8d2138667..7a3ef51b89 100644 --- a/lib/gnutls_str.c +++ b/lib/gnutls_str.c @@ -346,13 +346,10 @@ int _gnutls_buffer_escape (gnutls_buffer_st * dest, const char *const invalid_chars) { - static const char *x = "0123456789ABCDEF"; int rv = -1; char t[5]; int pos = 0; - /*_PKCS11H_ASSERT (target!=NULL); Not required*/ - while (pos < dest->length) { @@ -360,9 +357,7 @@ _gnutls_buffer_escape (gnutls_buffer_st * dest, || !isgraph (dest->data[pos])) { - t[0] = '%'; - t[1] = x[(dest->data[pos] & 0xf0) >> 4]; - t[2] = x[(dest->data[pos] & 0x0f) >> 0]; + snprintf(t, sizeof(t), "%%%.2X", (unsigned int)dest->data[pos]); _gnutls_buffer_delete_data (dest, pos, 1); @@ -389,21 +384,22 @@ _gnutls_buffer_unescape (gnutls_buffer_st * dest) int rv = -1; int pos = 0; - /*_PKCS11H_ASSERT (target!=NULL); Not required*/ - while (pos < dest->length) { if (dest->data[pos] == '%') { char b[3]; - unsigned u; - char x; + unsigned int u; + unsigned char x; + b[0] = dest->data[pos + 1]; b[1] = dest->data[pos + 2]; - b[2] = '\x0'; + b[2] = 0; + + sscanf (b, "%02x", &u); + + x = u; - sscanf (b, "%08x", &u); - x = u & 0xff; _gnutls_buffer_delete_data (dest, pos, 3); _gnutls_buffer_insert_data (dest, pos, &x, 1); }