/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License , v . 2 . 0 . If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "gtest/gtest.h"
#include <algorithm>
#include <stdint.h>
#include <vector>
#include "../ClearKeyBase64.cpp"
using namespace std;
struct B64Test {
string b64;
vector<uint8_t> raw;
bool shouldPass;
};
MOZ_RUNINIT
const B64Test tests[] = {
{
"AAAAADk4AU4AAAAAAAAAAA" ,
{
0 x0,
0 x0,
0 x0,
0 x0,
0 x39,
0 x38,
0 x1,
0 x4e,
0 x0,
0 x0,
0 x0,
0 x0,
0 x0,
0 x0,
0 x0,
0 x0},
true },
{
"h2mqp1zAJjDIC34YXEXBxA==" ,
{
0 x87,
0 x69,
0 xaa,
0 xa7,
0 x5c,
0 xc0,
0 x26,
0 x30,
0 xc8,
0 xb,
0 x7e,
0 x18,
0 x5c,
0 x45,
0 xc1,
0 xc4},
true },
{
"flcdA35XHQN-Vx0DflcdAw" ,
{
0 x7e,
0 x57,
0 x1d,
0 x3,
0 x7e,
0 x57,
0 x1d,
0 x3,
0 x7e,
0 x57,
0 x1d,
0 x3,
0 x7e,
0 x57,
0 x1d,
0 x3},
true },
{
"flczM35XMzN-VzMzflczMw" ,
{
0 x7e,
0 x57,
0 x33,
0 x33,
0 x7e,
0 x57,
0 x33,
0 x33,
0 x7e,
0 x57,
0 x33,
0 x33,
0 x7e,
0 x57,
0 x33,
0 x33},
true ,
},
{
"flcdBH5XHQR-Vx0EflcdBA" ,
{
0 x7e,
0 x57,
0 x1d,
0 x4,
0 x7e,
0 x57,
0 x1d,
0 x4,
0 x7e,
0 x57,
0 x1d,
0 x4,
0 x7e,
0 x57,
0 x1d,
0 x4},
true },
{
"fldERH5XRER-V0REfldERA" ,
{
0 x7e,
0 x57,
0 x44,
0 x44,
0 x7e,
0 x57,
0 x44,
0 x44,
0 x7e,
0 x57,
0 x44,
0 x44,
0 x7e,
0 x57,
0 x44,
0 x44},
true },
{
"fuzzbiz=" , {
0 x7e,
0 xec,
0 xf3,
0 x6e,
0 x2c},
true },
{
"fuzzbizfuzzbizfuzzbizfuzzbizfuzzbizfuzzbizfuzzbizfuzzbiz" ,
{
0 x7e,
0 xec,
0 xf3,
0 x6e,
0 x2c,
0 xdf,
0 xbb,
0 x3c,
0 xdb,
0 x8b,
0 x37,
0 xee,
0 xcf,
0 x36,
0 xe2,
0 xcd,
0 xfb,
0 xb3,
0 xcd,
0 xb8,
0 xb3,
0 x7e,
0 xec,
0 xf3,
0 x6e,
0 x2c,
0 xdf,
0 xbb,
0 x3c,
0 xdb,
0 x8b,
0 x37,
0 xee,
0 xcf,
0 x36,
0 xe2,
0 xcd,
0 xfb,
0 xb3,
0 xcd,
0 xb8,
0 xb3},
true },
{
"" , {},
true },
{
"00" , {
0 xd3},
true },
{
"000" , {
0 xd3,
0 x4d},
true },
{
"invalid" , {
0 x8a,
0 x7b,
0 xda,
0 x96,
0 x27},
true },
{
"invalic" , {
0 x8a,
0 x7b,
0 xda,
0 x96,
0 x27},
true },
// Failure tests
{
"A" , {},
false },
// 1 character is too few.
{
"_" , {},
false },
// 1 character is too few.
};
TEST(ClearKey, DecodeBase64)
{
for (
const B64Test& test : tests) {
vector<uint8_t> v;
bool rv = DecodeBase64(string(test.b64), v);
EXPECT_EQ(test.shouldPass, rv);
if (test.shouldPass) {
EXPECT_EQ(test.raw.size(), v.size());
for (size_t k =
0 ; k < test.raw.size(); k++) {
EXPECT_EQ(test.raw[k], v[k]);
}
}
}
}
Messung V0.5 in Prozent C=90 H=96 G=93
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet am 2026-06-11)
¤
*© Formatika GbR, Deutschland