TEST(Base85Test, DecodeOverflow) { EXPECT_FALSE(base85_decode("|NsC1")); EXPECT_FALSE(base85_decode("|NsD0")); EXPECT_FALSE(base85_decode("|NtC0")); EXPECT_FALSE(base85_decode("|OsC0")); EXPECT_FALSE(base85_decode("}NsC0")); }
TEST(Base85Test, DecodeInvalidChar) { EXPECT_FALSE(base85_decode(" 0000")); EXPECT_FALSE(base85_decode("0 000")); EXPECT_FALSE(base85_decode("00 00")); EXPECT_FALSE(base85_decode("000 0")); EXPECT_FALSE(base85_decode("0000 ")); }
int main(int argc, char *argv[]) { char buffer_in[1000], buffer_out[1252]; int len_in, len_out; parse_opts(argc, argv); if (opt_decode) { /* Decoding */ int c = EOF; do { len_in = 0; while (len_in < sizeof(buffer_in)) { if ((c = fgetc(stdin)) == EOF) break; if (base85_code(c) >= 0) buffer_in[len_in++] = c; } len_out = base85_decode(buffer_in, len_in, buffer_out); fwrite(buffer_out, 1, len_out, stdout); } while (c != EOF); } else { /* Encoding */ int n, col = 0; while ((len_in = fread(buffer_in, 1, sizeof(buffer_in), stdin)) > 0) { len_out = base85_encode(buffer_in, len_in, buffer_out); for (n = 0; n < len_out; ++n) { if (col == opt_width) { if (opt_c) fputc('"', stdout); fputc('\n', stdout); col = 0; } if (col == 0 && opt_c) fputc('"', stdout); fputc(buffer_out[n], stdout); ++col; } } if (!opt_raw && col > 0) { if (opt_c) fputc('"', stdout); fputc('\n', stdout); } } return 0; }
TEST(Base85Test, Decode) { using Data = std::vector<std::uint8_t>; EXPECT_EQ(Data(), base85_decode("").value()); EXPECT_EQ(Data(), base85_decode("0").value()); EXPECT_EQ(Data({0}), base85_decode("00").value()); EXPECT_EQ(Data({0, 0}), base85_decode("000").value()); EXPECT_EQ(Data({0, 0, 0}), base85_decode("0000").value()); EXPECT_EQ(Data({0, 0, 0, 0}), base85_decode("00000").value()); EXPECT_EQ(Data({0, 0, 0, 0}), base85_decode("000000").value()); EXPECT_EQ(Data({0, 0, 0, 0, 0}), base85_decode("0000000").value()); EXPECT_EQ(Data({0, 0, 0, 0, 0, 0}), base85_decode("00000000").value()); EXPECT_EQ(Data({0, 0, 0, 0, 0, 0, 0}), base85_decode("000000000").value()); EXPECT_EQ(Data({0, 0, 0, 0, 0, 0, 0, 0}), base85_decode("0000000000").value()); EXPECT_EQ(Data({0x01}), base85_decode("0R").value()); EXPECT_EQ(Data({0x01, 0x23}), base85_decode("0V4").value()); EXPECT_EQ(Data({0x01, 0x23, 0x45}), base85_decode("0V72").value()); EXPECT_EQ(Data({0x01, 0x23, 0x45, 0x67}), base85_decode("0V73c").value()); EXPECT_EQ(Data({0x01, 0x23, 0x45, 0x67, 0x89}), base85_decode("0V73ci2").value()); EXPECT_EQ(Data({0x01, 0x23, 0x45, 0x67, 0x89, 0xab}), base85_decode("0V73ciK_").value()); EXPECT_EQ(Data({0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd}), base85_decode("0V73ciL1>").value()); EXPECT_EQ(Data({0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}), base85_decode("0V73ciL1@;").value()); EXPECT_EQ(Data({0xff, 0xff, 0xff, 0xff}), base85_decode("|NsC0").value()); }