• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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)14 inline QUIC_EXPORT_PRIVATE 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)19 inline QUIC_EXPORT_PRIVATE 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)26 inline QUIC_EXPORT_PRIVATE bool AddStringToCbb(CBB* cbb,
27                                                absl::string_view piece) {
28   return 1 == CBB_add_bytes(cbb, reinterpret_cast<const uint8_t*>(piece.data()),
29                             piece.size());
30 }
31 
32 }  // namespace quic
33 
34 #endif  // QUICHE_QUIC_CORE_CRYPTO_BORING_UTILS_H_
35