X-Git-Url: https://the.earth.li/gitweb/?a=blobdiff_plain;f=armor.c;h=f218b5595fdf5b8199a30e984a310f03da38f1c9;hb=9aadc77b48c7826015f8ec87cebdc15d012c5f14;hp=9b61b1acde9ce17832907cfae5a8302771b4089a;hpb=e0dd4d10f385cd19da389ec66622eea8aa66ae59;p=onak.git
diff --git a/armor.c b/armor.c
index 9b61b1a..f218b55 100644
--- a/armor.c
+++ b/armor.c
@@ -14,17 +14,16 @@
* 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 .
*/
#include
+#include "build-config.h"
+
#include "armor.h"
#include "keystructs.h"
-#include "onak-conf.h"
#include "parsekey.h"
-#include "version.h"
/**
* @brief Line length we'll use for armored output
@@ -97,7 +96,7 @@ struct armor_context {
/** 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);
+ size_t (*putchar_func)(void *ctx, size_t count, void *c);
/** Context for putchar_func. */
void *ctx;
};
@@ -204,7 +203,7 @@ static int armor_putchar_int(void *ctx, unsigned char c)
}
-static int armor_putchar(void *ctx, size_t count, void *c)
+static size_t armor_putchar(void *ctx, size_t count, void *c)
{
int i;
@@ -212,8 +211,8 @@ static int armor_putchar(void *ctx, size_t count, void *c)
for (i = 0; i < count; i++) {
armor_putchar_int(ctx, ((char *) c)[i]);
}
-
- return 0;
+
+ return count;
}
/**
@@ -229,7 +228,7 @@ struct dearmor_context {
/** 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);
+ size_t (*getchar_func)(void *ctx, size_t count, void *c);
/** Context for getchar_func. */
void *ctx;
};
@@ -310,7 +309,7 @@ static int dearmor_getchar(void *ctx, unsigned char *c)
return (tmpc == 64);
}
-static int dearmor_getchar_c(void *ctx, size_t count, void *c)
+static size_t dearmor_getchar_c(void *ctx, size_t count, void *c)
{
int i, rc = 0;
@@ -318,10 +317,10 @@ static int dearmor_getchar_c(void *ctx, size_t count, void *c)
rc = dearmor_getchar(ctx, &((unsigned char *) c)[i]);
}
- return rc;
+ return (rc == 0) ? i : 0;
}
-int armor_openpgp_stream(int (*putchar_func)(void *ctx, size_t count,
+int armor_openpgp_stream(size_t (*putchar_func)(void *ctx, size_t count,
void *c),
void *ctx,
struct openpgp_packet_list *packets)
@@ -331,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;
@@ -351,7 +348,7 @@ int armor_openpgp_stream(int (*putchar_func)(void *ctx, size_t count,
return 0;
}
-int dearmor_openpgp_stream(int (*getchar_func)(void *ctx, size_t count,
+int dearmor_openpgp_stream(size_t (*getchar_func)(void *ctx, size_t count,
void *c),
void *ctx,
struct openpgp_packet_list **packets)
@@ -366,7 +363,7 @@ int dearmor_openpgp_stream(int (*getchar_func)(void *ctx, size_t count,
* with :s in them, then a blank line, then the data.
*/
state = 1;
- while (state != 4 && !getchar_func(ctx, 1, &curchar)) {
+ while (state != 4 && getchar_func(ctx, 1, &curchar) == 1) {
switch (state) {
case 0:
if (curchar == '\n') {