Coverage Report

Created: 2024-11-12 06:16

/src/boringssl/include/openssl/span.h
Line
Count
Source (jump to first uncovered line)
1
/* Copyright (c) 2017, Google Inc.
2
 *
3
 * Permission to use, copy, modify, and/or distribute this software for any
4
 * purpose with or without fee is hereby granted, provided that the above
5
 * copyright notice and this permission notice appear in all copies.
6
 *
7
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10
 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12
 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14
15
#ifndef OPENSSL_HEADER_SSL_SPAN_H
16
#define OPENSSL_HEADER_SSL_SPAN_H
17
18
#include <openssl/base.h>
19
20
#if !defined(BORINGSSL_NO_CXX)
21
22
extern "C++" {
23
24
#include <stdlib.h>
25
26
#include <algorithm>
27
#include <type_traits>
28
29
#if __cplusplus >= 201703L
30
#include <string_view>
31
#endif
32
33
#if defined(__has_include)
34
#if __has_include(<version>)
35
#include <version>
36
#endif
37
#endif
38
39
#if defined(__cpp_lib_ranges) && __cpp_lib_ranges >= 201911L
40
#include <ranges>
41
BSSL_NAMESPACE_BEGIN
42
template <typename T>
43
class Span;
44
BSSL_NAMESPACE_END
45
46
// Mark `Span` as satisfying the `view` and `borrowed_range` concepts. This
47
// should be done before the definition of `Span`, so that any inlined calls to
48
// range functionality use the correct specializations.
49
template <typename T>
50
inline constexpr bool std::ranges::enable_view<bssl::Span<T>> = true;
51
template <typename T>
52
inline constexpr bool std::ranges::enable_borrowed_range<bssl::Span<T>> = true;
53
#endif
54
55
BSSL_NAMESPACE_BEGIN
56
57
template <typename T>
58
class Span;
59
60
namespace internal {
61
template <typename T>
62
class SpanBase {
63
  // Put comparison operator implementations into a base class with const T, so
64
  // they can be used with any type that implicitly converts into a Span.
65
  static_assert(std::is_const<T>::value,
66
                "Span<T> must be derived from SpanBase<const T>");
67
68
279k
  friend bool operator==(Span<T> lhs, Span<T> rhs) {
69
279k
    return std::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
70
279k
  }
71
72
1.69k
  friend bool operator!=(Span<T> lhs, Span<T> rhs) { return !(lhs == rhs); }
73
};
74
75
// Heuristically test whether C is a container type that can be converted into
76
// a Span<T> by checking for data() and size() member functions.
77
//
78
// TODO(davidben): Require C++17 support for std::is_convertible_v, etc.
79
template <typename C, typename T>
80
using EnableIfContainer = std::enable_if_t<
81
    std::is_convertible<decltype(std::declval<C>().data()), T *>::value &&
82
    std::is_integral<decltype(std::declval<C>().size())>::value>;
83
84
}  // namespace internal
85
86
// A Span<T> is a non-owning reference to a contiguous array of objects of type
87
// |T|. Conceptually, a Span is a simple a pointer to |T| and a count of
88
// elements accessible via that pointer. The elements referenced by the Span can
89
// be mutated if |T| is mutable.
90
//
91
// A Span can be constructed from container types implementing |data()| and
92
// |size()| methods. If |T| is constant, construction from a container type is
93
// implicit. This allows writing methods that accept data from some unspecified
94
// container type:
95
//
96
// // Foo views data referenced by v.
97
// void Foo(bssl::Span<const uint8_t> v) { ... }
98
//
99
// std::vector<uint8_t> vec;
100
// Foo(vec);
101
//
102
// For mutable Spans, conversion is explicit:
103
//
104
// // FooMutate mutates data referenced by v.
105
// void FooMutate(bssl::Span<uint8_t> v) { ... }
106
//
107
// FooMutate(bssl::Span<uint8_t>(vec));
108
//
109
// You can also use the |MakeSpan| and |MakeConstSpan| factory methods to
110
// construct Spans in order to deduce the type of the Span automatically.
111
//
112
// FooMutate(bssl::MakeSpan(vec));
113
//
114
// Note that Spans have value type sematics. They are cheap to construct and
115
// copy, and should be passed by value whenever a method would otherwise accept
116
// a reference or pointer to a container or array.
117
template <typename T>
118
class Span : private internal::SpanBase<const T> {
119
 public:
120
  static const size_t npos = static_cast<size_t>(-1);
121
122
  using element_type = T;
123
  using value_type = std::remove_cv_t<T>;
124
  using size_type = size_t;
125
  using difference_type = ptrdiff_t;
126
  using pointer = T *;
127
  using const_pointer = const T *;
128
  using reference = T &;
129
  using const_reference = const T &;
130
  using iterator = T *;
131
  using const_iterator = const T *;
132
133
6.04M
  constexpr Span() : Span(nullptr, 0) {}
bssl::Span<unsigned char const>::Span()
Line
Count
Source
133
4.33M
  constexpr Span() : Span(nullptr, 0) {}
bssl::Span<unsigned short const>::Span()
Line
Count
Source
133
41.8k
  constexpr Span() : Span(nullptr, 0) {}
bssl::Span<unsigned char>::Span()
Line
Count
Source
133
1.67M
  constexpr Span() : Span(nullptr, 0) {}
Unexecuted instantiation: bssl::Span<char const*>::Span()
bssl::Span<char const>::Span()
Line
Count
Source
133
461
  constexpr Span() : Span(nullptr, 0) {}
134
16.2M
  constexpr Span(T *ptr, size_t len) : data_(ptr), size_(len) {}
bssl::Span<unsigned char const>::Span(unsigned char const*, unsigned long)
Line
Count
Source
134
10.4M
  constexpr Span(T *ptr, size_t len) : data_(ptr), size_(len) {}
bssl::Span<unsigned char>::Span(unsigned char*, unsigned long)
Line
Count
Source
134
4.95M
  constexpr Span(T *ptr, size_t len) : data_(ptr), size_(len) {}
bssl::Span<unsigned short const>::Span(unsigned short const*, unsigned long)
Line
Count
Source
134
584k
  constexpr Span(T *ptr, size_t len) : data_(ptr), size_(len) {}
Unexecuted instantiation: bssl::Span<ssl_cipher_st const>::Span(ssl_cipher_st const*, unsigned long)
Unexecuted instantiation: bssl::Span<bool const>::Span(bool const*, unsigned long)
Unexecuted instantiation: bssl::Span<char const* const>::Span(char const* const*, unsigned long)
Unexecuted instantiation: bssl::Span<char const*>::Span(char const**, unsigned long)
Unexecuted instantiation: bssl::Span<bssl::NamedGroup const>::Span(bssl::NamedGroup const*, unsigned long)
bssl::Span<int const>::Span(int const*, unsigned long)
Line
Count
Source
134
6.86k
  constexpr Span(T *ptr, size_t len) : data_(ptr), size_(len) {}
Unexecuted instantiation: bssl::Span<SignatureAlgorithmName const>::Span(SignatureAlgorithmName const*, unsigned long)
bssl::Span<char const>::Span(char const*, unsigned long)
Line
Count
Source
134
240k
  constexpr Span(T *ptr, size_t len) : data_(ptr), size_(len) {}
Unexecuted instantiation: bssl::Span<bssl::VersionInfo const>::Span(bssl::VersionInfo const*, unsigned long)
135
136
  template <size_t N>
137
851k
  constexpr Span(T (&array)[N]) : Span(array, N) {}
bssl::Span<unsigned char const>::Span<1ul>(unsigned char const (&) [1ul])
Line
Count
Source
137
98.3k
  constexpr Span(T (&array)[N]) : Span(array, N) {}
bssl::Span<unsigned short const>::Span<3ul>(unsigned short const (&) [3ul])
Line
Count
Source
137
62.8k
  constexpr Span(T (&array)[N]) : Span(array, N) {}
bssl::Span<unsigned short const>::Span<9ul>(unsigned short const (&) [9ul])
Line
Count
Source
137
104k
  constexpr Span(T (&array)[N]) : Span(array, N) {}
bssl::Span<unsigned char const>::Span<16ul>(unsigned char const (&) [16ul])
Line
Count
Source
137
67
  constexpr Span(T (&array)[N]) : Span(array, N) {}
bssl::Span<unsigned short const>::Span<2ul>(unsigned short const (&) [2ul])
Line
Count
Source
137
6.21k
  constexpr Span(T (&array)[N]) : Span(array, N) {}
bssl::Span<unsigned short const>::Span<12ul>(unsigned short const (&) [12ul])
Line
Count
Source
137
31.8k
  constexpr Span(T (&array)[N]) : Span(array, N) {}
bssl::Span<unsigned char>::Span<65ul>(unsigned char (&) [65ul])
Line
Count
Source
137
54.1k
  constexpr Span(T (&array)[N]) : Span(array, N) {}
bssl::Span<unsigned char const>::Span<8ul>(unsigned char const (&) [8ul])
Line
Count
Source
137
16.2k
  constexpr Span(T (&array)[N]) : Span(array, N) {}
bssl::Span<unsigned char const>::Span<4ul>(unsigned char const (&) [4ul])
Line
Count
Source
137
18.5k
  constexpr Span(T (&array)[N]) : Span(array, N) {}
bssl::Span<unsigned char const>::Span<6ul>(unsigned char const (&) [6ul])
Line
Count
Source
137
2.76k
  constexpr Span(T (&array)[N]) : Span(array, N) {}
bssl::Span<unsigned char const>::Span<32ul>(unsigned char const (&) [32ul])
Line
Count
Source
137
101k
  constexpr Span(T (&array)[N]) : Span(array, N) {}
bssl::Span<unsigned char>::Span<32ul>(unsigned char (&) [32ul])
Line
Count
Source
137
3.04k
  constexpr Span(T (&array)[N]) : Span(array, N) {}
bssl::Span<unsigned char const>::Span<2ul>(unsigned char const (&) [2ul])
Line
Count
Source
137
15.1k
  constexpr Span(T (&array)[N]) : Span(array, N) {}
Unexecuted instantiation: bssl::Span<ssl_cipher_st const>::Span<24ul>(ssl_cipher_st const (&) [24ul])
Unexecuted instantiation: bssl::Span<bssl::NamedGroup const>::Span<7ul>(bssl::NamedGroup const (&) [7ul])
Unexecuted instantiation: bssl::Span<char const* const>::Span<3ul>(char const* const (&) [3ul])
Unexecuted instantiation: bssl::Span<SignatureAlgorithmName const>::Span<14ul>(SignatureAlgorithmName const (&) [14ul])
bssl::Span<unsigned short const>::Span<4ul>(unsigned short const (&) [4ul])
Line
Count
Source
137
323k
  constexpr Span(T (&array)[N]) : Span(array, N) {}
Unexecuted instantiation: bssl::Span<bssl::VersionInfo const>::Span<7ul>(bssl::VersionInfo const (&) [7ul])
bssl::Span<char const>::Span<34ul>(char const (&) [34ul])
Line
Count
Source
137
441
  constexpr Span(T (&array)[N]) : Span(array, N) {}
bssl::Span<char const>::Span<20ul>(char const (&) [20ul])
Line
Count
Source
137
20
  constexpr Span(T (&array)[N]) : Span(array, N) {}
Unexecuted instantiation: bssl::Span<unsigned char>::Span<8ul>(unsigned char (&) [8ul])
Unexecuted instantiation: bssl::Span<unsigned char>::Span<2ul>(unsigned char (&) [2ul])
bssl::Span<unsigned char const>::Span<9ul>(unsigned char const (&) [9ul])
Line
Count
Source
137
4.04k
  constexpr Span(T (&array)[N]) : Span(array, N) {}
bssl::Span<unsigned char const>::Span<3ul>(unsigned char const (&) [3ul])
Line
Count
Source
137
5.79k
  constexpr Span(T (&array)[N]) : Span(array, N) {}
bssl::Span<unsigned char const>::Span<5ul>(unsigned char const (&) [5ul])
Line
Count
Source
137
716
  constexpr Span(T (&array)[N]) : Span(array, N) {}
bssl::Span<unsigned char const>::Span<7ul>(unsigned char const (&) [7ul])
Line
Count
Source
137
621
  constexpr Span(T (&array)[N]) : Span(array, N) {}
Unexecuted instantiation: bssl::Span<unsigned char const>::Span<10ul>(unsigned char const (&) [10ul])
138
139
  template <typename C, typename = internal::EnableIfContainer<C, T>,
140
            typename = std::enable_if_t<std::is_const<T>::value, C>>
141
  constexpr Span(const C &container)
142
5.69M
      : data_(container.data()), size_(container.size()) {}
bssl::Span<unsigned char const>::Span<bssl::Array<unsigned char>, void, bssl::Array<unsigned char> >(bssl::Array<unsigned char> const&)
Line
Count
Source
142
1.24M
      : data_(container.data()), size_(container.size()) {}
bssl::Span<unsigned short const>::Span<bssl::Array<unsigned short>, void, bssl::Array<unsigned short> >(bssl::Array<unsigned short> const&)
Line
Count
Source
142
415k
      : data_(container.data()), size_(container.size()) {}
bssl::Span<unsigned char const>::Span<bssl::InplaceVector<unsigned char, 48ul>, void, bssl::InplaceVector<unsigned char, 48ul> >(bssl::InplaceVector<unsigned char, 48ul> const&)
Line
Count
Source
142
267k
      : data_(container.data()), size_(container.size()) {}
bssl::Span<unsigned char const>::Span<bssl::InplaceVector<unsigned char, 32ul>, void, bssl::InplaceVector<unsigned char, 32ul> >(bssl::InplaceVector<unsigned char, 32ul> const&)
Line
Count
Source
142
540k
      : data_(container.data()), size_(container.size()) {}
bssl::Span<unsigned char const>::Span<bssl::Span<unsigned char>, void, bssl::Span<unsigned char> >(bssl::Span<unsigned char> const&)
Line
Count
Source
142
2.75M
      : data_(container.data()), size_(container.size()) {}
bssl::Span<bool const>::Span<bssl::Array<bool>, void, bssl::Array<bool> >(bssl::Array<bool> const&)
Line
Count
Source
142
17.6k
      : data_(container.data()), size_(container.size()) {}
Unexecuted instantiation: bssl::Span<char const* const>::Span<bssl::Span<char const*>, void, bssl::Span<char const*> >(bssl::Span<char const*> const&)
Unexecuted instantiation: bssl::Span<unsigned char const>::Span<bssl::InplaceVector<unsigned char, 12ul>, void, bssl::InplaceVector<unsigned char, 12ul> >(bssl::InplaceVector<unsigned char, 12ul> const&)
bssl::Span<unsigned char const>::Span<bssl::InplaceVector<unsigned char, 64ul>, void, bssl::InplaceVector<unsigned char, 64ul> >(bssl::InplaceVector<unsigned char, 64ul> const&)
Line
Count
Source
142
54.2k
      : data_(container.data()), size_(container.size()) {}
bssl::Span<unsigned char const>::Span<std::__1::vector<unsigned char, std::__1::allocator<unsigned char> >, void, std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > >(std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > const&)
Line
Count
Source
142
6.71k
      : data_(container.data()), size_(container.size()) {}
bssl::Span<unsigned char const>::Span<bssl::der::Input, void, bssl::der::Input>(bssl::der::Input const&)
Line
Count
Source
142
388k
      : data_(container.data()), size_(container.size()) {}
143
144
  template <typename C, typename = internal::EnableIfContainer<C, T>,
145
            typename = std::enable_if_t<!std::is_const<T>::value, C>>
146
  constexpr explicit Span(C &container)
147
      : data_(container.data()), size_(container.size()) {}
148
149
10.7M
  constexpr T *data() const { return data_; }
bssl::Span<unsigned char const>::data() const
Line
Count
Source
149
7.41M
  constexpr T *data() const { return data_; }
bssl::Span<unsigned char>::data() const
Line
Count
Source
149
3.06M
  constexpr T *data() const { return data_; }
Unexecuted instantiation: bssl::Span<char const*>::data() const
Unexecuted instantiation: bssl::Span<unsigned short const>::data() const
bssl::Span<char const>::data() const
Line
Count
Source
149
240k
  constexpr T *data() const { return data_; }
150
17.0M
  constexpr size_t size() const { return size_; }
bssl::Span<unsigned char const>::size() const
Line
Count
Source
150
12.0M
  constexpr size_t size() const { return size_; }
Unexecuted instantiation: bssl::Span<char const* const>::size() const
Unexecuted instantiation: bssl::Span<char const*>::size() const
bssl::Span<unsigned char>::size() const
Line
Count
Source
150
4.27M
  constexpr size_t size() const { return size_; }
bssl::Span<unsigned short const>::size() const
Line
Count
Source
150
377k
  constexpr size_t size() const { return size_; }
bssl::Span<bool const>::size() const
Line
Count
Source
150
35.2k
  constexpr size_t size() const { return size_; }
Unexecuted instantiation: bssl::Span<ssl_cipher_st const>::size() const
Unexecuted instantiation: bssl::Span<bssl::NamedGroup const>::size() const
bssl::Span<int const>::size() const
Line
Count
Source
150
14.3k
  constexpr size_t size() const { return size_; }
Unexecuted instantiation: bssl::Span<SignatureAlgorithmName const>::size() const
Unexecuted instantiation: bssl::Span<bssl::VersionInfo const>::size() const
bssl::Span<char const>::size() const
Line
Count
Source
150
240k
  constexpr size_t size() const { return size_; }
151
2.17M
  constexpr bool empty() const { return size_ == 0; }
Unexecuted instantiation: bssl::Span<char const*>::empty() const
bssl::Span<unsigned char const>::empty() const
Line
Count
Source
151
1.09M
  constexpr bool empty() const { return size_ == 0; }
bssl::Span<unsigned short const>::empty() const
Line
Count
Source
151
86.5k
  constexpr bool empty() const { return size_ == 0; }
bssl::Span<unsigned char>::empty() const
Line
Count
Source
151
991k
  constexpr bool empty() const { return size_ == 0; }
152
153
3.55M
  constexpr iterator begin() const { return data_; }
bssl::Span<unsigned char const>::begin() const
Line
Count
Source
153
2.54M
  constexpr iterator begin() const { return data_; }
bssl::Span<unsigned short const>::begin() const
Line
Count
Source
153
997k
  constexpr iterator begin() const { return data_; }
bssl::Span<bool const>::begin() const
Line
Count
Source
153
17.6k
  constexpr iterator begin() const { return data_; }
Unexecuted instantiation: bssl::Span<ssl_cipher_st const>::begin() const
Unexecuted instantiation: bssl::Span<bssl::NamedGroup const>::begin() const
154
  constexpr const_iterator cbegin() const { return data_; }
155
3.72M
  constexpr iterator end() const { return data_ + size_; }
bssl::Span<unsigned char const>::end() const
Line
Count
Source
155
2.54M
  constexpr iterator end() const { return data_ + size_; }
bssl::Span<unsigned short const>::end() const
Line
Count
Source
155
1.16M
  constexpr iterator end() const { return data_ + size_; }
bssl::Span<bool const>::end() const
Line
Count
Source
155
17.6k
  constexpr iterator end() const { return data_ + size_; }
Unexecuted instantiation: bssl::Span<ssl_cipher_st const>::end() const
Unexecuted instantiation: bssl::Span<bssl::NamedGroup const>::end() const
156
  constexpr const_iterator cend() const { return end(); }
157
158
5.51k
  constexpr T &front() const {
159
5.51k
    if (size_ == 0) {
160
0
      abort();
161
0
    }
162
5.51k
    return data_[0];
163
5.51k
  }
164
48.7k
  constexpr T &back() const {
165
48.7k
    if (size_ == 0) {
166
0
      abort();
167
0
    }
168
48.7k
    return data_[size_ - 1];
169
48.7k
  }
bssl::Span<unsigned char const>::back() const
Line
Count
Source
164
8.26k
  constexpr T &back() const {
165
8.26k
    if (size_ == 0) {
166
0
      abort();
167
0
    }
168
8.26k
    return data_[size_ - 1];
169
8.26k
  }
bssl::Span<unsigned char>::back() const
Line
Count
Source
164
40.5k
  constexpr T &back() const {
165
40.5k
    if (size_ == 0) {
166
0
      abort();
167
0
    }
168
40.5k
    return data_[size_ - 1];
169
40.5k
  }
170
171
756k
  constexpr T &operator[](size_t i) const {
172
756k
    if (i >= size_) {
173
0
      abort();
174
0
    }
175
756k
    return data_[i];
176
756k
  }
Unexecuted instantiation: bssl::Span<char const*>::operator[](unsigned long) const
Unexecuted instantiation: bssl::Span<char const* const>::operator[](unsigned long) const
bssl::Span<unsigned char const>::operator[](unsigned long) const
Line
Count
Source
171
496k
  constexpr T &operator[](size_t i) const {
172
496k
    if (i >= size_) {
173
0
      abort();
174
0
    }
175
496k
    return data_[i];
176
496k
  }
bssl::Span<unsigned short const>::operator[](unsigned long) const
Line
Count
Source
171
201k
  constexpr T &operator[](size_t i) const {
172
201k
    if (i >= size_) {
173
0
      abort();
174
0
    }
175
201k
    return data_[i];
176
201k
  }
bssl::Span<unsigned char>::operator[](unsigned long) const
Line
Count
Source
171
52.6k
  constexpr T &operator[](size_t i) const {
172
52.6k
    if (i >= size_) {
173
0
      abort();
174
0
    }
175
52.6k
    return data_[i];
176
52.6k
  }
Unexecuted instantiation: bssl::Span<ssl_cipher_st const>::operator[](unsigned long) const
Unexecuted instantiation: bssl::Span<bssl::NamedGroup const>::operator[](unsigned long) const
bssl::Span<int const>::operator[](unsigned long) const
Line
Count
Source
171
4.88k
  constexpr T &operator[](size_t i) const {
172
4.88k
    if (i >= size_) {
173
0
      abort();
174
0
    }
175
4.88k
    return data_[i];
176
4.88k
  }
Unexecuted instantiation: bssl::Span<SignatureAlgorithmName const>::operator[](unsigned long) const
Unexecuted instantiation: bssl::Span<bssl::VersionInfo const>::operator[](unsigned long) const
177
  T &at(size_t i) const { return (*this)[i]; }
178
179
1.54M
  constexpr Span subspan(size_t pos = 0, size_t len = npos) const {
180
1.54M
    if (pos > size_) {
181
      // absl::Span throws an exception here. Note std::span and Chromium
182
      // base::span additionally forbid pos + len being out of range, with a
183
      // special case at npos/dynamic_extent, while absl::Span::subspan clips
184
      // the span. For now, we align with absl::Span in case we switch to it in
185
      // the future.
186
0
      abort();
187
0
    }
188
1.54M
    return Span(data_ + pos, std::min(size_ - pos, len));
189
1.54M
  }
Unexecuted instantiation: bssl::Span<char const*>::subspan(unsigned long, unsigned long) const
bssl::Span<unsigned char>::subspan(unsigned long, unsigned long) const
Line
Count
Source
179
596k
  constexpr Span subspan(size_t pos = 0, size_t len = npos) const {
180
596k
    if (pos > size_) {
181
      // absl::Span throws an exception here. Note std::span and Chromium
182
      // base::span additionally forbid pos + len being out of range, with a
183
      // special case at npos/dynamic_extent, while absl::Span::subspan clips
184
      // the span. For now, we align with absl::Span in case we switch to it in
185
      // the future.
186
0
      abort();
187
0
    }
188
596k
    return Span(data_ + pos, std::min(size_ - pos, len));
189
596k
  }
bssl::Span<unsigned char const>::subspan(unsigned long, unsigned long) const
Line
Count
Source
179
950k
  constexpr Span subspan(size_t pos = 0, size_t len = npos) const {
180
950k
    if (pos > size_) {
181
      // absl::Span throws an exception here. Note std::span and Chromium
182
      // base::span additionally forbid pos + len being out of range, with a
183
      // special case at npos/dynamic_extent, while absl::Span::subspan clips
184
      // the span. For now, we align with absl::Span in case we switch to it in
185
      // the future.
186
0
      abort();
187
0
    }
188
950k
    return Span(data_ + pos, std::min(size_ - pos, len));
189
950k
  }
190
191
25.5k
  constexpr Span first(size_t len) const {
192
25.5k
    if (len > size_) {
193
0
      abort();
194
0
    }
195
25.5k
    return Span(data_, len);
196
25.5k
  }
bssl::Span<unsigned char const>::first(unsigned long) const
Line
Count
Source
191
3.01k
  constexpr Span first(size_t len) const {
192
3.01k
    if (len > size_) {
193
0
      abort();
194
0
    }
195
3.01k
    return Span(data_, len);
196
3.01k
  }
bssl::Span<unsigned char>::first(unsigned long) const
Line
Count
Source
191
22.5k
  constexpr Span first(size_t len) const {
192
22.5k
    if (len > size_) {
193
0
      abort();
194
0
    }
195
22.5k
    return Span(data_, len);
196
22.5k
  }
197
198
7.89k
  constexpr Span last(size_t len) const {
199
7.89k
    if (len > size_) {
200
0
      abort();
201
0
    }
202
7.89k
    return Span(data_ + size_ - len, len);
203
7.89k
  }
bssl::Span<unsigned char>::last(unsigned long) const
Line
Count
Source
198
3.44k
  constexpr Span last(size_t len) const {
199
3.44k
    if (len > size_) {
200
0
      abort();
201
0
    }
202
3.44k
    return Span(data_ + size_ - len, len);
203
3.44k
  }
bssl::Span<unsigned char const>::last(unsigned long) const
Line
Count
Source
198
4.44k
  constexpr Span last(size_t len) const {
199
4.44k
    if (len > size_) {
200
0
      abort();
201
0
    }
202
4.44k
    return Span(data_ + size_ - len, len);
203
4.44k
  }
204
205
 private:
206
  T *data_;
207
  size_t size_;
208
};
209
210
template <typename T>
211
const size_t Span<T>::npos;
212
213
#if __cplusplus >= 201703L
214
template <typename T>
215
Span(T *, size_t) -> Span<T>;
216
template <typename T, size_t size>
217
Span(T (&array)[size]) -> Span<T>;
218
template <
219
    typename C,
220
    typename T = std::remove_pointer_t<decltype(std::declval<C>().data())>,
221
    typename = internal::EnableIfContainer<C, T>>
222
Span(C &) -> Span<T>;
223
#endif
224
225
// C++17 callers can instead rely on CTAD and the deduction guides defined
226
// above.
227
template <typename T>
228
2.62M
constexpr Span<T> MakeSpan(T *ptr, size_t size) {
229
2.62M
  return Span<T>(ptr, size);
230
2.62M
}
Unexecuted instantiation: bssl::Span<char const*> bssl::MakeSpan<char const*>(char const**, unsigned long)
bssl::Span<unsigned char> bssl::MakeSpan<unsigned char>(unsigned char*, unsigned long)
Line
Count
Source
228
2.58M
constexpr Span<T> MakeSpan(T *ptr, size_t size) {
229
2.58M
  return Span<T>(ptr, size);
230
2.58M
}
bssl::Span<unsigned char const> bssl::MakeSpan<unsigned char const>(unsigned char const*, unsigned long)
Line
Count
Source
228
46.2k
constexpr Span<T> MakeSpan(T *ptr, size_t size) {
229
46.2k
  return Span<T>(ptr, size);
230
46.2k
}
231
232
template <typename C>
233
193k
constexpr auto MakeSpan(C &c) -> decltype(MakeSpan(c.data(), c.size())) {
234
193k
  return MakeSpan(c.data(), c.size());
235
193k
}
decltype (MakeSpan(({parm#1}.data)(), ({parm#1}.size)())) bssl::MakeSpan<bssl::Array<unsigned char> >(bssl::Array<unsigned char>&)
Line
Count
Source
233
76.0k
constexpr auto MakeSpan(C &c) -> decltype(MakeSpan(c.data(), c.size())) {
234
76.0k
  return MakeSpan(c.data(), c.size());
235
76.0k
}
decltype (MakeSpan(({parm#1}.data)(), ({parm#1}.size)())) bssl::MakeSpan<bssl::Array<unsigned char> const>(bssl::Array<unsigned char> const&)
Line
Count
Source
233
46.2k
constexpr auto MakeSpan(C &c) -> decltype(MakeSpan(c.data(), c.size())) {
234
46.2k
  return MakeSpan(c.data(), c.size());
235
46.2k
}
decltype (MakeSpan(({parm#1}.data)(), ({parm#1}.size)())) bssl::MakeSpan<bssl::InplaceVector<unsigned char, 48ul> >(bssl::InplaceVector<unsigned char, 48ul>&)
Line
Count
Source
233
71.7k
constexpr auto MakeSpan(C &c) -> decltype(MakeSpan(c.data(), c.size())) {
234
71.7k
  return MakeSpan(c.data(), c.size());
235
71.7k
}
236
237
template <typename T, size_t N>
238
22.5k
constexpr Span<T> MakeSpan(T (&array)[N]) {
239
22.5k
  return Span<T>(array, N);
240
22.5k
}
bssl::Span<unsigned char> bssl::MakeSpan<unsigned char, 80ul>(unsigned char (&) [80ul])
Line
Count
Source
238
11.2k
constexpr Span<T> MakeSpan(T (&array)[N]) {
239
11.2k
  return Span<T>(array, N);
240
11.2k
}
bssl::Span<unsigned char> bssl::MakeSpan<unsigned char, 24ul>(unsigned char (&) [24ul])
Line
Count
Source
238
11.2k
constexpr Span<T> MakeSpan(T (&array)[N]) {
239
11.2k
  return Span<T>(array, N);
240
11.2k
}
Unexecuted instantiation: bssl::Span<unsigned char> bssl::MakeSpan<unsigned char, 32ul>(unsigned char (&) [32ul])
241
242
template <typename T>
243
3.13M
constexpr Span<const T> MakeConstSpan(T *ptr, size_t size) {
244
3.13M
  return Span<const T>(ptr, size);
245
3.13M
}
bssl::Span<unsigned char const> bssl::MakeConstSpan<unsigned char const>(unsigned char const*, unsigned long)
Line
Count
Source
243
2.49M
constexpr Span<const T> MakeConstSpan(T *ptr, size_t size) {
244
2.49M
  return Span<const T>(ptr, size);
245
2.49M
}
bssl::Span<unsigned char const> bssl::MakeConstSpan<unsigned char>(unsigned char*, unsigned long)
Line
Count
Source
243
373k
constexpr Span<const T> MakeConstSpan(T *ptr, size_t size) {
244
373k
  return Span<const T>(ptr, size);
245
373k
}
Unexecuted instantiation: bssl::Span<ssl_cipher_st const> bssl::MakeConstSpan<ssl_cipher_st const>(ssl_cipher_st const*, unsigned long)
Unexecuted instantiation: bssl::Span<char const* const> bssl::MakeConstSpan<char const*>(char const**, unsigned long)
Unexecuted instantiation: bssl::Span<unsigned short const> bssl::MakeConstSpan<unsigned short>(unsigned short*, unsigned long)
Unexecuted instantiation: bssl::Span<bssl::NamedGroup const> bssl::MakeConstSpan<bssl::NamedGroup const>(bssl::NamedGroup const*, unsigned long)
bssl::Span<unsigned short const> bssl::MakeConstSpan<unsigned short const>(unsigned short const*, unsigned long)
Line
Count
Source
243
12.8k
constexpr Span<const T> MakeConstSpan(T *ptr, size_t size) {
244
12.8k
  return Span<const T>(ptr, size);
245
12.8k
}
bssl::Span<int const> bssl::MakeConstSpan<int const>(int const*, unsigned long)
Line
Count
Source
243
6.86k
constexpr Span<const T> MakeConstSpan(T *ptr, size_t size) {
244
6.86k
  return Span<const T>(ptr, size);
245
6.86k
}
bssl::Span<char const> bssl::MakeConstSpan<char const>(char const*, unsigned long)
Line
Count
Source
243
239k
constexpr Span<const T> MakeConstSpan(T *ptr, size_t size) {
244
239k
  return Span<const T>(ptr, size);
245
239k
}
246
247
template <typename C>
248
constexpr auto MakeConstSpan(const C &c)
249
186k
    -> decltype(MakeConstSpan(c.data(), c.size())) {
250
186k
  return MakeConstSpan(c.data(), c.size());
251
186k
}
decltype (MakeConstSpan(({parm#1}.data)(), ({parm#1}.size)())) bssl::MakeConstSpan<bssl::Array<unsigned char> >(bssl::Array<unsigned char> const&)
Line
Count
Source
249
718
    -> decltype(MakeConstSpan(c.data(), c.size())) {
250
718
  return MakeConstSpan(c.data(), c.size());
251
718
}
decltype (MakeConstSpan(({parm#1}.data)(), ({parm#1}.size)())) bssl::MakeConstSpan<bssl::InplaceVector<unsigned char, 32ul> >(bssl::InplaceVector<unsigned char, 32ul> const&)
Line
Count
Source
249
185k
    -> decltype(MakeConstSpan(c.data(), c.size())) {
250
185k
  return MakeConstSpan(c.data(), c.size());
251
185k
}
decltype (MakeConstSpan(({parm#1}.data)(), ({parm#1}.size)())) bssl::MakeConstSpan<bssl::InplaceVector<unsigned char, 48ul> >(bssl::InplaceVector<unsigned char, 48ul> const&)
Line
Count
Source
249
444
    -> decltype(MakeConstSpan(c.data(), c.size())) {
250
444
  return MakeConstSpan(c.data(), c.size());
251
444
}
252
253
template <typename T, size_t size>
254
36.3k
constexpr Span<const T> MakeConstSpan(T (&array)[size]) {
255
36.3k
  return array;
256
36.3k
}
bssl::Span<unsigned short const> bssl::MakeConstSpan<unsigned short const, 12ul>(unsigned short const (&) [12ul])
Line
Count
Source
254
31.8k
constexpr Span<const T> MakeConstSpan(T (&array)[size]) {
255
31.8k
  return array;
256
31.8k
}
bssl::Span<unsigned char const> bssl::MakeConstSpan<unsigned char const, 4ul>(unsigned char const (&) [4ul])
Line
Count
Source
254
1.68k
constexpr Span<const T> MakeConstSpan(T (&array)[size]) {
255
1.68k
  return array;
256
1.68k
}
bssl::Span<unsigned char const> bssl::MakeConstSpan<unsigned char const, 6ul>(unsigned char const (&) [6ul])
Line
Count
Source
254
2.76k
constexpr Span<const T> MakeConstSpan(T (&array)[size]) {
255
2.76k
  return array;
256
2.76k
}
Unexecuted instantiation: bssl::Span<ssl_cipher_st const> bssl::MakeConstSpan<ssl_cipher_st const, 24ul>(ssl_cipher_st const (&) [24ul])
Unexecuted instantiation: bssl::Span<bssl::NamedGroup const> bssl::MakeConstSpan<bssl::NamedGroup const, 7ul>(bssl::NamedGroup const (&) [7ul])
Unexecuted instantiation: bssl::Span<char const* const> bssl::MakeConstSpan<char const*, 3ul>(char const* (&) [3ul])
Unexecuted instantiation: bssl::Span<SignatureAlgorithmName const> bssl::MakeConstSpan<SignatureAlgorithmName const, 14ul>(SignatureAlgorithmName const (&) [14ul])
Unexecuted instantiation: bssl::Span<bssl::VersionInfo const> bssl::MakeConstSpan<bssl::VersionInfo const, 7ul>(bssl::VersionInfo const (&) [7ul])
257
258
#if __cplusplus >= 201703L
259
912
inline Span<const uint8_t> StringAsBytes(std::string_view s) {
260
912
  return MakeConstSpan(reinterpret_cast<const uint8_t *>(s.data()), s.size());
261
912
}
262
263
305k
inline std::string_view BytesAsStringView(bssl::Span<const uint8_t> b) {
264
305k
  return std::string_view(reinterpret_cast<const char *>(b.data()), b.size());
265
305k
}
266
#endif
267
268
BSSL_NAMESPACE_END
269
270
}  // extern C++
271
272
#endif  // !defined(BORINGSSL_NO_CXX)
273
274
#endif  // OPENSSL_HEADER_SSL_SPAN_H