Avi Drissman | e4622aa | 2022-09-08 20:36:06 | [diff] [blame] | 1 | // Copyright 2017 The Chromium Authors |
Charles Harrison | 45a9833 | 2017-10-20 03:39:27 | [diff] [blame] | 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> |
Helmut Januschka | 0fc785b | 2024-04-17 21:13:36 | [diff] [blame] | 6 | #include<string_view> |
Charles Harrison | 45a9833 | 2017-10-20 03:39:27 | [diff] [blame] | 7 | |
| 8 | #include"base/base64.h" |
Hans Wennborg | c3cffa6 | 2020-04-27 10:09:12 | [diff] [blame] | 9 | #include"base/check_op.h" |
Daniel Cheng | 17390fd | 2025-06-07 06:38:26 | [diff] [blame] | 10 | #include"base/strings/string_view_util.h" |
Charles Harrison | 45a9833 | 2017-10-20 03:39:27 | [diff] [blame] | 11 | |
| 12 | // Encode some random data, and then decode it. |
danakj | d6537d03 | 2024-05-21 21:32:57 | [diff] [blame] | 13 | extern"C"intLLVMFuzzerTestOneInput(constuint8_t* data_ptr,size_t size){ |
| 14 | // SAFETY: libfuzzer provides a valid pointer and size pair. |
| 15 | auto data= UNSAFE_BUFFERS(base::span(data_ptr, size)); |
| 16 | std::string_view data_string= base::as_string_view(data); |
Collin Baker | e21f723d | 2019-09-05 20:05:41 | [diff] [blame] | 17 | |
danakj | d6537d03 | 2024-05-21 21:32:57 | [diff] [blame] | 18 | const std::string encode_output= base::Base64Encode(data); |
Collin Baker | e21f723d | 2019-09-05 20:05:41 | [diff] [blame] | 19 | std::string decode_output; |
Charles Harrison | 45a9833 | 2017-10-20 03:39:27 | [diff] [blame] | 20 | CHECK(base::Base64Decode(encode_output,&decode_output)); |
danakj | d6537d03 | 2024-05-21 21:32:57 | [diff] [blame] | 21 | CHECK_EQ(data_string, decode_output); |
Collin Baker | e21f723d | 2019-09-05 20:05:41 | [diff] [blame] | 22 | |
Helmut Januschka | 0fc785b | 2024-04-17 21:13:36 | [diff] [blame] | 23 | // Also run the std::string_view variant and check that it gives the same |
| 24 | // results. |
danakj | d6537d03 | 2024-05-21 21:32:57 | [diff] [blame] | 25 | CHECK_EQ(encode_output, base::Base64Encode(data_string)); |
Collin Baker | e21f723d | 2019-09-05 20:05:41 | [diff] [blame] | 26 | |
Charles Harrison | 45a9833 | 2017-10-20 03:39:27 | [diff] [blame] | 27 | return0; |
| 28 | } |