]> granicus.if.org Git - neomutt/commitdiff
mutt_str_startswith - ncrypt/pgp.c
authorPietro Cerutti <gahr@gahr.ch>
Fri, 9 Nov 2018 15:44:06 +0000 (15:44 +0000)
committerRichard Russon <rich@flatcap.org>
Wed, 14 Nov 2018 15:10:31 +0000 (15:10 +0000)
ncrypt/pgp.c

index b362bba40b824f69ea9add7d727b38b9c7c59aad..7cc6ac07f5355d3f21236adcbcbade8f27fee1d1 100644 (file)
@@ -361,15 +361,16 @@ static int pgp_check_decryption_okay(FILE *fpin)
 
   while ((line = mutt_file_read_line(line, &linelen, fpin, &lineno, 0)))
   {
-    if (mutt_str_strncmp(line, "[GNUPG:] ", 9) != 0)
+    size_t plen = mutt_str_startswith(line, "[GNUPG:]", CASE_MATCH);
+    if (plen == 0)
       continue;
-    s = line + 9;
+    s = line + plen;
     mutt_debug(2, "checking \"%s\".\n", line);
-    if (mutt_str_strncmp(s, "BEGIN_DECRYPTION", 16) == 0)
+    if (mutt_str_startswith(s, "BEGIN_DECRYPTION", CASE_MATCH))
       inside_decrypt = 1;
-    else if (mutt_str_strncmp(s, "END_DECRYPTION", 14) == 0)
+    else if (mutt_str_startswith(s, "END_DECRYPTION", CASE_MATCH))
       inside_decrypt = 0;
-    else if (mutt_str_strncmp(s, "PLAINTEXT", 9) == 0)
+    else if (mutt_str_startswith(s, "PLAINTEXT", CASE_MATCH))
     {
       if (!inside_decrypt)
       {
@@ -379,13 +380,13 @@ static int pgp_check_decryption_okay(FILE *fpin)
         break;
       }
     }
-    else if (mutt_str_strncmp(s, "DECRYPTION_FAILED", 17) == 0)
+    else if (mutt_str_startswith(s, "DECRYPTION_FAILED", CASE_MATCH))
     {
       mutt_debug(2, "\tDECRYPTION_FAILED encountered.  Failure.\n");
       rv = -3;
       break;
     }
-    else if (mutt_str_strncmp(s, "DECRYPTION_OKAY", 15) == 0)
+    else if (mutt_str_startswith(s, "DECRYPTION_OKAY", CASE_MATCH))
     {
       /* Don't break out because we still have to check for
        * PLAINTEXT outside of the decryption boundaries. */
@@ -499,20 +500,21 @@ int pgp_class_application_handler(struct Body *m, struct State *s)
     bytes -= (offset - last_pos); /* don't rely on mutt_str_strlen(buf) */
     last_pos = offset;
 
-    if (mutt_str_strncmp("-----BEGIN PGP ", buf, 15) == 0)
+    size_t plen = mutt_str_startswith(buf, "-----BEGIN PGP ", CASE_MATCH);
+    if (plen != 0)
     {
       clearsign = false;
       could_not_decrypt = false;
       decrypt_okay_rc = 0;
 
-      if (mutt_str_strcmp("MESSAGE-----\n", buf + 15) == 0)
+      if (mutt_str_startswith(buf + plen, "MESSAGE-----\n", CASE_MATCH))
         needpass = 1;
-      else if (mutt_str_strcmp("SIGNED MESSAGE-----\n", buf + 15) == 0)
+      else if (mutt_str_startswith(buf + plen, "SIGNED MESSAGE-----\n", CASE_MATCH))
       {
         clearsign = true;
         needpass = 0;
       }
-      else if (mutt_str_strcmp("PUBLIC KEY BLOCK-----\n", buf + 15) == 0)
+      else if (mutt_str_startswith(buf + plen, "PUBLIC KEY BLOCK-----\n", CASE_MATCH))
       {
         needpass = 0;
         pgp_keyblock = true;
@@ -555,7 +557,7 @@ int pgp_class_application_handler(struct Body *m, struct State *s)
           break;
         }
         /* remember optional Charset: armor header as defined by RFC4880 */
-        if (mutt_str_strncmp("Charset: ", buf, 9) == 0)
+        if (mutt_str_startswith(buf, "Charset: ", CASE_MATCH))
         {
           size_t l = 0;
           FREE(&gpgcharset);
@@ -806,13 +808,14 @@ static int pgp_check_traditional_one_body(FILE *fp, struct Body *b)
 
   while (fgets(buf, sizeof(buf), tfp))
   {
-    if (mutt_str_strncmp("-----BEGIN PGP ", buf, 15) == 0)
+    size_t plen = mutt_str_startswith(buf, "-----BEGIN PGP ", CASE_MATCH);
+    if (plen != 0)
     {
-      if (mutt_str_strcmp("MESSAGE-----\n", buf + 15) == 0)
+      if (mutt_str_startswith(buf + plen, "MESSAGE-----\n", CASE_MATCH))
         enc = true;
-      else if (mutt_str_strcmp("SIGNED MESSAGE-----\n", buf + 15) == 0)
+      else if (mutt_str_startswith(buf + plen, "SIGNED MESSAGE-----\n", CASE_MATCH))
         sgn = true;
-      else if (mutt_str_strcmp("PUBLIC KEY BLOCK-----\n", buf + 15) == 0)
+      else if (mutt_str_startswith(buf + plen, "PUBLIC KEY BLOCK-----\n", CASE_MATCH))
         key = true;
     }
   }