xref: /aosp_15_r20/external/tink/cc/internal/util.h (revision e7b1675dde1b92d52ec075b0a92829627f2c52a5)
1 // Copyright 2021 Google LLC
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 #ifndef TINK_INTERNAL_UTIL_H_
17 #define TINK_INTERNAL_UTIL_H_
18 
19 #include "absl/base/attributes.h"
20 #include "absl/strings/string_view.h"
21 
22 namespace crypto {
23 namespace tink {
24 namespace internal {
25 
26 // Return an empty string if str.data() is nullptr; otherwise return str.
27 absl::string_view EnsureStringNonNull(absl::string_view str);
28 
29 // Returns true if `first` overlaps with `second`.
30 bool BuffersOverlap(absl::string_view first, absl::string_view second);
31 
32 // Returns true if `first` fully overlaps with `second`.
33 bool BuffersAreIdentical(absl::string_view first, absl::string_view second);
34 
35 // Returns true if `input` only contains printable ASCII characters (whitespace
36 // is not allowed).
37 bool IsPrintableAscii(absl::string_view input);
38 
39 // Returns true if built on Windows; false otherwise.
IsWindows()40 inline bool IsWindows() {
41 #if defined(_WIN32)
42   return true;
43 #else
44   return false;
45 #endif
46 }
47 
48 // Wraps Abseil's LOG(FATAL) macro and sets the [noreturn] attribute, which is
49 // useful for avoiding false positive [-Werror=return-type] compiler errors.
50 ABSL_ATTRIBUTE_NORETURN void LogFatal(absl::string_view msg);
51 
52 }  // namespace internal
53 }  // namespace tink
54 }  // namespace crypto
55 
56 #endif  // TINK_INTERNAL_UTIL_H_
57