]> the.earth.li Git - onak.git/blobdiff - armor.c
Remove dead store in generic_fetch_key
[onak.git] / armor.c
diff --git a/armor.c b/armor.c
index a730acd83bbfd1b2a8ed994b3fa1c7d6fd107c52..1341950c77af48152e1f7c8189c0c66d03217e1f 100644 (file)
--- a/armor.c
+++ b/armor.c
@@ -1,5 +1,6 @@
-/*
- * armor.c - Routines to (de)armor OpenPGP packet streams.
+/**
+ * @file armor.c
+ * @brief Routines to (de)armor OpenPGP packet streams.
  *
  * Copyright 2002-2004, 2011 Jonathan McDowell <noodles@earth.li>
  *
  * more details.
  *
  * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
 #include <stdlib.h>
 
+#include "build-config.h"
+
 #include "armor.h"
 #include "keystructs.h"
-#include "log.h"
-#include "onak-conf.h"
 #include "parsekey.h"
-#include "version.h"
 
+/**
+ * @brief Line length we'll use for armored output
+ */
 #define ARMOR_WIDTH 64
 
+/**
+ * @brief CRC24 initialisation value
+ */
 #define CRC24_INIT 0xb704ceL
+/**
+ * @brief CRC24 polynomial value
+ */
 #define CRC24_POLY 0x1864cfbL
 
 /**
@@ -46,7 +54,7 @@ static unsigned char encode64(unsigned char c) {
        } else if (c == 63) {
                c = '/';
        } else {
-               log_assert(c < 64);
+               c = '?';
        }
 
        return c;
@@ -76,19 +84,20 @@ static unsigned char decode64(unsigned char c) {
 }
 
 /**
- *     @lastoctet: The last octet we got.
- *     @curoctet: The current octet we're expecting (0, 1 or 2).
- *     @count: The number of octets we've seen.
- *     @crc24: A running CRC24 of the data we've seen.
- *     @putchar_func: The function to output a character.
- *     @ctx: Context for putchar_func.
+ * @brief Holds the context of an ongoing ASCII armor operation
  */
 struct armor_context {
+       /** The last octet we got. */
        unsigned char lastoctet;
+       /** The current octet we're expecting (0, 1 or 2). */
        int curoctet;
+       /** The number of octets we've seen. */
        int count;
+       /** A running CRC24 of the data we've seen. */
        long crc24;
+       /** The function to output a character. */
        int (*putchar_func)(void *ctx, size_t count, void *c);
+       /** Context for putchar_func. */
        void *ctx;
 };
 
@@ -154,7 +163,6 @@ static int armor_putchar_int(void *ctx, unsigned char c)
        unsigned char t;
        int i;
 
-       log_assert(ctx != NULL);
        state = (struct armor_context *) ctx;
 
        switch (state->curoctet++) {
@@ -199,7 +207,6 @@ static int armor_putchar(void *ctx, size_t count, void *c)
 {
        int i;
 
-       log_assert(c != NULL);
 
        for (i = 0; i < count; i++) {
                armor_putchar_int(ctx, ((char *) c)[i]);
@@ -209,19 +216,20 @@ static int armor_putchar(void *ctx, size_t count, void *c)
 }
 
 /**
- *     @lastoctet: The last octet we got.
- *     @curoctet: The current octet we're expecting (0, 1 or 2).
- *     @count: The number of octets we've seen.
- *     @crc24: A running CRC24 of the data we've seen.
- *     @putchar_func: The function to output a character.
- *     @ctx: Context for putchar_func.
+ * @brief Holds the context of an ongoing ASCII dearmor operation
  */
 struct dearmor_context {
+       /** The last octet we got. */
        unsigned char lastoctet;
+       /** The current octet we're expecting (0, 1 or 2). */
        int curoctet;
+       /** The number of octets we've seen. */
        int count;
+       /** A running CRC24 of the data we've seen. */
        long crc24;
+       /** The function to get the next character. */
        int (*getchar_func)(void *ctx, size_t count, void *c);
+       /** Context for getchar_func. */
        void *ctx;
 };
 
@@ -257,7 +265,6 @@ static int dearmor_getchar(void *ctx, unsigned char *c)
        unsigned char tmpc;
        int i;
 
-       log_assert(ctx != NULL);
        state = (struct dearmor_context *) ctx;
        *c = 0;
        
@@ -313,15 +320,6 @@ static int dearmor_getchar_c(void *ctx, size_t count, void *c)
        return rc;
 }
 
-/**
- *     armor_openpgp_stream - Takes a list of OpenPGP packets and armors it.
- *     @putchar_func: The function to output the next armor character.
- *     @ctx: The context pointer for putchar_func.
- *     @packets: The list of packets to output.
- *
- *     This function ASCII armors a list of OpenPGP packets and outputs it
- *     using putchar_func.
- */
 int armor_openpgp_stream(int (*putchar_func)(void *ctx, size_t count,
                                                void *c),
                                void *ctx,
@@ -332,11 +330,9 @@ int armor_openpgp_stream(int (*putchar_func)(void *ctx, size_t count,
        /*
         * Print armor header
         */
-       putchar_func(ctx, sizeof("-----BEGIN PGP PUBLIC KEY BLOCK-----\n") - 1,
-               (unsigned char *) "-----BEGIN PGP PUBLIC KEY BLOCK-----\n");
-       putchar_func(ctx, sizeof("Version: onak " ONAK_VERSION "\n\n") - 1,
-               (unsigned char *) "Version: onak " ONAK_VERSION "\n\n");
-       
+       putchar_func(ctx, sizeof("-----BEGIN PGP PUBLIC KEY BLOCK-----\n\n") - 1,
+               (unsigned char *) "-----BEGIN PGP PUBLIC KEY BLOCK-----\n\n");
+
        armor_init(&armor_ctx);
        armor_ctx.putchar_func = putchar_func;
        armor_ctx.ctx = ctx;
@@ -352,16 +348,6 @@ int armor_openpgp_stream(int (*putchar_func)(void *ctx, size_t count,
        return 0;
 }
 
-/**
- *     dearmor_openpgp_stream - Reads & decodes an ACSII armored OpenPGP msg.
- *     @getchar_func: The function to get the next character from the stream.
- *     @ctx: The context pointer for getchar_func.
- *     @packets: The list of packets.
- *
- *     This function uses getchar_func to read characters from an ASCII
- *     armored OpenPGP stream and outputs the data as a linked list of
- *     packets.
- */
 int dearmor_openpgp_stream(int (*getchar_func)(void *ctx, size_t count,
                                                void *c),
                                void *ctx,