blob: 4809e704adbee73582f7ea89279797ca188bc209 [file] [log] [blame]
Jun Choi6d30c4a2017-12-09 01:10:321// Copyright 2017 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <stdint.h>
6#include <algorithm>
7
Jun Choi9f1446c02017-12-21 23:33:278#include "components/cbor/cbor_reader.h" // nogncheck
9#include "components/cbor/cbor_writer.h" // nogncheck
Jun Choi6d30c4a2017-12-09 01:10:3210
Jun Choi9f1446c02017-12-21 23:33:2711namespace cbor {
Jun Choi6d30c4a2017-12-09 01:10:3212
13extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
14 std::vector<uint8_t> input(data, data + size);
15 base::Optional<CBORValue> cbor = CBORReader::Read(input);
16
17 if (cbor.has_value()) {
18 base::Optional<std::vector<uint8_t>> serialized_cbor =
19 CBORWriter::Write(cbor.value());
20 CHECK(serialized_cbor.has_value());
21 if (serialized_cbor.has_value()) {
22 CHECK(serialized_cbor.value().size() == input.size());
23 CHECK(memcmp(serialized_cbor.value().data(), input.data(),
24 input.size()) == 0);
25 }
26 }
27 return 0;
28}
29
Jun Choi9f1446c02017-12-21 23:33:2730} // namespace cbor