Skip to content

Commit

Permalink
Ease checks in armor_write_message_header
Browse files Browse the repository at this point in the history
  • Loading branch information
ni4 authored and antonsviridenko committed Dec 6, 2023
1 parent 2e8617d commit d934fa9
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions src/librepgp/stream-armor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -841,15 +841,12 @@ init_armored_src(pgp_source_t *src, pgp_source_t *readsrc, bool noheaders)
}

/** @brief Write message header to the dst. */
static bool
static void
armor_write_message_header(pgp_dest_armored_param_t *param, bool finish)
{
const char *str = finish ? ST_ARMOR_END : ST_ARMOR_BEGIN;
dst_write(param->writedst, str, strlen(str));
switch (param->type) {
case PGP_ARMORED_MESSAGE:
str = "MESSAGE";
break;
case PGP_ARMORED_PUBLIC_KEY:
str = "PUBLIC KEY BLOCK";
break;
Expand All @@ -859,15 +856,13 @@ armor_write_message_header(pgp_dest_armored_param_t *param, bool finish)
case PGP_ARMORED_SIGNATURE:
str = "SIGNATURE";
break;
case PGP_ARMORED_CLEARTEXT:
str = "SIGNED MESSAGE";
break;
case PGP_ARMORED_MESSAGE:
default:
return false;
str = "MESSAGE";
break;
}
dst_write(param->writedst, str, strlen(str));
dst_write(param->writedst, ST_DASHES, strlen(ST_DASHES));
return true;
}

static void
Expand Down Expand Up @@ -1057,9 +1052,7 @@ armored_dst_finish(pgp_dest_t *dst)
armor_write_eol(param);

/* writing armor header */
if (!armor_write_message_header(param, true)) {
return RNP_ERROR_BAD_PARAMETERS;
}
armor_write_message_header(param, true);
armor_write_eol(param);
return param->writedst->werr;
}
Expand Down Expand Up @@ -1113,11 +1106,7 @@ init_armored_dst(pgp_dest_t *dst, pgp_dest_t *writedst, pgp_armored_msg_t msgtyp
param->eol[1] = CH_LF;
param->llen = 76; /* must be multiple of 4 */
/* armor header */
if (!armor_write_message_header(param, false)) {
RNP_LOG("unknown data type");
armored_dst_close(dst, true);
return RNP_ERROR_BAD_PARAMETERS;
}
armor_write_message_header(param, false);
armor_write_eol(param);
/* empty line */
armor_write_eol(param);
Expand Down

0 comments on commit d934fa9

Please sign in to comment.