1 // Copyright 2020 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 #ifndef QUICHE_QUIC_CORE_CRYPTO_BORING_UTILS_H_ 6 #define QUICHE_QUIC_CORE_CRYPTO_BORING_UTILS_H_ 7 8 #include "absl/strings/string_view.h" 9 #include "openssl/bytestring.h" 10 #include "quiche/quic/platform/api/quic_export.h" 11 12 namespace quic { 13 CbsToStringPiece(CBS cbs)14inline QUICHE_EXPORT absl::string_view CbsToStringPiece(CBS cbs) { 15 return absl::string_view(reinterpret_cast<const char*>(CBS_data(&cbs)), 16 CBS_len(&cbs)); 17 } 18 StringPieceToCbs(absl::string_view piece)19inline QUICHE_EXPORT CBS StringPieceToCbs(absl::string_view piece) { 20 CBS result; 21 CBS_init(&result, reinterpret_cast<const uint8_t*>(piece.data()), 22 piece.size()); 23 return result; 24 } 25 AddStringToCbb(CBB * cbb,absl::string_view piece)26inline QUICHE_EXPORT bool AddStringToCbb(CBB* cbb, absl::string_view piece) { 27 return 1 == CBB_add_bytes(cbb, reinterpret_cast<const uint8_t*>(piece.data()), 28 piece.size()); 29 } 30 31 } // namespace quic 32 33 #endif // QUICHE_QUIC_CORE_CRYPTO_BORING_UTILS_H_ 34