sexp: Change internal versions to always use gpg_err_code_t.
authorWerner Koch <wk@gnupg.org>
Sat, 7 Sep 2013 08:06:46 +0000 (10:06 +0200)
committerWerner Koch <wk@gnupg.org>
Fri, 20 Sep 2013 16:30:05 +0000 (18:30 +0200)
* src/sexp.c (gcry_sexp_new, gcry_sexp_create, gcry_sexp_build)
(gcry_sexp_build_array, gcry_sexp_canon_len): Change error return type
from gpg_error_t to gpg_err_code_t.  Remove all calls to gpg_error.
* src/visibility.c (gcry_sexp_new, gcry_sexp_create, gcry_sexp_sscan)
(gcry_sexp_build, gcry_sexp_build_array, gcry_sexp_canon_len): Map
error codes via gpg_error.
* cipher/dsa.c, cipher/ecc.c, cipher/elgamal.c, cipher/rsa.c: Remove
use gpg_err_code wrappers.

--

We should do such a change for all other use of internal functions.
It just does not make sense to use gpg_error in the internal interface
because the error source is always Libgcrypt.

Signed-off-by: Werner Koch <wk@gnupg.org>
cipher/dsa.c
cipher/ecc.c
cipher/elgamal.c
cipher/rsa.c
src/cipher-proto.h
src/g10lib.h
src/sexp.c
src/visibility.c

index ceff947..394800d 100644 (file)
@@ -817,10 +817,9 @@ dsa_generate (int algo, unsigned int nbits, unsigned long evalue,
         {
           /* Format the seed-values unless domain parameters are used
              for which a H_VALUE of NULL is an indication.  */
-          rc = gpg_err_code (gcry_sexp_build
-                             (&seedinfo, NULL,
-                              "(seed-values(counter %d)(seed %b)(h %m))",
-                              counter, (int)seedlen, seed, h_value));
+          rc = gcry_sexp_build (&seedinfo, NULL,
+                                "(seed-values(counter %d)(seed %b)(h %m))",
+                                counter, (int)seedlen, seed, h_value);
           gcry_free (seed);
           gcry_mpi_release (h_value);
         }
@@ -876,8 +875,7 @@ dsa_generate (int algo, unsigned int nbits, unsigned long evalue,
                 arg_list[i++] = factors + j;
               arg_list[i] = NULL;
 
-              rc = gpg_err_code (gcry_sexp_build_array
-                                 (&misc_info, NULL, format, arg_list));
+              rc = gcry_sexp_build_array (&misc_info, NULL, format, arg_list);
             }
         }
 
@@ -886,17 +884,16 @@ dsa_generate (int algo, unsigned int nbits, unsigned long evalue,
     }
 
   if (!rc)
-    rc = gcry_err_code (gcry_sexp_build
-                        (r_skey, NULL,
-                         "(key-data"
-                         " (public-key"
-                         "  (dsa(p%m)(q%m)(g%m)(y%m)))"
-                         " (private-key"
-                         "  (dsa(p%m)(q%m)(g%m)(y%m)(x%m)))"
-                         " %S)",
-                         sk.p, sk.q, sk.g, sk.y,
-                         sk.p, sk.q, sk.g, sk.y, sk.x,
-                         misc_info));
+    rc = gcry_sexp_build (r_skey, NULL,
+                          "(key-data"
+                          " (public-key"
+                          "  (dsa(p%m)(q%m)(g%m)(y%m)))"
+                          " (private-key"
+                          "  (dsa(p%m)(q%m)(g%m)(y%m)(x%m)))"
+                          " %S)",
+                          sk.p, sk.q, sk.g, sk.y,
+                          sk.p, sk.q, sk.g, sk.y, sk.x,
+                          misc_info);
 
 
   gcry_mpi_release (sk.p);
@@ -976,9 +973,7 @@ dsa_sign (int algo, gcry_sexp_t *r_result, gcry_mpi_t data, gcry_mpi_t *skey,
       s = mpi_alloc (mpi_get_nlimbs (sk.p));
       rc = sign (r, s, data, &sk, flags, hashalgo);
       if (!rc)
-        rc = gcry_err_code (gcry_sexp_build (r_result, NULL,
-                                             "(sig-val(dsa(r%M)(s%M)))",
-                                             r, s));
+        rc = gcry_sexp_build (r_result, NULL, "(sig-val(dsa(r%M)(s%M)))", r, s);
       mpi_free (r);
       mpi_free (s);
     }
index cf054f8..2161b64 100644 (file)
@@ -1271,18 +1271,17 @@ ecc_generate (int algo, unsigned int nbits, unsigned long evalue,
         goto leave;
     }
 
-  rc = gcry_err_code (gcry_sexp_build
-                      (r_skey, NULL,
-                       "(key-data"
-                       " (public-key"
-                       "  (ecc%S(p%m)(a%m)(b%m)(g%m)(n%m)(q%m)))"
-                       " (private-key"
-                       "  (ecc%S(p%m)(a%m)(b%m)(g%m)(n%m)(q%m)(d%m)))"
-                       " )",
-                       curve_info,
-                       sk.E.p, sk.E.a, sk.E.b, base, sk.E.n, public,
-                       curve_info,
-                       sk.E.p, sk.E.a, sk.E.b, base, sk.E.n, public, secret));
+  rc = gcry_sexp_build (r_skey, NULL,
+                        "(key-data"
+                        " (public-key"
+                        "  (ecc%S(p%m)(a%m)(b%m)(g%m)(n%m)(q%m)))"
+                        " (private-key"
+                        "  (ecc%S(p%m)(a%m)(b%m)(g%m)(n%m)(q%m)(d%m)))"
+                        " )",
+                        curve_info,
+                        sk.E.p, sk.E.a, sk.E.b, base, sk.E.n, public,
+                        curve_info,
+                        sk.E.p, sk.E.a, sk.E.b, base, sk.E.n, public, secret);
   if (rc)
     goto leave;
 
@@ -1434,17 +1433,15 @@ ecc_sign (int algo, gcry_sexp_t *r_result, gcry_mpi_t data, gcry_mpi_t *skey,
               {
                 rc = sign_eddsa (data, &sk, r, s, hashalgo, skey[5]);
                 if (!rc)
-                  rc = gcry_err_code (gcry_sexp_build
-                                      (r_result, NULL,
-                                       "(sig-val(eddsa(r%M)(s%M)))", r, s));
+                  rc = gcry_sexp_build (r_result, NULL,
+                                        "(sig-val(eddsa(r%M)(s%M)))", r, s);
               }
             else
               {
                 rc = sign_ecdsa (data, &sk, r, s, flags, hashalgo);
                 if (!rc)
-                  rc = gcry_err_code (gcry_sexp_build
-                                      (r_result, NULL,
-                                       "(sig-val(ecdsa(r%M)(s%M)))", r, s));
+                  rc = gcry_sexp_build (r_result, NULL,
+                                        "(sig-val(ecdsa(r%M)(s%M)))", r, s);
               }
             gcry_mpi_release (sk.d);
             sk.d = NULL;
@@ -1644,9 +1641,7 @@ ecc_encrypt_raw (int algo, gcry_sexp_t *r_result, gcry_mpi_t k,
   point_free (&pk.E.G);
   point_free (&pk.Q);
 
-  rc = gcry_err_code (gcry_sexp_build (r_result, NULL,
-                                       "(enc-val(ecdh(s%m)(e%m)))",
-                                       s, e));
+  rc = gcry_sexp_build (r_result, NULL, "(enc-val(ecdh(s%m)(e%m)))", s, e);
   mpi_free (s);
   mpi_free (e);
 
@@ -1752,7 +1747,7 @@ ecc_decrypt_raw (int algo, gcry_sexp_t *r_plain, gcry_mpi_t *data,
   point_free (&sk.Q);
 
   if (!rc)
-    rc = gcry_err_code (gcry_sexp_build (r_plain, NULL, "(value %m)", r));
+    rc = gcry_sexp_build (r_plain, NULL, "(value %m)", r);
   mpi_free (r);
   return rc;
 }
@@ -1924,20 +1919,18 @@ _gcry_pk_ecc_get_sexp (gcry_sexp_t *r_sexp, int mode, mpi_ec_t ec)
   if (ec->d && (!mode || mode == GCRY_PK_GET_SECKEY))
     {
       /* Let's return a private key. */
-      rc = gpg_err_code
-        (gcry_sexp_build
-         (r_sexp, NULL,
-          "(private-key(ecc(p%m)(a%m)(b%m)(g%m)(n%m)(q%m)(d%m)))",
-          ec->p, ec->a, ec->b, mpi_G, ec->n, mpi_Q, ec->d));
+      rc = gcry_sexp_build
+        (r_sexp, NULL,
+         "(private-key(ecc(p%m)(a%m)(b%m)(g%m)(n%m)(q%m)(d%m)))",
+         ec->p, ec->a, ec->b, mpi_G, ec->n, mpi_Q, ec->d);
     }
   else if (ec->Q)
     {
       /* Let's return a public key.  */
-      rc = gpg_err_code
-        (gcry_sexp_build
-         (r_sexp, NULL,
-          "(public-key(ecc(p%m)(a%m)(b%m)(g%m)(n%m)(q%m)))",
-          ec->p, ec->a, ec->b, mpi_G, ec->n, mpi_Q));
+      rc = gcry_sexp_build
+        (r_sexp, NULL,
+         "(public-key(ecc(p%m)(a%m)(b%m)(g%m)(n%m)(q%m)))",
+         ec->p, ec->a, ec->b, mpi_G, ec->n, mpi_Q);
     }
   else
     rc = GPG_ERR_BAD_CRYPT_CTX;
index ecbac75..c63059d 100644 (file)
@@ -692,17 +692,16 @@ elg_generate (int algo, unsigned int nbits, unsigned long evalue,
         goto leave;
     }
 
-  rc = gcry_err_code (gcry_sexp_build
-                      (r_skey, NULL,
-                       "(key-data"
-                       " (public-key"
-                       "  (elg(p%m)(g%m)(y%m)))"
-                       " (private-key"
+  rc = gcry_sexp_build (r_skey, NULL,
+                        "(key-data"
+                        " (public-key"
+                        "  (elg(p%m)(g%m)(y%m)))"
+                        " (private-key"
                        "  (elg(p%m)(g%m)(y%m)(x%m)))"
-                       " %S)",
-                       sk.p, sk.g, sk.y,
-                       sk.p, sk.g, sk.y, sk.x,
-                       misc_info));
+                        " %S)",
+                        sk.p, sk.g, sk.y,
+                        sk.p, sk.g, sk.y, sk.x,
+                        misc_info);
 
  leave:
   mpi_free (sk.p);
@@ -768,9 +767,7 @@ elg_encrypt (int algo, gcry_sexp_t *r_result,
       a = mpi_alloc (mpi_get_nlimbs (pk.p));
       b = mpi_alloc (mpi_get_nlimbs (pk.p));
       do_encrypt (a, b, data, &pk);
-      rc = gcry_err_code (gcry_sexp_build (r_result, NULL,
-                                           "(enc-val(elg(a%m)(b%m)))",
-                                           a, b));
+      rc = gcry_sexp_build (r_result, NULL, "(enc-val(elg(a%m)(b%m)))", a, b);
       mpi_free (a);
       mpi_free (b);
     }
@@ -817,8 +814,8 @@ elg_decrypt (int algo, gcry_sexp_t *r_plain,
           mpi_free (plain);
           plain = NULL;
           if (!rc)
-            rc = gcry_err_code (gcry_sexp_build (r_plain, NULL, "(value %b)",
-                                                 (int)unpadlen, unpad));
+            rc = gcry_sexp_build (r_plain, NULL, "(value %b)",
+                                  (int)unpadlen, unpad);
           break;
 
         case PUBKEY_ENC_OAEP:
@@ -827,18 +824,17 @@ elg_decrypt (int algo, gcry_sexp_t *r_plain,
           mpi_free (plain);
           plain = NULL;
           if (!rc)
-            rc = gcry_err_code (gcry_sexp_build (r_plain, NULL, "(value %b)",
-                                             (int)unpadlen, unpad));
+            rc = gcry_sexp_build (r_plain, NULL, "(value %b)",
+                                  (int)unpadlen, unpad);
           break;
 
         default:
           /* Raw format.  For backward compatibility we need to assume a
              signed mpi by using the sexp format string "%m".  */
-          rc = gcry_err_code
-            (gcry_sexp_build (r_plain, NULL,
-                              (flags & PUBKEY_FLAG_LEGACYRESULT)
-                              ? "%m" : "(value %m)",
-                              plain));
+          rc = gcry_sexp_build (r_plain, NULL,
+                                (flags & PUBKEY_FLAG_LEGACYRESULT)
+                                ? "%m" : "(value %m)",
+                                plain);
           break;
         }
 
@@ -876,9 +872,7 @@ elg_sign (int algo, gcry_sexp_t *r_result, gcry_mpi_t data, gcry_mpi_t *skey,
       r = mpi_alloc (mpi_get_nlimbs (sk.p));
       s = mpi_alloc (mpi_get_nlimbs (sk.p));
       sign (r, s, data, &sk);
-      rc = gcry_err_code (gcry_sexp_build (r_result, NULL,
-                                           "(sig-val(elg(r%M)(s%M)))",
-                                           r, s));
+      rc = gcry_sexp_build (r_result, NULL, "(sig-val(elg(r%M)(s%M)))", r, s);
       mpi_free (r);
       mpi_free (s);
     }
index 7105271..53b9d89 100644 (file)
@@ -794,17 +794,16 @@ rsa_generate (int algo, unsigned int nbits, unsigned long evalue,
 
   if (!ec)
     {
-      ec = gcry_err_code (gcry_sexp_build
-                          (r_skey, NULL,
-                           "(key-data"
-                           " (public-key"
-                           "  (rsa(n%m)(e%m)))"
-                           " (private-key"
-                           "  (rsa(n%m)(e%m)(d%m)(p%m)(q%m)(u%m)))"
-                           " %S)",
-                           sk.n, sk.e,
-                           sk.n, sk.e, sk.d, sk.p, sk.q, sk.u,
-                           swap_info));
+      ec = gcry_sexp_build (r_skey, NULL,
+                            "(key-data"
+                            " (public-key"
+                            "  (rsa(n%m)(e%m)))"
+                            " (private-key"
+                            "  (rsa(n%m)(e%m)(d%m)(p%m)(q%m)(u%m)))"
+                            " %S)",
+                            sk.n, sk.e,
+                            sk.n, sk.e, sk.d, sk.p, sk.q, sk.u,
+                            swap_info);
     }
 
   mpi_free (sk.n);
@@ -869,16 +868,13 @@ rsa_encrypt (int algo, gcry_sexp_t *r_result, gcry_mpi_t data,
       rc = _gcry_mpi_to_octet_string (&em, NULL, result, emlen);
       if (!rc)
         {
-          rc = gcry_err_code (gcry_sexp_build (r_result, NULL,
-                                               "(enc-val(rsa(a%b)))",
-                                               (int)emlen, em));
+          rc = gcry_sexp_build (r_result, NULL,
+                                "(enc-val(rsa(a%b)))", (int)emlen, em);
           gcry_free (em);
         }
     }
   else
-    rc = gcry_err_code (gcry_sexp_build (r_result, NULL,
-                                         "(enc-val(rsa(a%m)))",
-                                         result));
+    rc = gcry_sexp_build (r_result, NULL, "(enc-val(rsa(a%m)))", result);
 
   mpi_free (result);
   return rc;
@@ -969,8 +965,8 @@ rsa_decrypt (int algo, gcry_sexp_t *r_plain, gcry_mpi_t *data,
       mpi_free (plain);
       plain = NULL;
       if (!rc)
-        rc = gcry_err_code (gcry_sexp_build (r_plain, NULL, "(value %b)",
-                                             (int)unpadlen, unpad));
+        rc = gcry_sexp_build (r_plain, NULL,
+                              "(value %b)", (int)unpadlen, unpad);
       break;
 
     case PUBKEY_ENC_OAEP:
@@ -979,17 +975,16 @@ rsa_decrypt (int algo, gcry_sexp_t *r_plain, gcry_mpi_t *data,
       mpi_free (plain);
       plain = NULL;
       if (!rc)
-        rc = gcry_err_code (gcry_sexp_build (r_plain, NULL, "(value %b)",
-                                             (int)unpadlen, unpad));
+        rc = gcry_sexp_build (r_plain, NULL,
+                              "(value %b)", (int)unpadlen, unpad);
       break;
 
     default:
       /* Raw format.  For backward compatibility we need to assume a
          signed mpi by using the sexp format string "%m".  */
-      rc = gcry_err_code
-        (gcry_sexp_build (r_plain, NULL,
-                          (flags & PUBKEY_FLAG_LEGACYRESULT)? "%m":"(value %m)",
-                          plain));
+      rc = gcry_sexp_build (r_plain, NULL,
+                            (flags & PUBKEY_FLAG_LEGACYRESULT)
+                            ? "%m":"(value %m)", plain);
       break;
     }
 
@@ -1033,16 +1028,13 @@ rsa_sign (int algo, gcry_sexp_t *r_result, gcry_mpi_t data, gcry_mpi_t *skey,
       rc = _gcry_mpi_to_octet_string (&em, NULL, result, emlen);
       if (!rc)
         {
-          rc = gcry_err_code (gcry_sexp_build (r_result, NULL,
-                                               "(sig-val(rsa(s%b)))",
-                                               (int)emlen, em));
+          rc = gcry_sexp_build (r_result, NULL,
+                                "(sig-val(rsa(s%b)))", (int)emlen, em);
           gcry_free (em);
         }
     }
   else
-    rc = gcry_err_code (gcry_sexp_build (r_result, NULL,
-                                         "(sig-val(rsa(s%M)))",
-                                         result));
+    rc = gcry_sexp_build (r_result, NULL, "(sig-val(rsa(s%M)))",  result);
   mpi_free (result);
 
   return rc;
index 212857b..5b152b5 100644 (file)
@@ -24,6 +24,8 @@
 #define G10_CIPHER_PROTO_H
 
 
+enum pk_encoding;
+
 
 /* Definition of a function used to report selftest failures.
    DOMAIN is a string describing the function block:
index 57176e9..73ba683 100644 (file)
@@ -405,8 +405,8 @@ gcry_err_code_t _gcry_mpi_init (void);
 
 
 /*-- sexp.c --*/
-gcry_error_t _gcry_sexp_vbuild (gcry_sexp_t *retsexp, size_t *erroff,
-                                const char *format, va_list arg_ptr);
+gcry_err_code_t _gcry_sexp_vbuild (gcry_sexp_t *retsexp, size_t *erroff,
+                                   const char *format, va_list arg_ptr);
 gcry_mpi_t _gcry_sexp_nth_opaque_mpi (gcry_sexp_t list, int number);
 char *_gcry_sexp_nth_string (const gcry_sexp_t list, int number);
 
index 882ee52..54d0c4a 100644 (file)
@@ -54,12 +54,12 @@ struct gcry_sexp
 
 #define TOKEN_SPECIALS  "-./_:*+="
 
-static gcry_error_t
+static gcry_err_code_t
 vsexp_sscan (gcry_sexp_t *retsexp, size_t *erroff,
             const char *buffer, size_t length, int argflag,
             void **arg_list, va_list arg_ptr);
 
-static gcry_error_t
+static gcry_err_code_t
 sexp_sscan (gcry_sexp_t *retsexp, size_t *erroff,
            const char *buffer, size_t length, int argflag,
            void **arg_list, ...);
@@ -210,18 +210,18 @@ normalize ( gcry_sexp_t list )
 
    This function returns 0 and and the pointer to the new object in
    RETSEXP or an error code in which case RETSEXP is set to NULL.  */
-gcry_error_t
+gcry_err_code_t
 gcry_sexp_create (gcry_sexp_t *retsexp, void *buffer, size_t length,
                   int autodetect, void (*freefnc)(void*) )
 {
-  gcry_error_t errcode;
+  gcry_err_code_t errcode;
   gcry_sexp_t se;
 
   if (!retsexp)
-    return gcry_error (GPG_ERR_INV_ARG);
+    return GPG_ERR_INV_ARG;
   *retsexp = NULL;
   if (autodetect < 0 || autodetect > 1 || !buffer)
-    return gcry_error (GPG_ERR_INV_ARG);
+    return GPG_ERR_INV_ARG;
 
   if (!length && !autodetect)
     { /* What a brave caller to assume that there is really a canonical
@@ -249,11 +249,11 @@ gcry_sexp_create (gcry_sexp_t *retsexp, void *buffer, size_t length,
          GCRYSEXP object and use the BUFFER directly.  */
       freefnc (buffer);
     }
-  return gcry_error (GPG_ERR_NO_ERROR);
+  return 0;
 }
 
 /* Same as gcry_sexp_create but don't transfer ownership */
-gcry_error_t
+gcry_err_code_t
 gcry_sexp_new (gcry_sexp_t *retsexp, const void *buffer, size_t length,
                int autodetect)
 {
@@ -1047,7 +1047,7 @@ unquote_string (const char *string, size_t length, unsigned char *buf)
  * common operation gcry_sexp_cdr_mpi() will always return a secure MPI
  * regardless whether it is needed or not.
  */
-static gcry_error_t
+static gpg_err_code_t
 vsexp_sscan (gcry_sexp_t *retsexp, size_t *erroff,
             const char *buffer, size_t length, int argflag,
             void **arg_list, va_list arg_ptr)
@@ -1643,18 +1643,18 @@ vsexp_sscan (gcry_sexp_t *retsexp, size_t *erroff,
   else
     *retsexp = normalize (c.sexp);
 
-  return gcry_error (err);
+  return err;
 #undef MAKE_SPACE
 #undef STORE_LEN
 }
 
 
-static gcry_error_t
+static gpg_err_code_t
 sexp_sscan (gcry_sexp_t *retsexp, size_t *erroff,
            const char *buffer, size_t length, int argflag,
            void **arg_list, ...)
 {
-  gcry_error_t rc;
+  gcry_err_code_t rc;
   va_list arg_ptr;
 
   va_start (arg_ptr, arg_list);
@@ -1666,10 +1666,10 @@ sexp_sscan (gcry_sexp_t *retsexp, size_t *erroff,
 }
 
 
-gcry_error_t
+gpg_err_code_t
 gcry_sexp_build (gcry_sexp_t *retsexp, size_t *erroff, const char *format, ...)
 {
-  gcry_error_t rc;
+  gcry_err_code_t rc;
   va_list arg_ptr;
 
   va_start (arg_ptr, format);
@@ -1681,7 +1681,7 @@ gcry_sexp_build (gcry_sexp_t *retsexp, size_t *erroff, const char *format, ...)
 }
 
 
-gcry_error_t
+gcry_err_code_t
 _gcry_sexp_vbuild (gcry_sexp_t *retsexp, size_t *erroff,
                    const char *format, va_list arg_ptr)
 {
@@ -1692,7 +1692,7 @@ _gcry_sexp_vbuild (gcry_sexp_t *retsexp, size_t *erroff,
 
 /* Like gcry_sexp_build, but uses an array instead of variable
    function arguments.  */
-gcry_error_t
+gcry_err_code_t
 gcry_sexp_build_array (gcry_sexp_t *retsexp, size_t *erroff,
                       const char *format, void **arg_list)
 {
@@ -1700,7 +1700,7 @@ gcry_sexp_build_array (gcry_sexp_t *retsexp, size_t *erroff,
 }
 
 
-gcry_error_t
+gcry_err_code_t
 gcry_sexp_sscan (gcry_sexp_t *retsexp, size_t *erroff,
                 const char *buffer, size_t length)
 {
@@ -1987,13 +1987,13 @@ gcry_sexp_sprint (const gcry_sexp_t list, int mode,
    NULL.  */
 size_t
 gcry_sexp_canon_len (const unsigned char *buffer, size_t length,
-                     size_t *erroff, gcry_error_t *errcode)
+                     size_t *erroff, gcry_err_code_t *errcode)
 {
   const unsigned char *p;
   const unsigned char *disphint = NULL;
   unsigned int datalen = 0;
   size_t dummy_erroff;
-  gcry_error_t dummy_errcode;
+  gcry_err_code_t dummy_errcode;
   size_t count = 0;
   int level = 0;
 
@@ -2002,13 +2002,13 @@ gcry_sexp_canon_len (const unsigned char *buffer, size_t length,
   if (!errcode)
     errcode = &dummy_errcode;
 
-  *errcode = gcry_error (GPG_ERR_NO_ERROR);
+  *errcode = GPG_ERR_NO_ERROR;
   *erroff = 0;
   if (!buffer)
     return 0;
   if (*buffer != '(')
     {
-      *errcode = gcry_error (GPG_ERR_SEXP_NOT_CANONICAL);
+      *errcode = GPG_ERR_SEXP_NOT_CANONICAL;
       return 0;
     }
 
@@ -2017,7 +2017,7 @@ gcry_sexp_canon_len (const unsigned char *buffer, size_t length,
       if (length && count >= length)
         {
           *erroff = count;
-          *errcode = gcry_error (GPG_ERR_SEXP_STRING_TOO_LONG);
+          *errcode = GPG_ERR_SEXP_STRING_TOO_LONG;
           return 0;
         }
 
@@ -2028,7 +2028,7 @@ gcry_sexp_canon_len (const unsigned char *buffer, size_t length,
               if (length && (count+datalen) >= length)
                 {
                   *erroff = count;
-                  *errcode = gcry_error (GPG_ERR_SEXP_STRING_TOO_LONG);
+                  *errcode = GPG_ERR_SEXP_STRING_TOO_LONG;
                   return 0;
                 }
               count += datalen;
@@ -2040,7 +2040,7 @@ gcry_sexp_canon_len (const unsigned char *buffer, size_t length,
           else
             {
               *erroff = count;
-              *errcode = gcry_error (GPG_ERR_SEXP_INV_LEN_SPEC);
+              *errcode = GPG_ERR_SEXP_INV_LEN_SPEC;
               return 0;
            }
        }
@@ -2049,7 +2049,7 @@ gcry_sexp_canon_len (const unsigned char *buffer, size_t length,
           if (disphint)
             {
               *erroff = count;
-              *errcode = gcry_error (GPG_ERR_SEXP_UNMATCHED_DH);
+              *errcode = GPG_ERR_SEXP_UNMATCHED_DH;
               return 0;
            }
           level++;
@@ -2059,13 +2059,13 @@ gcry_sexp_canon_len (const unsigned char *buffer, size_t length,
           if (!level)
             {
               *erroff = count;
-              *errcode = gcry_error (GPG_ERR_SEXP_UNMATCHED_PAREN);
+              *errcode = GPG_ERR_SEXP_UNMATCHED_PAREN;
               return 0;
            }
           if (disphint)
             {
               *erroff = count;
-              *errcode = gcry_error (GPG_ERR_SEXP_UNMATCHED_DH);
+              *errcode = GPG_ERR_SEXP_UNMATCHED_DH;
               return 0;
            }
           if (!--level)
@@ -2076,7 +2076,7 @@ gcry_sexp_canon_len (const unsigned char *buffer, size_t length,
           if (disphint)
             {
               *erroff = count;
-              *errcode = gcry_error (GPG_ERR_SEXP_NESTED_DH);
+              *errcode = GPG_ERR_SEXP_NESTED_DH;
               return 0;
             }
           disphint = p;
@@ -2086,7 +2086,7 @@ gcry_sexp_canon_len (const unsigned char *buffer, size_t length,
           if ( !disphint )
             {
               *erroff = count;
-              *errcode = gcry_error (GPG_ERR_SEXP_UNMATCHED_DH);
+              *errcode = GPG_ERR_SEXP_UNMATCHED_DH;
               return 0;
            }
           disphint = NULL;
@@ -2096,7 +2096,7 @@ gcry_sexp_canon_len (const unsigned char *buffer, size_t length,
           if (*p == '0')
             {
               *erroff = count;
-              *errcode = gcry_error (GPG_ERR_SEXP_ZERO_PREFIX);
+              *errcode = GPG_ERR_SEXP_ZERO_PREFIX;
               return 0;
            }
           datalen = atoi_1 (p);
@@ -2104,13 +2104,13 @@ gcry_sexp_canon_len (const unsigned char *buffer, size_t length,
       else if (*p == '&' || *p == '\\')
         {
           *erroff = count;
-          *errcode = gcry_error (GPG_ERR_SEXP_UNEXPECTED_PUNC);
+          *errcode = GPG_ERR_SEXP_UNEXPECTED_PUNC;
           return 0;
        }
       else
         {
           *erroff = count;
-          *errcode = gcry_error (GPG_ERR_SEXP_BAD_CHARACTER);
+          *errcode = GPG_ERR_SEXP_BAD_CHARACTER;
           return 0;
        }
     }
index 3c8041a..cfb159f 100644 (file)
@@ -86,7 +86,7 @@ gcry_sexp_new (gcry_sexp_t *retsexp,
                const void *buffer, size_t length,
                int autodetect)
 {
-  return _gcry_sexp_new (retsexp, buffer, length, autodetect);
+  return gpg_error (_gcry_sexp_new (retsexp, buffer, length, autodetect));
 }
 
 gcry_error_t
@@ -94,35 +94,35 @@ gcry_sexp_create (gcry_sexp_t *retsexp,
                   void *buffer, size_t length,
                   int autodetect, void (*freefnc) (void *))
 {
-  return _gcry_sexp_create (retsexp, buffer, length,
-                            autodetect, freefnc);
+  return gpg_error (_gcry_sexp_create (retsexp, buffer, length,
+                                       autodetect, freefnc));
 }
 
 gcry_error_t
 gcry_sexp_sscan (gcry_sexp_t *retsexp, size_t *erroff,
                  const char *buffer, size_t length)
 {
-  return _gcry_sexp_sscan (retsexp, erroff, buffer, length);
+  return gpg_error (_gcry_sexp_sscan (retsexp, erroff, buffer, length));
 }
 
 gcry_error_t
 gcry_sexp_build (gcry_sexp_t *retsexp, size_t *erroff,
                  const char *format, ...)
 {
-  gcry_error_t err;
+  gcry_err_code_t rc;
   va_list arg_ptr;
 
   va_start (arg_ptr, format);
-  err = _gcry_sexp_vbuild (retsexp, erroff, format, arg_ptr);
+  rc = _gcry_sexp_vbuild (retsexp, erroff, format, arg_ptr);
   va_end (arg_ptr);
-  return err;
+  return gpg_error (rc);
 }
 
 gcry_error_t
 gcry_sexp_build_array (gcry_sexp_t *retsexp, size_t *erroff,
                        const char *format, void **arg_list)
 {
-  return _gcry_sexp_build_array (retsexp, erroff, format, arg_list);
+  return gpg_error (_gcry_sexp_build_array (retsexp, erroff, format, arg_list));
 }
 
 void
@@ -135,7 +135,13 @@ size_t
 gcry_sexp_canon_len (const unsigned char *buffer, size_t length,
                      size_t *erroff, gcry_error_t *errcode)
 {
-  return _gcry_sexp_canon_len (buffer, length, erroff, errcode);
+  size_t n;
+  gpg_err_code_t rc;
+
+  n = _gcry_sexp_canon_len (buffer, length, erroff, &rc);
+  if (errcode)
+    *errcode = gpg_error (rc);
+  return n;
 }
 
 size_t