Charles Harrison | 45a9833 | 2017-10-20 03:39:27 | [diff] [blame] | 1 | // 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 <string> |
| 6 | |
| 7 | #include "base/base64.h" |
Hans Wennborg | c3cffa6 | 2020-04-27 10:09:12 | [diff] [blame] | 8 | #include "base/check_op.h" |
Charles Harrison | 45a9833 | 2017-10-20 03:39:27 | [diff] [blame] | 9 | #include "base/strings/string_piece.h" |
| 10 | |
| 11 | // Encode some random data, and then decode it. |
| 12 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
Collin Baker | e21f723d | 2019-09-05 20:05:41 | [diff] [blame] | 13 | base::span<const uint8_t> data_span(data, size); |
Charles Harrison | 45a9833 | 2017-10-20 03:39:27 | [diff] [blame] | 14 | base::StringPiece data_piece(reinterpret_cast<const char*>(data), size); |
Collin Baker | e21f723d | 2019-09-05 20:05:41 | [diff] [blame] | 15 | |
| 16 | const std::string encode_output = base::Base64Encode(data_span); |
| 17 | std::string decode_output; |
Charles Harrison | 45a9833 | 2017-10-20 03:39:27 | [diff] [blame] | 18 | CHECK(base::Base64Decode(encode_output, &decode_output)); |
| 19 | CHECK_EQ(data_piece, decode_output); |
Collin Baker | e21f723d | 2019-09-05 20:05:41 | [diff] [blame] | 20 | |
| 21 | // Also run the StringPiece variant and check that it gives the same results. |
| 22 | std::string string_piece_encode_output; |
| 23 | base::Base64Encode(data_piece, &string_piece_encode_output); |
| 24 | CHECK_EQ(encode_output, string_piece_encode_output); |
| 25 | |
Charles Harrison | 45a9833 | 2017-10-20 03:39:27 | [diff] [blame] | 26 | return 0; |
| 27 | } |