Skip to content

Commit 091595d

Browse files
ni4Daniel Wyatt
authored and
Daniel Wyatt
committed
Refactored to reduce number of ifs and nesting level.
1 parent 9d0f216 commit 091595d

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

src/librepgp/stream-parse.c

+24-19
Original file line numberDiff line numberDiff line change
@@ -1312,29 +1312,34 @@ encrypted_decrypt_cfb_header(pgp_source_encrypted_param_t *param,
13121312
}
13131313

13141314
pgp_cipher_cfb_decrypt(&crypt, dechdr, enchdr, blsize + 2);
1315-
if ((dechdr[blsize] == dechdr[blsize - 2]) && (dechdr[blsize + 1] == dechdr[blsize - 1])) {
1316-
src_skip(param->pkt.readsrc, blsize + 2);
1317-
param->decrypt = crypt;
1318-
/* init mdc if it is here */
1319-
/* RFC 4880, 5.13: Unlike the Symmetrically Encrypted Data Packet, no special CFB
1320-
* resynchronization is done after encrypting this prefix data. */
1321-
if (!param->has_mdc) {
1322-
pgp_cipher_cfb_resync(&param->decrypt, enchdr + 2);
1323-
} else {
1324-
if (!pgp_hash_create(&param->mdc, PGP_HASH_SHA1)) {
1325-
pgp_cipher_cfb_finish(&crypt);
1326-
RNP_LOG("cannot create sha1 hash");
1327-
return false;
1328-
}
13291315

1330-
pgp_hash_add(&param->mdc, dechdr, blsize + 2);
1331-
}
1316+
if ((dechdr[blsize] != dechdr[blsize - 2]) || (dechdr[blsize + 1] != dechdr[blsize - 1])) {
1317+
RNP_LOG("checksum check failed");
1318+
goto error;
1319+
}
1320+
1321+
src_skip(param->pkt.readsrc, blsize + 2);
1322+
param->decrypt = crypt;
13321323

1324+
/* init mdc if it is here */
1325+
/* RFC 4880, 5.13: Unlike the Symmetrically Encrypted Data Packet, no special CFB
1326+
* resynchronization is done after encrypting this prefix data. */
1327+
if (!param->has_mdc) {
1328+
pgp_cipher_cfb_resync(&param->decrypt, enchdr + 2);
13331329
return true;
1334-
} else {
1335-
pgp_cipher_cfb_finish(&crypt);
1336-
return false;
13371330
}
1331+
1332+
if (!pgp_hash_create(&param->mdc, PGP_HASH_SHA1)) {
1333+
RNP_LOG("cannot create sha1 hash");
1334+
goto error;
1335+
}
1336+
1337+
pgp_hash_add(&param->mdc, dechdr, blsize + 2);
1338+
return true;
1339+
1340+
error:
1341+
pgp_cipher_cfb_finish(&crypt);
1342+
return false;
13381343
}
13391344

13401345
static bool

0 commit comments

Comments
 (0)