1 // Copyright 2020 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 ////////////////////////////////////////////////////////////////////////////////
16
17 #include <string>
18
19 #include "absl/strings/escaping.h"
20
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)21 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
22 std::string str (reinterpret_cast<const char*>(data), size);
23 std::string escaped, unescaped;
24 escaped = absl::CHexEscape(str);
25 absl::CUnescape(escaped, &unescaped);
26 if (str != unescaped)
27 abort();
28
29 escaped = absl::CEscape(str);
30 absl::CUnescape(escaped, &unescaped);
31 if (str != unescaped)
32 abort();
33
34 escaped = absl::Utf8SafeCEscape(str);
35 absl::CUnescape(escaped, &unescaped);
36 if (str != unescaped)
37 abort();
38
39 escaped = absl::Utf8SafeCHexEscape(str);
40 absl::CUnescape(escaped, &unescaped);
41 if (str != unescaped)
42 abort();
43
44 std::string encoded, decoded;
45 absl::Base64Escape(str, &encoded);
46 absl::Base64Unescape(encoded, &decoded);
47 if (str != unescaped)
48 abort();
49
50 absl::WebSafeBase64Escape(str, &encoded);
51 absl::WebSafeBase64Unescape(encoded, &decoded);
52 if (str != decoded)
53 abort();
54
55 std::string hex_result, bytes_result;
56 hex_result = absl::BytesToHexString(str);
57 bytes_result = absl::HexStringToBytes(hex_result);
58 if (str != decoded)
59 abort();
60
61 return 0;
62 }