
This is a preparation to fix each files. This CL has no behavior changes. This patch was fully automated using script: https://paste.googleplex.com/5614491201175552 Note that in patchset2, change to: /build/config/unsafe_buffers_paths.txt was reverted. Indeed, running too many (~3) CQ run touching this file is making the builder cache much slower. I will bundle every change to this file in a subsequent CL. I will limit myself to 1-2 CQ run per day. See internal doc about it: https://docs.google.com/document/d/1erdcokeh6rfBqs_h0drHqSLtbDbB61j7j3O2Pz8NH78/edit?resourcekey=0-hNe6w1hYAYyVXGEpWI7HVA&tab=t.0 Bug: 40285824 Change-Id: I52c2f97a60e4d5280ac7b4eee002055ab1ae1cfe Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5717831 Commit-Queue: Sylvain Defresne <sdefresne@chromium.org> Auto-Submit: Arthur Sonzogni <arthursonzogni@chromium.org> Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org> Reviewed-by: Sylvain Defresne <sdefresne@chromium.org> Cr-Commit-Position: refs/heads/main@{#1330100}
58 lines
1.7 KiB
C++
58 lines
1.7 KiB
C++
// Copyright 2012 The Chromium Authors
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
//
|
|
// Uniitest for data encryption functions.
|
|
|
|
#ifdef UNSAFE_BUFFERS_BUILD
|
|
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
|
|
#pragma allow_unsafe_buffers
|
|
#endif
|
|
|
|
#include <stddef.h>
|
|
|
|
#include "testing/gmock/include/gmock/gmock.h"
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
|
|
|
#include "rlz/lib/crc8.h"
|
|
|
|
TEST(Crc8Unittest, TestCrc8) {
|
|
struct Data {
|
|
char string[10];
|
|
// Externally calculated checksums use
|
|
// http://www.zorc.breitbandkatze.de/crc.html
|
|
// with the ATM HEC paramters:
|
|
// CRC-8, Polynomial 0x07, Initial value 0x00, Final XOR value 0x55
|
|
// (direct, don't reverse data byes, don't reverse CRC before final XOR)
|
|
unsigned char external_crc;
|
|
int random_byte;
|
|
unsigned char corrupt_value;
|
|
} data[] = {
|
|
{"Google", 0x01, 2, 0x53},
|
|
{"GOOGLE", 0xA6, 4, 0x11},
|
|
{"My CRC 8!", 0xDC, 0, 0x50},
|
|
};
|
|
|
|
unsigned char* bytes;
|
|
unsigned char crc;
|
|
bool matches;
|
|
int length;
|
|
for (size_t i = 0; i < sizeof(data) / sizeof(data[0]); ++i) {
|
|
bytes = reinterpret_cast<unsigned char*>(data[i].string);
|
|
crc = 0;
|
|
matches = false;
|
|
length = strlen(data[i].string);
|
|
|
|
// Calculate CRC and compare against external value.
|
|
rlz_lib::Crc8::Generate(bytes, length, &crc);
|
|
EXPECT_TRUE(crc == data[i].external_crc);
|
|
rlz_lib::Crc8::Verify(bytes, length, crc, &matches);
|
|
EXPECT_TRUE(matches);
|
|
|
|
// Corrupt string and see if CRC still matches.
|
|
data[i].string[data[i].random_byte] = data[i].corrupt_value;
|
|
rlz_lib::Crc8::Verify(bytes, length, crc, &matches);
|
|
EXPECT_FALSE(matches);
|
|
}
|
|
}
|