Remove trailing white space from a file
[gnupg.git] / g10 / skclist.c
index e0e1256..70b375a 100644 (file)
@@ -27,7 +27,7 @@
 #include "gpg.h"
 #include "options.h"
 #include "packet.h"
-#include "errors.h"
+#include "status.h"
 #include "keydb.h"
 #include "util.h"
 #include "i18n.h"
 int
 random_is_faked (void)
 {
-  /* We use a runtime check to allow for slow migrattion of libgcrypt.
-     We can't use the constant becuase that one is actually an enum
-     value.  */
-  gpg_error_t err = gcry_control ( 51 /*GCRYCTL_FAKED_RANDOM_P*/, 0);
-
-  if (!err)
-    return 0;
-  if (gpg_err_code (err) != GPG_ERR_INV_OP)
-    return 1;
-  log_info ("WARNING: libgcrypt too old.\n");
-  log_info ("         can't check whether we are in faked RNG mode\n");
-  return 0; /* Need to return false.  */
+  return !!gcry_control ( GCRYCTL_FAKED_RANDOM_P, 0);
 }
 
 
@@ -139,6 +128,8 @@ build_sk_list( strlist_t locusr, SK_LIST *ret_sk_list,
        if( (rc = get_seckey_byname( sk, NULL, unlock )) ) {
          free_secret_key( sk ); sk = NULL;
          log_error("no default secret key: %s\n", g10_errstr(rc) );
+          write_status_text (STATUS_INV_SGNR,
+                             get_inv_recpsgnr_code (GPG_ERR_NO_SECKEY));
        }
        else if( !(rc=openpgp_pk_test_algo2 (sk->pubkey_algo, use)) )
          {
@@ -149,6 +140,8 @@ build_sk_list( strlist_t locusr, SK_LIST *ret_sk_list,
                log_info(_("key is not flagged as insecure - "
                           "can't use it with the faked RNG!\n"));
                free_secret_key( sk ); sk = NULL;
+                write_status_text (STATUS_INV_SGNR, 
+                                   get_inv_recpsgnr_code (GPG_ERR_NOT_TRUSTED));
              }
            else
              {
@@ -163,6 +156,7 @@ build_sk_list( strlist_t locusr, SK_LIST *ret_sk_list,
          {
            free_secret_key( sk ); sk = NULL;
            log_error("invalid default secret key: %s\n", g10_errstr(rc) );
+            write_status_text (STATUS_INV_SGNR, get_inv_recpsgnr_code (rc));
          }
       }
     else {
@@ -177,7 +171,7 @@ build_sk_list( strlist_t locusr, SK_LIST *ret_sk_list,
              */
             if ( is_duplicated_entry ( locusr_orig, locusr ) )
              {
-               log_error(_("skipped \"%s\": duplicated\n"), locusr->d );
+               log_info (_("skipped \"%s\": duplicated\n"), locusr->d );
                 continue;
              }
            sk = xmalloc_clear( sizeof *sk );
@@ -187,6 +181,9 @@ build_sk_list( strlist_t locusr, SK_LIST *ret_sk_list,
                free_secret_key( sk ); sk = NULL;
                log_error(_("skipped \"%s\": %s\n"),
                          locusr->d, g10_errstr(rc) );
+                write_status_text_and_buffer 
+                  (STATUS_INV_SGNR, get_inv_recpsgnr_code (rc), 
+                   locusr->d, strlen (locusr->d), -1);
              }
             else if ( key_present_in_sk_list(sk_list, sk) == 0) {
                 free_secret_key(sk); sk = NULL;
@@ -197,6 +194,9 @@ build_sk_list( strlist_t locusr, SK_LIST *ret_sk_list,
                free_secret_key( sk ); sk = NULL;
                log_error(_("skipped \"%s\": %s\n"),
                          locusr->d, g10_errstr(rc) );
+                write_status_text_and_buffer 
+                  (STATUS_INV_SGNR, get_inv_recpsgnr_code (rc), 
+                   locusr->d, strlen (locusr->d), -1);
              }
            else if( !(rc=openpgp_pk_test_algo2 (sk->pubkey_algo, use)) ) {
                SK_LIST r;
@@ -208,11 +208,19 @@ build_sk_list( strlist_t locusr, SK_LIST *ret_sk_list,
                             _("this is a PGP generated Elgamal key which"
                               " is not secure for signatures!"));
                    free_secret_key( sk ); sk = NULL;
+                    write_status_text_and_buffer 
+                      (STATUS_INV_SGNR, 
+                       get_inv_recpsgnr_code (GPG_ERR_WRONG_KEY_USAGE), 
+                       locusr->d, strlen (locusr->d), -1);
                  }
                else if( random_is_faked() && !is_insecure( sk ) ) {
                    log_info(_("key is not flagged as insecure - "
                               "can't use it with the faked RNG!\n"));
                    free_secret_key( sk ); sk = NULL;
+                    write_status_text_and_buffer 
+                      (STATUS_INV_SGNR, 
+                       get_inv_recpsgnr_code (GPG_ERR_NOT_TRUSTED), 
+                       locusr->d, strlen (locusr->d), -1);
                }
                else {
                    r = xmalloc( sizeof *r );
@@ -225,6 +233,9 @@ build_sk_list( strlist_t locusr, SK_LIST *ret_sk_list,
            else {
                free_secret_key( sk ); sk = NULL;
                log_error("skipped \"%s\": %s\n", locusr->d, g10_errstr(rc) );
+                write_status_text_and_buffer 
+                  (STATUS_INV_SGNR, get_inv_recpsgnr_code (rc), 
+                   locusr->d, strlen (locusr->d), -1);
            }
        }
     }
@@ -232,6 +243,7 @@ build_sk_list( strlist_t locusr, SK_LIST *ret_sk_list,
 
     if( !rc && !sk_list ) {
        log_error("no valid signators\n");
+        write_status_text (STATUS_NO_SGNR, "0");
        rc = G10ERR_NO_USER_ID;
     }