diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2010-12-06 17:12:44 +0100 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2010-12-06 17:21:04 +0100 |
commit | 29902dcbbb9925cc0f4e3b4a2e8593717466fd95 (patch) | |
tree | 5c45aedf913a6e13ab1f79c8eb633ac873843d81 | |
parent | 87e93091861c7b427104542bdfa8a2cf888c619b (diff) | |
download | gnutls-29902dcbbb9925cc0f4e3b4a2e8593717466fd95.tar.gz |
simplified escape and unescape.
-rw-r--r-- | lib/gnutls_str.c | 22 |
1 files changed, 9 insertions, 13 deletions
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); } |