]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
simplified escape and unescape.
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Mon, 6 Dec 2010 16:12:44 +0000 (17:12 +0100)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Mon, 6 Dec 2010 16:21:04 +0000 (17:21 +0100)
lib/gnutls_str.c

index c8d2138667e214e524934464099850a07a9526a7..7a3ef51b895c97bb99ad57c46711b659264750fc 100644 (file)
@@ -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);
        }