/src/boringssl/crypto/mem_internal.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2025 The BoringSSL Authors |
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 | | // https://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 | | #ifndef OPENSSL_HEADER_CRYPTO_MEM_INTERNAL_H |
16 | | #define OPENSSL_HEADER_CRYPTO_MEM_INTERNAL_H |
17 | | |
18 | | #include <openssl/mem.h> |
19 | | |
20 | | #include <algorithm> |
21 | | #include <memory> |
22 | | #include <type_traits> |
23 | | #include <utility> |
24 | | |
25 | | #include <openssl/err.h> |
26 | | #include <openssl/span.h> |
27 | | |
28 | | |
29 | | BSSL_NAMESPACE_BEGIN |
30 | | |
31 | | // Internal allocation-dependent functions. |
32 | | // |
33 | | // This header is separate from crypto/internal.h because there are some files |
34 | | // which must avoid |OPENSSL_malloc|, to avoid a circular dependency, but |
35 | | // need other support routines in crypto/internal.h. (See |
36 | | // |_BORINGSSL_PROHIBIT_OPENSSL_MALLOC|.) |
37 | | |
38 | | |
39 | | // Memory allocation. |
40 | | |
41 | | // New behaves like |new| but uses |OPENSSL_malloc| for memory allocation. It |
42 | | // returns nullptr on allocation error. It only implements single-object |
43 | | // allocation and not new T[n]. |
44 | | // |
45 | | // Note: unlike |new|, this does not support non-public constructors. |
46 | | template <typename T, typename... Args> |
47 | 255k | T *New(Args &&...args) { |
48 | 255k | void *t = OPENSSL_malloc(sizeof(T)); |
49 | 255k | if (t == nullptr) { |
50 | 0 | return nullptr; |
51 | 0 | } |
52 | 255k | return new (t) T(std::forward<Args>(args)...); |
53 | 255k | } Unexecuted instantiation: bssl::DTLSReadEpoch* bssl::New<bssl::DTLSReadEpoch, bssl::DTLSReadEpoch>(bssl::DTLSReadEpoch&&) Unexecuted instantiation: bssl::DTLSWriteEpoch* bssl::New<bssl::DTLSWriteEpoch, bssl::DTLSWriteEpoch>(bssl::DTLSWriteEpoch&&) Unexecuted instantiation: bssl::ECHConfig* bssl::New<bssl::ECHConfig, bssl::ECHConfig>(bssl::ECHConfig&&) ssl_ech_keys_st* bssl::New<ssl_ech_keys_st>() Line | Count | Source | 47 | 2 | T *New(Args &&...args) { | 48 | 2 | void *t = OPENSSL_malloc(sizeof(T)); | 49 | 2 | if (t == nullptr) { | 50 | 0 | return nullptr; | 51 | 0 | } | 52 | 2 | return new (t) T(std::forward<Args>(args)...); | 53 | 2 | } |
bssl::ECHServerConfig* bssl::New<bssl::ECHServerConfig>() Line | Count | Source | 47 | 2 | T *New(Args &&...args) { | 48 | 2 | void *t = OPENSSL_malloc(sizeof(T)); | 49 | 2 | if (t == nullptr) { | 50 | 0 | return nullptr; | 51 | 0 | } | 52 | 2 | return new (t) T(std::forward<Args>(args)...); | 53 | 2 | } |
bssl::SSLPAKEShare* bssl::New<bssl::SSLPAKEShare>() Line | Count | Source | 47 | 3 | T *New(Args &&...args) { | 48 | 3 | void *t = OPENSSL_malloc(sizeof(T)); | 49 | 3 | if (t == nullptr) { | 50 | 0 | return nullptr; | 51 | 0 | } | 52 | 3 | return new (t) T(std::forward<Args>(args)...); | 53 | 3 | } |
Unexecuted instantiation: bssl::spake2plus::Prover* bssl::New<bssl::spake2plus::Prover>() bssl::SSLCipherPreferenceList* bssl::New<bssl::SSLCipherPreferenceList>() Line | Count | Source | 47 | 4 | T *New(Args &&...args) { | 48 | 4 | void *t = OPENSSL_malloc(sizeof(T)); | 49 | 4 | if (t == nullptr) { | 50 | 0 | return nullptr; | 51 | 0 | } | 52 | 4 | return new (t) T(std::forward<Args>(args)...); | 53 | 4 | } |
bssl::SSL_HANDSHAKE_HINTS* bssl::New<bssl::SSL_HANDSHAKE_HINTS>() Line | Count | Source | 47 | 23.6k | T *New(Args &&...args) { | 48 | 23.6k | void *t = OPENSSL_malloc(sizeof(T)); | 49 | 23.6k | if (t == nullptr) { | 50 | 0 | return nullptr; | 51 | 0 | } | 52 | 23.6k | return new (t) T(std::forward<Args>(args)...); | 53 | 23.6k | } |
bssl::SSL_HANDSHAKE* bssl::New<bssl::SSL_HANDSHAKE, ssl_st*&>(ssl_st*&) Line | Count | Source | 47 | 19.3k | T *New(Args &&...args) { | 48 | 19.3k | void *t = OPENSSL_malloc(sizeof(T)); | 49 | 19.3k | if (t == nullptr) { | 50 | 0 | return nullptr; | 51 | 0 | } | 52 | 19.3k | return new (t) T(std::forward<Args>(args)...); | 53 | 19.3k | } |
bssl::SSLAEADContext* bssl::New<bssl::SSLAEADContext, decltype(nullptr)>(decltype(nullptr)&&) Line | Count | Source | 47 | 38.7k | T *New(Args &&...args) { | 48 | 38.7k | void *t = OPENSSL_malloc(sizeof(T)); | 49 | 38.7k | if (t == nullptr) { | 50 | 0 | return nullptr; | 51 | 0 | } | 52 | 38.7k | return new (t) T(std::forward<Args>(args)...); | 53 | 38.7k | } |
bssl::SSLAEADContext* bssl::New<bssl::SSLAEADContext, ssl_cipher_st const*&>(ssl_cipher_st const*&) Line | Count | Source | 47 | 10.4k | T *New(Args &&...args) { | 48 | 10.4k | void *t = OPENSSL_malloc(sizeof(T)); | 49 | 10.4k | if (t == nullptr) { | 50 | 0 | return nullptr; | 51 | 0 | } | 52 | 10.4k | return new (t) T(std::forward<Args>(args)...); | 53 | 10.4k | } |
ssl_credential_st* bssl::New<ssl_credential_st, bssl::SSLCredentialType>(bssl::SSLCredentialType&&) Line | Count | Source | 47 | 19.3k | T *New(Args &&...args) { | 48 | 19.3k | void *t = OPENSSL_malloc(sizeof(T)); | 49 | 19.3k | if (t == nullptr) { | 50 | 0 | return nullptr; | 51 | 0 | } | 52 | 19.3k | return new (t) T(std::forward<Args>(args)...); | 53 | 19.3k | } |
bssl::CERT* bssl::New<bssl::CERT, bssl::SSL_X509_METHOD const*&>(bssl::SSL_X509_METHOD const*&) Line | Count | Source | 47 | 19.3k | T *New(Args &&...args) { | 48 | 19.3k | void *t = OPENSSL_malloc(sizeof(T)); | 49 | 19.3k | if (t == nullptr) { | 50 | 0 | return nullptr; | 51 | 0 | } | 52 | 19.3k | return new (t) T(std::forward<Args>(args)...); | 53 | 19.3k | } |
Unexecuted instantiation: ssl_credential_st* bssl::New<ssl_credential_st, bssl::SSLCredentialType&>(bssl::SSLCredentialType&) ssl_credential_st* bssl::New<ssl_credential_st, bssl::SSLCredentialType const&>(bssl::SSLCredentialType const&) Line | Count | Source | 47 | 19.3k | T *New(Args &&...args) { | 48 | 19.3k | void *t = OPENSSL_malloc(sizeof(T)); | 49 | 19.3k | if (t == nullptr) { | 50 | 0 | return nullptr; | 51 | 0 | } | 52 | 19.3k | return new (t) T(std::forward<Args>(args)...); | 53 | 19.3k | } |
ssl_key_share.cc:bssl::(anonymous namespace)::ECKeyShare* bssl::New<bssl::(anonymous namespace)::ECKeyShare, ec_group_st const*, int>(ec_group_st const*&&, int&&) Line | Count | Source | 47 | 759 | T *New(Args &&...args) { | 48 | 759 | void *t = OPENSSL_malloc(sizeof(T)); | 49 | 759 | if (t == nullptr) { | 50 | 0 | return nullptr; | 51 | 0 | } | 52 | 759 | return new (t) T(std::forward<Args>(args)...); | 53 | 759 | } |
ssl_key_share.cc:bssl::(anonymous namespace)::X25519KeyShare* bssl::New<bssl::(anonymous namespace)::X25519KeyShare>() Line | Count | Source | 47 | 1.94k | T *New(Args &&...args) { | 48 | 1.94k | void *t = OPENSSL_malloc(sizeof(T)); | 49 | 1.94k | if (t == nullptr) { | 50 | 0 | return nullptr; | 51 | 0 | } | 52 | 1.94k | return new (t) T(std::forward<Args>(args)...); | 53 | 1.94k | } |
ssl_key_share.cc:bssl::(anonymous namespace)::X25519Kyber768KeyShare* bssl::New<bssl::(anonymous namespace)::X25519Kyber768KeyShare>() Line | Count | Source | 47 | 53 | T *New(Args &&...args) { | 48 | 53 | void *t = OPENSSL_malloc(sizeof(T)); | 49 | 53 | if (t == nullptr) { | 50 | 0 | return nullptr; | 51 | 0 | } | 52 | 53 | return new (t) T(std::forward<Args>(args)...); | 53 | 53 | } |
ssl_key_share.cc:bssl::(anonymous namespace)::X25519MLKEM768KeyShare* bssl::New<bssl::(anonymous namespace)::X25519MLKEM768KeyShare>() Line | Count | Source | 47 | 56 | T *New(Args &&...args) { | 48 | 56 | void *t = OPENSSL_malloc(sizeof(T)); | 49 | 56 | if (t == nullptr) { | 50 | 0 | return nullptr; | 51 | 0 | } | 52 | 56 | return new (t) T(std::forward<Args>(args)...); | 53 | 56 | } |
ssl_ctx_st* bssl::New<ssl_ctx_st, ssl_method_st const*&>(ssl_method_st const*&) Line | Count | Source | 47 | 2 | T *New(Args &&...args) { | 48 | 2 | void *t = OPENSSL_malloc(sizeof(T)); | 49 | 2 | if (t == nullptr) { | 50 | 0 | return nullptr; | 51 | 0 | } | 52 | 2 | return new (t) T(std::forward<Args>(args)...); | 53 | 2 | } |
bssl::CERT* bssl::New<bssl::CERT, bssl::SSL_X509_METHOD const* const&>(bssl::SSL_X509_METHOD const* const&) Line | Count | Source | 47 | 2 | T *New(Args &&...args) { | 48 | 2 | void *t = OPENSSL_malloc(sizeof(T)); | 49 | 2 | if (t == nullptr) { | 50 | 0 | return nullptr; | 51 | 0 | } | 52 | 2 | return new (t) T(std::forward<Args>(args)...); | 53 | 2 | } |
ssl_st* bssl::New<ssl_st, ssl_ctx_st*&>(ssl_ctx_st*&) Line | Count | Source | 47 | 19.3k | T *New(Args &&...args) { | 48 | 19.3k | void *t = OPENSSL_malloc(sizeof(T)); | 49 | 19.3k | if (t == nullptr) { | 50 | 0 | return nullptr; | 51 | 0 | } | 52 | 19.3k | return new (t) T(std::forward<Args>(args)...); | 53 | 19.3k | } |
bssl::SSL_CONFIG* bssl::New<bssl::SSL_CONFIG, ssl_st*>(ssl_st*&&) Line | Count | Source | 47 | 19.3k | T *New(Args &&...args) { | 48 | 19.3k | void *t = OPENSSL_malloc(sizeof(T)); | 49 | 19.3k | if (t == nullptr) { | 50 | 0 | return nullptr; | 51 | 0 | } | 52 | 19.3k | return new (t) T(std::forward<Args>(args)...); | 53 | 19.3k | } |
bssl::TicketKey* bssl::New<bssl::TicketKey>() Line | Count | Source | 47 | 1 | T *New(Args &&...args) { | 48 | 1 | void *t = OPENSSL_malloc(sizeof(T)); | 49 | 1 | if (t == nullptr) { | 50 | 0 | return nullptr; | 51 | 0 | } | 52 | 1 | return new (t) T(std::forward<Args>(args)...); | 53 | 1 | } |
ssl_session_st* bssl::New<ssl_session_st, bssl::SSL_X509_METHOD const*&>(bssl::SSL_X509_METHOD const*&) Line | Count | Source | 47 | 33.2k | T *New(Args &&...args) { | 48 | 33.2k | void *t = OPENSSL_malloc(sizeof(T)); | 49 | 33.2k | if (t == nullptr) { | 50 | 0 | return nullptr; | 51 | 0 | } | 52 | 33.2k | return new (t) T(std::forward<Args>(args)...); | 53 | 33.2k | } |
Unexecuted instantiation: tls13_enc.cc:bssl::(anonymous namespace)::NullRecordNumberEncrypter* bssl::New<bssl::(anonymous namespace)::NullRecordNumberEncrypter>() Unexecuted instantiation: tls13_enc.cc:bssl::(anonymous namespace)::AES128RecordNumberEncrypter* bssl::New<bssl::(anonymous namespace)::AES128RecordNumberEncrypter>() Unexecuted instantiation: tls13_enc.cc:bssl::(anonymous namespace)::AES256RecordNumberEncrypter* bssl::New<bssl::(anonymous namespace)::AES256RecordNumberEncrypter>() Unexecuted instantiation: tls13_enc.cc:bssl::(anonymous namespace)::ChaChaRecordNumberEncrypter* bssl::New<bssl::(anonymous namespace)::ChaChaRecordNumberEncrypter>() Unexecuted instantiation: bssl::spake2plus::Verifier* bssl::New<bssl::spake2plus::Verifier>() Unexecuted instantiation: bssl::DTLSIncomingMessage* bssl::New<bssl::DTLSIncomingMessage>() Unexecuted instantiation: bssl::MRUQueue<bssl::DTLSSentRecord, 32ul>* bssl::New<bssl::MRUQueue<bssl::DTLSSentRecord, 32ul>>() Unexecuted instantiation: bssl::DTLS1_STATE* bssl::New<bssl::DTLS1_STATE>() Unexecuted instantiation: bssl::DTLSPrevReadEpoch* bssl::New<bssl::DTLSPrevReadEpoch>() bssl::SSL3_STATE* bssl::New<bssl::SSL3_STATE>() Line | Count | Source | 47 | 19.3k | T *New(Args &&...args) { | 48 | 19.3k | void *t = OPENSSL_malloc(sizeof(T)); | 49 | 19.3k | if (t == nullptr) { | 50 | 0 | return nullptr; | 51 | 0 | } | 52 | 19.3k | return new (t) T(std::forward<Args>(args)...); | 53 | 19.3k | } |
bignum_ctx* bssl::New<bignum_ctx>() Line | Count | Source | 47 | 3.88k | T *New(Args &&...args) { | 48 | 3.88k | void *t = OPENSSL_malloc(sizeof(T)); | 49 | 3.88k | if (t == nullptr) { | 50 | 0 | return nullptr; | 51 | 0 | } | 52 | 3.88k | return new (t) T(std::forward<Args>(args)...); | 53 | 3.88k | } |
evp_pkey_ctx_st* bssl::New<evp_pkey_ctx_st>() Line | Count | Source | 47 | 6.70k | T *New(Args &&...args) { | 48 | 6.70k | void *t = OPENSSL_malloc(sizeof(T)); | 49 | 6.70k | if (t == nullptr) { | 50 | 0 | return nullptr; | 51 | 0 | } | 52 | 6.70k | return new (t) T(std::forward<Args>(args)...); | 53 | 6.70k | } |
|
54 | | |
55 | | // Delete behaves like |delete| but uses |OPENSSL_free| to release memory. |
56 | | // |
57 | | // Note: unlike |delete| this does not support non-public destructors. |
58 | | template <typename T> |
59 | 183k | void Delete(T *t) { |
60 | 183k | if (t != nullptr) { |
61 | 183k | t->~T(); |
62 | 183k | OPENSSL_free(t); |
63 | 183k | } |
64 | 183k | } void bssl::Delete<bssl::SSLAEADContext>(bssl::SSLAEADContext*) Line | Count | Source | 59 | 49.2k | void Delete(T *t) { | 60 | 49.2k | if (t != nullptr) { | 61 | 49.2k | t->~T(); | 62 | 49.2k | OPENSSL_free(t); | 63 | 49.2k | } | 64 | 49.2k | } |
Unexecuted instantiation: void bssl::Delete<bssl::RecordNumberEncrypter>(bssl::RecordNumberEncrypter*) Unexecuted instantiation: void bssl::Delete<bssl::DTLSReadEpoch>(bssl::DTLSReadEpoch*) Unexecuted instantiation: void bssl::Delete<bssl::DTLSWriteEpoch>(bssl::DTLSWriteEpoch*) Unexecuted instantiation: void bssl::Delete<bssl::ECHServerConfig>(bssl::ECHServerConfig*) Unexecuted instantiation: void bssl::Delete<bssl::ECHConfig>(bssl::ECHConfig*) void bssl::Delete<bssl::SSLPAKEShare>(bssl::SSLPAKEShare*) Line | Count | Source | 59 | 3 | void Delete(T *t) { | 60 | 3 | if (t != nullptr) { | 61 | 3 | t->~T(); | 62 | 3 | OPENSSL_free(t); | 63 | 3 | } | 64 | 3 | } |
void bssl::Delete<bssl::SSLKeyShare>(bssl::SSLKeyShare*) Line | Count | Source | 59 | 2.80k | void Delete(T *t) { | 60 | 2.80k | if (t != nullptr) { | 61 | 2.80k | t->~T(); | 62 | 2.80k | OPENSSL_free(t); | 63 | 2.80k | } | 64 | 2.80k | } |
Unexecuted instantiation: void bssl::Delete<bssl::spake2plus::Prover>(bssl::spake2plus::Prover*) void bssl::Delete<bssl::SSLCipherPreferenceList>(bssl::SSLCipherPreferenceList*) Line | Count | Source | 59 | 2 | void Delete(T *t) { | 60 | 2 | if (t != nullptr) { | 61 | 2 | t->~T(); | 62 | 2 | OPENSSL_free(t); | 63 | 2 | } | 64 | 2 | } |
void bssl::Delete<bssl::SSL_HANDSHAKE>(bssl::SSL_HANDSHAKE*) Line | Count | Source | 59 | 19.3k | void Delete(T *t) { | 60 | 19.3k | if (t != nullptr) { | 61 | 19.3k | t->~T(); | 62 | 19.3k | OPENSSL_free(t); | 63 | 19.3k | } | 64 | 19.3k | } |
void bssl::Delete<bssl::SSL_HANDSHAKE_HINTS>(bssl::SSL_HANDSHAKE_HINTS*) Line | Count | Source | 59 | 23.6k | void Delete(T *t) { | 60 | 23.6k | if (t != nullptr) { | 61 | 23.6k | t->~T(); | 62 | 23.6k | OPENSSL_free(t); | 63 | 23.6k | } | 64 | 23.6k | } |
Unexecuted instantiation: void bssl::Delete<bssl::spake2plus::Verifier>(bssl::spake2plus::Verifier*) void bssl::Delete<bssl::CERT>(bssl::CERT*) Line | Count | Source | 59 | 19.3k | void Delete(T *t) { | 60 | 19.3k | if (t != nullptr) { | 61 | 19.3k | t->~T(); | 62 | 19.3k | OPENSSL_free(t); | 63 | 19.3k | } | 64 | 19.3k | } |
Unexecuted instantiation: ssl_key_share.cc:void bssl::Delete<bssl::(anonymous namespace)::ECKeyShare>(bssl::(anonymous namespace)::ECKeyShare*) Unexecuted instantiation: ssl_key_share.cc:void bssl::Delete<bssl::(anonymous namespace)::X25519KeyShare>(bssl::(anonymous namespace)::X25519KeyShare*) Unexecuted instantiation: ssl_key_share.cc:void bssl::Delete<bssl::(anonymous namespace)::X25519Kyber768KeyShare>(bssl::(anonymous namespace)::X25519Kyber768KeyShare*) Unexecuted instantiation: ssl_key_share.cc:void bssl::Delete<bssl::(anonymous namespace)::X25519MLKEM768KeyShare>(bssl::(anonymous namespace)::X25519MLKEM768KeyShare*) void bssl::Delete<bssl::SSL_CONFIG>(bssl::SSL_CONFIG*) Line | Count | Source | 59 | 19.3k | void Delete(T *t) { | 60 | 19.3k | if (t != nullptr) { | 61 | 19.3k | t->~T(); | 62 | 19.3k | OPENSSL_free(t); | 63 | 19.3k | } | 64 | 19.3k | } |
void bssl::Delete<ssl_st>(ssl_st*) Line | Count | Source | 59 | 19.3k | void Delete(T *t) { | 60 | 19.3k | if (t != nullptr) { | 61 | 19.3k | t->~T(); | 62 | 19.3k | OPENSSL_free(t); | 63 | 19.3k | } | 64 | 19.3k | } |
Unexecuted instantiation: void bssl::Delete<bssl::TicketKey>(bssl::TicketKey*) Unexecuted instantiation: tls13_enc.cc:void bssl::Delete<bssl::(anonymous namespace)::NullRecordNumberEncrypter>(bssl::(anonymous namespace)::NullRecordNumberEncrypter*) Unexecuted instantiation: tls13_enc.cc:void bssl::Delete<bssl::(anonymous namespace)::AES128RecordNumberEncrypter>(bssl::(anonymous namespace)::AES128RecordNumberEncrypter*) Unexecuted instantiation: tls13_enc.cc:void bssl::Delete<bssl::(anonymous namespace)::AES256RecordNumberEncrypter>(bssl::(anonymous namespace)::AES256RecordNumberEncrypter*) Unexecuted instantiation: tls13_enc.cc:void bssl::Delete<bssl::(anonymous namespace)::ChaChaRecordNumberEncrypter>(bssl::(anonymous namespace)::ChaChaRecordNumberEncrypter*) Unexecuted instantiation: void bssl::Delete<bssl::MRUQueue<bssl::DTLSSentRecord, 32ul> >(bssl::MRUQueue<bssl::DTLSSentRecord, 32ul>*) Unexecuted instantiation: void bssl::Delete<bssl::DTLSIncomingMessage>(bssl::DTLSIncomingMessage*) Unexecuted instantiation: void bssl::Delete<bssl::DTLSPrevReadEpoch>(bssl::DTLSPrevReadEpoch*) Unexecuted instantiation: void bssl::Delete<bssl::DTLS1_STATE>(bssl::DTLS1_STATE*) void bssl::Delete<bssl::SSL3_STATE>(bssl::SSL3_STATE*) Line | Count | Source | 59 | 19.3k | void Delete(T *t) { | 60 | 19.3k | if (t != nullptr) { | 61 | 19.3k | t->~T(); | 62 | 19.3k | OPENSSL_free(t); | 63 | 19.3k | } | 64 | 19.3k | } |
void bssl::Delete<bignum_ctx>(bignum_ctx*) Line | Count | Source | 59 | 4.26k | void Delete(T *t) { | 60 | 4.26k | if (t != nullptr) { | 61 | 3.88k | t->~T(); | 62 | 3.88k | OPENSSL_free(t); | 63 | 3.88k | } | 64 | 4.26k | } |
void bssl::Delete<evp_pkey_ctx_st>(evp_pkey_ctx_st*) Line | Count | Source | 59 | 6.70k | void Delete(T *t) { | 60 | 6.70k | if (t != nullptr) { | 61 | 6.70k | t->~T(); | 62 | 6.70k | OPENSSL_free(t); | 63 | 6.70k | } | 64 | 6.70k | } |
|
65 | | |
66 | | // All types with kAllowUniquePtr set may be used with UniquePtr. Other types |
67 | | // may be C structs which require a |BORINGSSL_MAKE_DELETER| registration. |
68 | | namespace internal { |
69 | | template <typename T> |
70 | | struct DeleterImpl<T, std::enable_if_t<T::kAllowUniquePtr>> { |
71 | 133k | static void Free(T *t) { Delete(t); } bssl::internal::DeleterImpl<bssl::SSLAEADContext, void>::Free(bssl::SSLAEADContext*) Line | Count | Source | 71 | 49.2k | static void Free(T *t) { Delete(t); } |
Unexecuted instantiation: bssl::internal::DeleterImpl<bssl::RecordNumberEncrypter, void>::Free(bssl::RecordNumberEncrypter*) Unexecuted instantiation: bssl::internal::DeleterImpl<bssl::DTLSReadEpoch, void>::Free(bssl::DTLSReadEpoch*) Unexecuted instantiation: bssl::internal::DeleterImpl<bssl::DTLSWriteEpoch, void>::Free(bssl::DTLSWriteEpoch*) Unexecuted instantiation: bssl::internal::DeleterImpl<bssl::ECHServerConfig, void>::Free(bssl::ECHServerConfig*) Unexecuted instantiation: bssl::internal::DeleterImpl<bssl::ECHConfig, void>::Free(bssl::ECHConfig*) bssl::internal::DeleterImpl<bssl::SSLPAKEShare, void>::Free(bssl::SSLPAKEShare*) Line | Count | Source | 71 | 3 | static void Free(T *t) { Delete(t); } |
bssl::internal::DeleterImpl<bssl::SSLKeyShare, void>::Free(bssl::SSLKeyShare*) Line | Count | Source | 71 | 2.80k | static void Free(T *t) { Delete(t); } |
Unexecuted instantiation: bssl::internal::DeleterImpl<bssl::spake2plus::Prover, void>::Free(bssl::spake2plus::Prover*) bssl::internal::DeleterImpl<bssl::SSLCipherPreferenceList, void>::Free(bssl::SSLCipherPreferenceList*) Line | Count | Source | 71 | 2 | static void Free(T *t) { Delete(t); } |
bssl::internal::DeleterImpl<bssl::SSL_HANDSHAKE, void>::Free(bssl::SSL_HANDSHAKE*) Line | Count | Source | 71 | 19.3k | static void Free(T *t) { Delete(t); } |
bssl::internal::DeleterImpl<bssl::SSL_HANDSHAKE_HINTS, void>::Free(bssl::SSL_HANDSHAKE_HINTS*) Line | Count | Source | 71 | 23.6k | static void Free(T *t) { Delete(t); } |
Unexecuted instantiation: bssl::internal::DeleterImpl<bssl::spake2plus::Verifier, void>::Free(bssl::spake2plus::Verifier*) bssl::internal::DeleterImpl<bssl::CERT, void>::Free(bssl::CERT*) Line | Count | Source | 71 | 19.3k | static void Free(T *t) { Delete(t); } |
Unexecuted instantiation: ssl_key_share.cc:bssl::internal::DeleterImpl<bssl::(anonymous namespace)::ECKeyShare, void>::Free(bssl::(anonymous namespace)::ECKeyShare*) Unexecuted instantiation: ssl_key_share.cc:bssl::internal::DeleterImpl<bssl::(anonymous namespace)::X25519KeyShare, void>::Free(bssl::(anonymous namespace)::X25519KeyShare*) Unexecuted instantiation: ssl_key_share.cc:bssl::internal::DeleterImpl<bssl::(anonymous namespace)::X25519Kyber768KeyShare, void>::Free(bssl::(anonymous namespace)::X25519Kyber768KeyShare*) Unexecuted instantiation: ssl_key_share.cc:bssl::internal::DeleterImpl<bssl::(anonymous namespace)::X25519MLKEM768KeyShare, void>::Free(bssl::(anonymous namespace)::X25519MLKEM768KeyShare*) bssl::internal::DeleterImpl<bssl::SSL_CONFIG, void>::Free(bssl::SSL_CONFIG*) Line | Count | Source | 71 | 19.3k | static void Free(T *t) { Delete(t); } |
Unexecuted instantiation: bssl::internal::DeleterImpl<bssl::TicketKey, void>::Free(bssl::TicketKey*) Unexecuted instantiation: tls13_enc.cc:bssl::internal::DeleterImpl<bssl::(anonymous namespace)::NullRecordNumberEncrypter, void>::Free(bssl::(anonymous namespace)::NullRecordNumberEncrypter*) Unexecuted instantiation: tls13_enc.cc:bssl::internal::DeleterImpl<bssl::(anonymous namespace)::AES128RecordNumberEncrypter, void>::Free(bssl::(anonymous namespace)::AES128RecordNumberEncrypter*) Unexecuted instantiation: tls13_enc.cc:bssl::internal::DeleterImpl<bssl::(anonymous namespace)::AES256RecordNumberEncrypter, void>::Free(bssl::(anonymous namespace)::AES256RecordNumberEncrypter*) Unexecuted instantiation: tls13_enc.cc:bssl::internal::DeleterImpl<bssl::(anonymous namespace)::ChaChaRecordNumberEncrypter, void>::Free(bssl::(anonymous namespace)::ChaChaRecordNumberEncrypter*) Unexecuted instantiation: bssl::internal::DeleterImpl<bssl::MRUQueue<bssl::DTLSSentRecord, 32ul>, void>::Free(bssl::MRUQueue<bssl::DTLSSentRecord, 32ul>*) Unexecuted instantiation: bssl::internal::DeleterImpl<bssl::DTLSIncomingMessage, void>::Free(bssl::DTLSIncomingMessage*) Unexecuted instantiation: bssl::internal::DeleterImpl<bssl::DTLSPrevReadEpoch, void>::Free(bssl::DTLSPrevReadEpoch*) Unexecuted instantiation: bssl::internal::DeleterImpl<bssl::DTLS1_STATE, void>::Free(bssl::DTLS1_STATE*) Unexecuted instantiation: bssl::internal::DeleterImpl<bssl::SSL3_STATE, void>::Free(bssl::SSL3_STATE*) |
72 | | }; |
73 | | } // namespace internal |
74 | | |
75 | | // MakeUnique behaves like |std::make_unique| but returns nullptr on allocation |
76 | | // error. |
77 | | template <typename T, typename... Args> |
78 | 251k | UniquePtr<T> MakeUnique(Args &&...args) { |
79 | 251k | return UniquePtr<T>(New<T>(std::forward<Args>(args)...)); |
80 | 251k | } Unexecuted instantiation: std::__1::unique_ptr<bssl::DTLSReadEpoch, bssl::internal::Deleter> bssl::MakeUnique<bssl::DTLSReadEpoch, bssl::DTLSReadEpoch>(bssl::DTLSReadEpoch&&) Unexecuted instantiation: std::__1::unique_ptr<bssl::DTLSWriteEpoch, bssl::internal::Deleter> bssl::MakeUnique<bssl::DTLSWriteEpoch, bssl::DTLSWriteEpoch>(bssl::DTLSWriteEpoch&&) Unexecuted instantiation: std::__1::unique_ptr<bssl::ECHConfig, bssl::internal::Deleter> bssl::MakeUnique<bssl::ECHConfig, bssl::ECHConfig>(bssl::ECHConfig&&) std::__1::unique_ptr<bssl::ECHServerConfig, bssl::internal::Deleter> bssl::MakeUnique<bssl::ECHServerConfig>() Line | Count | Source | 78 | 2 | UniquePtr<T> MakeUnique(Args &&...args) { | 79 | 2 | return UniquePtr<T>(New<T>(std::forward<Args>(args)...)); | 80 | 2 | } |
std::__1::unique_ptr<bssl::SSLPAKEShare, bssl::internal::Deleter> bssl::MakeUnique<bssl::SSLPAKEShare>() Line | Count | Source | 78 | 3 | UniquePtr<T> MakeUnique(Args &&...args) { | 79 | 3 | return UniquePtr<T>(New<T>(std::forward<Args>(args)...)); | 80 | 3 | } |
Unexecuted instantiation: std::__1::unique_ptr<bssl::spake2plus::Prover, bssl::internal::Deleter> bssl::MakeUnique<bssl::spake2plus::Prover>() std::__1::unique_ptr<bssl::SSLCipherPreferenceList, bssl::internal::Deleter> bssl::MakeUnique<bssl::SSLCipherPreferenceList>() Line | Count | Source | 78 | 4 | UniquePtr<T> MakeUnique(Args &&...args) { | 79 | 4 | return UniquePtr<T>(New<T>(std::forward<Args>(args)...)); | 80 | 4 | } |
std::__1::unique_ptr<bssl::SSL_HANDSHAKE_HINTS, bssl::internal::Deleter> bssl::MakeUnique<bssl::SSL_HANDSHAKE_HINTS>() Line | Count | Source | 78 | 23.6k | UniquePtr<T> MakeUnique(Args &&...args) { | 79 | 23.6k | return UniquePtr<T>(New<T>(std::forward<Args>(args)...)); | 80 | 23.6k | } |
std::__1::unique_ptr<bssl::SSL_HANDSHAKE, bssl::internal::Deleter> bssl::MakeUnique<bssl::SSL_HANDSHAKE, ssl_st*&>(ssl_st*&) Line | Count | Source | 78 | 19.3k | UniquePtr<T> MakeUnique(Args &&...args) { | 79 | 19.3k | return UniquePtr<T>(New<T>(std::forward<Args>(args)...)); | 80 | 19.3k | } |
std::__1::unique_ptr<bssl::SSLAEADContext, bssl::internal::Deleter> bssl::MakeUnique<bssl::SSLAEADContext, decltype(nullptr)>(decltype(nullptr)&&) Line | Count | Source | 78 | 38.7k | UniquePtr<T> MakeUnique(Args &&...args) { | 79 | 38.7k | return UniquePtr<T>(New<T>(std::forward<Args>(args)...)); | 80 | 38.7k | } |
std::__1::unique_ptr<bssl::SSLAEADContext, bssl::internal::Deleter> bssl::MakeUnique<bssl::SSLAEADContext, ssl_cipher_st const*&>(ssl_cipher_st const*&) Line | Count | Source | 78 | 10.4k | UniquePtr<T> MakeUnique(Args &&...args) { | 79 | 10.4k | return UniquePtr<T>(New<T>(std::forward<Args>(args)...)); | 80 | 10.4k | } |
std::__1::unique_ptr<ssl_credential_st, bssl::internal::Deleter> bssl::MakeUnique<ssl_credential_st, bssl::SSLCredentialType>(bssl::SSLCredentialType&&) Line | Count | Source | 78 | 19.3k | UniquePtr<T> MakeUnique(Args &&...args) { | 79 | 19.3k | return UniquePtr<T>(New<T>(std::forward<Args>(args)...)); | 80 | 19.3k | } |
std::__1::unique_ptr<bssl::CERT, bssl::internal::Deleter> bssl::MakeUnique<bssl::CERT, bssl::SSL_X509_METHOD const*&>(bssl::SSL_X509_METHOD const*&) Line | Count | Source | 78 | 19.3k | UniquePtr<T> MakeUnique(Args &&...args) { | 79 | 19.3k | return UniquePtr<T>(New<T>(std::forward<Args>(args)...)); | 80 | 19.3k | } |
Unexecuted instantiation: std::__1::unique_ptr<ssl_credential_st, bssl::internal::Deleter> bssl::MakeUnique<ssl_credential_st, bssl::SSLCredentialType&>(bssl::SSLCredentialType&) std::__1::unique_ptr<ssl_credential_st, bssl::internal::Deleter> bssl::MakeUnique<ssl_credential_st, bssl::SSLCredentialType const&>(bssl::SSLCredentialType const&) Line | Count | Source | 78 | 19.3k | UniquePtr<T> MakeUnique(Args &&...args) { | 79 | 19.3k | return UniquePtr<T>(New<T>(std::forward<Args>(args)...)); | 80 | 19.3k | } |
ssl_key_share.cc:std::__1::unique_ptr<bssl::(anonymous namespace)::ECKeyShare, bssl::internal::Deleter> bssl::MakeUnique<bssl::(anonymous namespace)::ECKeyShare, ec_group_st const*, int>(ec_group_st const*&&, int&&) Line | Count | Source | 78 | 759 | UniquePtr<T> MakeUnique(Args &&...args) { | 79 | 759 | return UniquePtr<T>(New<T>(std::forward<Args>(args)...)); | 80 | 759 | } |
ssl_key_share.cc:std::__1::unique_ptr<bssl::(anonymous namespace)::X25519KeyShare, bssl::internal::Deleter> bssl::MakeUnique<bssl::(anonymous namespace)::X25519KeyShare>() Line | Count | Source | 78 | 1.94k | UniquePtr<T> MakeUnique(Args &&...args) { | 79 | 1.94k | return UniquePtr<T>(New<T>(std::forward<Args>(args)...)); | 80 | 1.94k | } |
ssl_key_share.cc:std::__1::unique_ptr<bssl::(anonymous namespace)::X25519Kyber768KeyShare, bssl::internal::Deleter> bssl::MakeUnique<bssl::(anonymous namespace)::X25519Kyber768KeyShare>() Line | Count | Source | 78 | 53 | UniquePtr<T> MakeUnique(Args &&...args) { | 79 | 53 | return UniquePtr<T>(New<T>(std::forward<Args>(args)...)); | 80 | 53 | } |
ssl_key_share.cc:std::__1::unique_ptr<bssl::(anonymous namespace)::X25519MLKEM768KeyShare, bssl::internal::Deleter> bssl::MakeUnique<bssl::(anonymous namespace)::X25519MLKEM768KeyShare>() Line | Count | Source | 78 | 56 | UniquePtr<T> MakeUnique(Args &&...args) { | 79 | 56 | return UniquePtr<T>(New<T>(std::forward<Args>(args)...)); | 80 | 56 | } |
std::__1::unique_ptr<ssl_ctx_st, bssl::internal::Deleter> bssl::MakeUnique<ssl_ctx_st, ssl_method_st const*&>(ssl_method_st const*&) Line | Count | Source | 78 | 2 | UniquePtr<T> MakeUnique(Args &&...args) { | 79 | 2 | return UniquePtr<T>(New<T>(std::forward<Args>(args)...)); | 80 | 2 | } |
std::__1::unique_ptr<bssl::CERT, bssl::internal::Deleter> bssl::MakeUnique<bssl::CERT, bssl::SSL_X509_METHOD const* const&>(bssl::SSL_X509_METHOD const* const&) Line | Count | Source | 78 | 2 | UniquePtr<T> MakeUnique(Args &&...args) { | 79 | 2 | return UniquePtr<T>(New<T>(std::forward<Args>(args)...)); | 80 | 2 | } |
std::__1::unique_ptr<ssl_st, bssl::internal::Deleter> bssl::MakeUnique<ssl_st, ssl_ctx_st*&>(ssl_ctx_st*&) Line | Count | Source | 78 | 19.3k | UniquePtr<T> MakeUnique(Args &&...args) { | 79 | 19.3k | return UniquePtr<T>(New<T>(std::forward<Args>(args)...)); | 80 | 19.3k | } |
std::__1::unique_ptr<bssl::SSL_CONFIG, bssl::internal::Deleter> bssl::MakeUnique<bssl::SSL_CONFIG, ssl_st*>(ssl_st*&&) Line | Count | Source | 78 | 19.3k | UniquePtr<T> MakeUnique(Args &&...args) { | 79 | 19.3k | return UniquePtr<T>(New<T>(std::forward<Args>(args)...)); | 80 | 19.3k | } |
std::__1::unique_ptr<bssl::TicketKey, bssl::internal::Deleter> bssl::MakeUnique<bssl::TicketKey>() Line | Count | Source | 78 | 1 | UniquePtr<T> MakeUnique(Args &&...args) { | 79 | 1 | return UniquePtr<T>(New<T>(std::forward<Args>(args)...)); | 80 | 1 | } |
std::__1::unique_ptr<ssl_session_st, bssl::internal::Deleter> bssl::MakeUnique<ssl_session_st, bssl::SSL_X509_METHOD const*&>(bssl::SSL_X509_METHOD const*&) Line | Count | Source | 78 | 33.2k | UniquePtr<T> MakeUnique(Args &&...args) { | 79 | 33.2k | return UniquePtr<T>(New<T>(std::forward<Args>(args)...)); | 80 | 33.2k | } |
Unexecuted instantiation: tls13_enc.cc:std::__1::unique_ptr<bssl::(anonymous namespace)::NullRecordNumberEncrypter, bssl::internal::Deleter> bssl::MakeUnique<bssl::(anonymous namespace)::NullRecordNumberEncrypter>() Unexecuted instantiation: tls13_enc.cc:std::__1::unique_ptr<bssl::(anonymous namespace)::AES128RecordNumberEncrypter, bssl::internal::Deleter> bssl::MakeUnique<bssl::(anonymous namespace)::AES128RecordNumberEncrypter>() Unexecuted instantiation: tls13_enc.cc:std::__1::unique_ptr<bssl::(anonymous namespace)::AES256RecordNumberEncrypter, bssl::internal::Deleter> bssl::MakeUnique<bssl::(anonymous namespace)::AES256RecordNumberEncrypter>() Unexecuted instantiation: tls13_enc.cc:std::__1::unique_ptr<bssl::(anonymous namespace)::ChaChaRecordNumberEncrypter, bssl::internal::Deleter> bssl::MakeUnique<bssl::(anonymous namespace)::ChaChaRecordNumberEncrypter>() Unexecuted instantiation: std::__1::unique_ptr<bssl::spake2plus::Verifier, bssl::internal::Deleter> bssl::MakeUnique<bssl::spake2plus::Verifier>() Unexecuted instantiation: std::__1::unique_ptr<bssl::DTLSIncomingMessage, bssl::internal::Deleter> bssl::MakeUnique<bssl::DTLSIncomingMessage>() Unexecuted instantiation: std::__1::unique_ptr<bssl::MRUQueue<bssl::DTLSSentRecord, 32ul>, bssl::internal::Deleter> bssl::MakeUnique<bssl::MRUQueue<bssl::DTLSSentRecord, 32ul>>() Unexecuted instantiation: std::__1::unique_ptr<bssl::DTLS1_STATE, bssl::internal::Deleter> bssl::MakeUnique<bssl::DTLS1_STATE>() Unexecuted instantiation: std::__1::unique_ptr<bssl::DTLSPrevReadEpoch, bssl::internal::Deleter> bssl::MakeUnique<bssl::DTLSPrevReadEpoch>() std::__1::unique_ptr<bssl::SSL3_STATE, bssl::internal::Deleter> bssl::MakeUnique<bssl::SSL3_STATE>() Line | Count | Source | 78 | 19.3k | UniquePtr<T> MakeUnique(Args &&...args) { | 79 | 19.3k | return UniquePtr<T>(New<T>(std::forward<Args>(args)...)); | 80 | 19.3k | } |
std::__1::unique_ptr<evp_pkey_ctx_st, bssl::internal::Deleter> bssl::MakeUnique<evp_pkey_ctx_st>() Line | Count | Source | 78 | 6.70k | UniquePtr<T> MakeUnique(Args &&...args) { | 79 | 6.70k | return UniquePtr<T>(New<T>(std::forward<Args>(args)...)); | 80 | 6.70k | } |
|
81 | | |
82 | | |
83 | | // Containers. |
84 | | |
85 | | // Array<T> is an owning array of elements of |T|. |
86 | | template <typename T> |
87 | | class Array { |
88 | | public: |
89 | | // Array's default constructor creates an empty array. |
90 | 1.33M | Array() {} bssl::Array<unsigned char>::Array() Line | Count | Source | 90 | 1.17M | Array() {} |
bssl::Array<unsigned short>::Array() Line | Count | Source | 90 | 156k | Array() {} |
bssl::Array<ssl_credential_st*>::Array() Line | Count | Source | 90 | 3.80k | Array() {} |
Unexecuted instantiation: bssl::Array<int>::Array() bssl::Array<bool>::Array() Line | Count | Source | 90 | 8 | Array() {} |
|
91 | | Array(const Array &) = delete; |
92 | 16.1k | Array(Array &&other) { *this = std::move(other); } |
93 | | |
94 | 1.35M | ~Array() { Reset(); } bssl::Array<unsigned char>::~Array() Line | Count | Source | 94 | 1.19M | ~Array() { Reset(); } |
bssl::Array<unsigned short>::~Array() Line | Count | Source | 94 | 156k | ~Array() { Reset(); } |
bssl::Array<ssl_credential_st*>::~Array() Line | Count | Source | 94 | 3.80k | ~Array() { Reset(); } |
Unexecuted instantiation: bssl::Array<int>::~Array() bssl::Array<bool>::~Array() Line | Count | Source | 94 | 8 | ~Array() { Reset(); } |
|
95 | | |
96 | | Array &operator=(const Array &) = delete; |
97 | 22.9k | Array &operator=(Array &&other) { |
98 | 22.9k | Reset(); |
99 | 22.9k | other.Release(&data_, &size_); |
100 | 22.9k | return *this; |
101 | 22.9k | } bssl::Array<unsigned char>::operator=(bssl::Array<unsigned char>&&) Line | Count | Source | 97 | 18.1k | Array &operator=(Array &&other) { | 98 | 18.1k | Reset(); | 99 | 18.1k | other.Release(&data_, &size_); | 100 | 18.1k | return *this; | 101 | 18.1k | } |
bssl::Array<unsigned short>::operator=(bssl::Array<unsigned short>&&) Line | Count | Source | 97 | 4.79k | Array &operator=(Array &&other) { | 98 | 4.79k | Reset(); | 99 | 4.79k | other.Release(&data_, &size_); | 100 | 4.79k | return *this; | 101 | 4.79k | } |
|
102 | | |
103 | 147k | const T *data() const { return data_; } bssl::Array<unsigned char>::data() const Line | Count | Source | 103 | 77.4k | const T *data() const { return data_; } |
bssl::Array<unsigned short>::data() const Line | Count | Source | 103 | 70.2k | const T *data() const { return data_; } |
bssl::Array<bool>::data() const Line | Count | Source | 103 | 4 | const T *data() const { return data_; } |
|
104 | 6.91k | T *data() { return data_; } bssl::Array<unsigned char>::data() Line | Count | Source | 104 | 6.91k | T *data() { return data_; } |
Unexecuted instantiation: bssl::Array<unsigned short>::data() |
105 | 345k | size_t size() const { return size_; } bssl::Array<unsigned char>::size() const Line | Count | Source | 105 | 88.8k | size_t size() const { return size_; } |
bssl::Array<unsigned short>::size() const Line | Count | Source | 105 | 257k | size_t size() const { return size_; } |
bssl::Array<bool>::size() const Line | Count | Source | 105 | 4 | size_t size() const { return size_; } |
|
106 | 39.5k | bool empty() const { return size_ == 0; } bssl::Array<unsigned char>::empty() const Line | Count | Source | 106 | 25.7k | bool empty() const { return size_ == 0; } |
bssl::Array<unsigned short>::empty() const Line | Count | Source | 106 | 10.0k | bool empty() const { return size_ == 0; } |
bssl::Array<ssl_credential_st*>::empty() const Line | Count | Source | 106 | 3.80k | bool empty() const { return size_ == 0; } |
|
107 | | |
108 | 0 | const T &operator[](size_t i) const { |
109 | 0 | BSSL_CHECK(i < size_); |
110 | 0 | return data_[i]; |
111 | 0 | } |
112 | 404k | T &operator[](size_t i) { |
113 | 404k | BSSL_CHECK(i < size_); |
114 | 404k | return data_[i]; |
115 | 404k | } bssl::Array<unsigned short>::operator[](unsigned long) Line | Count | Source | 112 | 399k | T &operator[](size_t i) { | 113 | 399k | BSSL_CHECK(i < size_); | 114 | 399k | return data_[i]; | 115 | 399k | } |
bssl::Array<unsigned char>::operator[](unsigned long) Line | Count | Source | 112 | 1.06k | T &operator[](size_t i) { | 113 | 1.06k | BSSL_CHECK(i < size_); | 114 | 1.06k | return data_[i]; | 115 | 1.06k | } |
Unexecuted instantiation: bssl::Array<int>::operator[](unsigned long) bssl::Array<bool>::operator[](unsigned long) Line | Count | Source | 112 | 78 | T &operator[](size_t i) { | 113 | 78 | BSSL_CHECK(i < size_); | 114 | 78 | return data_[i]; | 115 | 78 | } |
bssl::Array<ssl_credential_st*>::operator[](unsigned long) Line | Count | Source | 112 | 3.80k | T &operator[](size_t i) { | 113 | 3.80k | BSSL_CHECK(i < size_); | 114 | 3.80k | return data_[i]; | 115 | 3.80k | } |
|
116 | | |
117 | | T &front() { |
118 | | BSSL_CHECK(size_ != 0); |
119 | | return data_[0]; |
120 | | } |
121 | | const T &front() const { |
122 | | BSSL_CHECK(size_ != 0); |
123 | | return data_[0]; |
124 | | } |
125 | | T &back() { |
126 | | BSSL_CHECK(size_ != 0); |
127 | | return data_[size_ - 1]; |
128 | | } |
129 | | const T &back() const { |
130 | | BSSL_CHECK(size_ != 0); |
131 | | return data_[size_ - 1]; |
132 | | } |
133 | | |
134 | 20.2k | T *begin() { return data_; } bssl::Array<unsigned short>::begin() Line | Count | Source | 134 | 16.4k | T *begin() { return data_; } |
bssl::Array<ssl_credential_st*>::begin() Line | Count | Source | 134 | 3.80k | T *begin() { return data_; } |
Unexecuted instantiation: bssl::Array<unsigned char>::begin() |
135 | | const T *begin() const { return data_; } |
136 | 20.2k | T *end() { return data_ + size_; } bssl::Array<unsigned short>::end() Line | Count | Source | 136 | 16.4k | T *end() { return data_ + size_; } |
bssl::Array<ssl_credential_st*>::end() Line | Count | Source | 136 | 3.80k | T *end() { return data_ + size_; } |
Unexecuted instantiation: bssl::Array<unsigned char>::end() |
137 | | const T *end() const { return data_ + size_; } |
138 | | |
139 | 1.65M | void Reset() { Reset(nullptr, 0); } bssl::Array<unsigned char>::Reset() Line | Count | Source | 139 | 1.39M | void Reset() { Reset(nullptr, 0); } |
bssl::Array<unsigned short>::Reset() Line | Count | Source | 139 | 244k | void Reset() { Reset(nullptr, 0); } |
bssl::Array<ssl_credential_st*>::Reset() Line | Count | Source | 139 | 7.60k | void Reset() { Reset(nullptr, 0); } |
Unexecuted instantiation: bssl::Array<int>::Reset() bssl::Array<bool>::Reset() Line | Count | Source | 139 | 16 | void Reset() { Reset(nullptr, 0); } |
|
140 | | |
141 | | // Reset releases the current contents of the array and takes ownership of the |
142 | | // raw pointer supplied by the caller. |
143 | 1.67M | void Reset(T *new_data, size_t new_size) { |
144 | 1.67M | std::destroy_n(data_, size_); |
145 | 1.67M | OPENSSL_free(data_); |
146 | 1.67M | data_ = new_data; |
147 | 1.67M | size_ = new_size; |
148 | 1.67M | } bssl::Array<unsigned char>::Reset(unsigned char*, unsigned long) Line | Count | Source | 143 | 1.41M | void Reset(T *new_data, size_t new_size) { | 144 | 1.41M | std::destroy_n(data_, size_); | 145 | 1.41M | OPENSSL_free(data_); | 146 | 1.41M | data_ = new_data; | 147 | 1.41M | size_ = new_size; | 148 | 1.41M | } |
bssl::Array<unsigned short>::Reset(unsigned short*, unsigned long) Line | Count | Source | 143 | 244k | void Reset(T *new_data, size_t new_size) { | 144 | 244k | std::destroy_n(data_, size_); | 145 | 244k | OPENSSL_free(data_); | 146 | 244k | data_ = new_data; | 147 | 244k | size_ = new_size; | 148 | 244k | } |
bssl::Array<ssl_credential_st*>::Reset(ssl_credential_st**, unsigned long) Line | Count | Source | 143 | 7.60k | void Reset(T *new_data, size_t new_size) { | 144 | 7.60k | std::destroy_n(data_, size_); | 145 | 7.60k | OPENSSL_free(data_); | 146 | 7.60k | data_ = new_data; | 147 | 7.60k | size_ = new_size; | 148 | 7.60k | } |
Unexecuted instantiation: bssl::Array<int>::Reset(int*, unsigned long) bssl::Array<bool>::Reset(bool*, unsigned long) Line | Count | Source | 143 | 16 | void Reset(T *new_data, size_t new_size) { | 144 | 16 | std::destroy_n(data_, size_); | 145 | 16 | OPENSSL_free(data_); | 146 | 16 | data_ = new_data; | 147 | 16 | size_ = new_size; | 148 | 16 | } |
|
149 | | |
150 | | // Release releases ownership of the array to a raw pointer supplied by the |
151 | | // caller. |
152 | 22.9k | void Release(T **out, size_t *out_size) { |
153 | 22.9k | *out = data_; |
154 | 22.9k | *out_size = size_; |
155 | 22.9k | data_ = nullptr; |
156 | 22.9k | size_ = 0; |
157 | 22.9k | } bssl::Array<unsigned char>::Release(unsigned char**, unsigned long*) Line | Count | Source | 152 | 18.1k | void Release(T **out, size_t *out_size) { | 153 | 18.1k | *out = data_; | 154 | 18.1k | *out_size = size_; | 155 | 18.1k | data_ = nullptr; | 156 | 18.1k | size_ = 0; | 157 | 18.1k | } |
bssl::Array<unsigned short>::Release(unsigned short**, unsigned long*) Line | Count | Source | 152 | 4.79k | void Release(T **out, size_t *out_size) { | 153 | 4.79k | *out = data_; | 154 | 4.79k | *out_size = size_; | 155 | 4.79k | data_ = nullptr; | 156 | 4.79k | size_ = 0; | 157 | 4.79k | } |
bssl::Array<bool>::Release(bool**, unsigned long*) Line | Count | Source | 152 | 4 | void Release(T **out, size_t *out_size) { | 153 | 4 | *out = data_; | 154 | 4 | *out_size = size_; | 155 | 4 | data_ = nullptr; | 156 | 4 | size_ = 0; | 157 | 4 | } |
|
158 | | |
159 | | // Init replaces the array with a newly-allocated array of |new_size| |
160 | | // value-constructed copies of |T|. It returns true on success and false on |
161 | | // error. If |T| is a primitive type like |uint8_t|, value-construction means |
162 | | // it will be zero-initialized. |
163 | 0 | [[nodiscard]] bool Init(size_t new_size) { |
164 | 0 | if (!InitUninitialized(new_size)) { |
165 | 0 | return false; |
166 | 0 | } |
167 | 0 | std::uninitialized_value_construct_n(data_, size_); |
168 | 0 | return true; |
169 | 0 | } Unexecuted instantiation: bssl::Array<unsigned char>::Init(unsigned long) Unexecuted instantiation: bssl::Array<int>::Init(unsigned long) |
170 | | |
171 | | // InitForOverwrite behaves like |Init| but it default-constructs each element |
172 | | // instead. This means that, if |T| is a primitive type, the array will be |
173 | | // uninitialized and thus must be filled in by the caller. |
174 | 27.5k | [[nodiscard]] bool InitForOverwrite(size_t new_size) { |
175 | 27.5k | if (!InitUninitialized(new_size)) { |
176 | 0 | return false; |
177 | 0 | } |
178 | 27.5k | std::uninitialized_default_construct_n(data_, size_); |
179 | 27.5k | return true; |
180 | 27.5k | } bssl::Array<unsigned char>::InitForOverwrite(unsigned long) Line | Count | Source | 174 | 2.51k | [[nodiscard]] bool InitForOverwrite(size_t new_size) { | 175 | 2.51k | if (!InitUninitialized(new_size)) { | 176 | 0 | return false; | 177 | 0 | } | 178 | 2.51k | std::uninitialized_default_construct_n(data_, size_); | 179 | 2.51k | return true; | 180 | 2.51k | } |
bssl::Array<unsigned short>::InitForOverwrite(unsigned long) Line | Count | Source | 174 | 21.2k | [[nodiscard]] bool InitForOverwrite(size_t new_size) { | 175 | 21.2k | if (!InitUninitialized(new_size)) { | 176 | 0 | return false; | 177 | 0 | } | 178 | 21.2k | std::uninitialized_default_construct_n(data_, size_); | 179 | 21.2k | return true; | 180 | 21.2k | } |
bssl::Array<bool>::InitForOverwrite(unsigned long) Line | Count | Source | 174 | 4 | [[nodiscard]] bool InitForOverwrite(size_t new_size) { | 175 | 4 | if (!InitUninitialized(new_size)) { | 176 | 0 | return false; | 177 | 0 | } | 178 | 4 | std::uninitialized_default_construct_n(data_, size_); | 179 | 4 | return true; | 180 | 4 | } |
bssl::Array<ssl_credential_st*>::InitForOverwrite(unsigned long) Line | Count | Source | 174 | 3.80k | [[nodiscard]] bool InitForOverwrite(size_t new_size) { | 175 | 3.80k | if (!InitUninitialized(new_size)) { | 176 | 0 | return false; | 177 | 0 | } | 178 | 3.80k | std::uninitialized_default_construct_n(data_, size_); | 179 | 3.80k | return true; | 180 | 3.80k | } |
|
181 | | |
182 | | // CopyFrom replaces the array with a newly-allocated copy of |in|. It returns |
183 | | // true on success and false on error. |
184 | 240k | [[nodiscard]] bool CopyFrom(Span<const T> in) { |
185 | 240k | if (!InitUninitialized(in.size())) { |
186 | 0 | return false; |
187 | 0 | } |
188 | 240k | std::uninitialized_copy(in.begin(), in.end(), data_); |
189 | 240k | return true; |
190 | 240k | } bssl::Array<unsigned char>::CopyFrom(bssl::Span<unsigned char const>) Line | Count | Source | 184 | 182k | [[nodiscard]] bool CopyFrom(Span<const T> in) { | 185 | 182k | if (!InitUninitialized(in.size())) { | 186 | 0 | return false; | 187 | 0 | } | 188 | 182k | std::uninitialized_copy(in.begin(), in.end(), data_); | 189 | 182k | return true; | 190 | 182k | } |
bssl::Array<bool>::CopyFrom(bssl::Span<bool const>) Line | Count | Source | 184 | 4 | [[nodiscard]] bool CopyFrom(Span<const T> in) { | 185 | 4 | if (!InitUninitialized(in.size())) { | 186 | 0 | return false; | 187 | 0 | } | 188 | 4 | std::uninitialized_copy(in.begin(), in.end(), data_); | 189 | 4 | return true; | 190 | 4 | } |
bssl::Array<unsigned short>::CopyFrom(bssl::Span<unsigned short const>) Line | Count | Source | 184 | 58.1k | [[nodiscard]] bool CopyFrom(Span<const T> in) { | 185 | 58.1k | if (!InitUninitialized(in.size())) { | 186 | 0 | return false; | 187 | 0 | } | 188 | 58.1k | std::uninitialized_copy(in.begin(), in.end(), data_); | 189 | 58.1k | return true; | 190 | 58.1k | } |
|
191 | | |
192 | | // Shrink shrinks the stored size of the array to |new_size|. It crashes if |
193 | | // the new size is larger. Note this does not shrink the allocation itself. |
194 | 4 | void Shrink(size_t new_size) { |
195 | 4 | if (new_size > size_) { |
196 | 0 | abort(); |
197 | 0 | } |
198 | 4 | std::destroy_n(data_ + new_size, size_ - new_size); |
199 | 4 | size_ = new_size; |
200 | 4 | } Unexecuted instantiation: bssl::Array<unsigned char>::Shrink(unsigned long) Unexecuted instantiation: bssl::Array<unsigned short>::Shrink(unsigned long) bssl::Array<bool>::Shrink(unsigned long) Line | Count | Source | 194 | 4 | void Shrink(size_t new_size) { | 195 | 4 | if (new_size > size_) { | 196 | 0 | abort(); | 197 | 0 | } | 198 | 4 | std::destroy_n(data_ + new_size, size_ - new_size); | 199 | 4 | size_ = new_size; | 200 | 4 | } |
|
201 | | |
202 | | private: |
203 | | // InitUninitialized replaces the array with a newly-allocated array of |
204 | | // |new_size| elements, but whose constructor has not yet run. On success, the |
205 | | // elements must be constructed before returning control to the caller. |
206 | 267k | bool InitUninitialized(size_t new_size) { |
207 | 267k | Reset(); |
208 | 267k | if (new_size == 0) { |
209 | 178k | return true; |
210 | 178k | } |
211 | | |
212 | 89.7k | if (new_size > SIZE_MAX / sizeof(T)) { |
213 | 0 | OPENSSL_PUT_ERROR(CRYPTO, ERR_R_OVERFLOW); |
214 | 0 | return false; |
215 | 0 | } |
216 | 89.7k | data_ = reinterpret_cast<T *>(OPENSSL_malloc(new_size * sizeof(T))); |
217 | 89.7k | if (data_ == nullptr) { |
218 | 0 | return false; |
219 | 0 | } |
220 | 89.7k | size_ = new_size; |
221 | 89.7k | return true; |
222 | 89.7k | } bssl::Array<unsigned char>::InitUninitialized(unsigned long) Line | Count | Source | 206 | 184k | bool InitUninitialized(size_t new_size) { | 207 | 184k | Reset(); | 208 | 184k | if (new_size == 0) { | 209 | 139k | return true; | 210 | 139k | } | 211 | | | 212 | 45.3k | if (new_size > SIZE_MAX / sizeof(T)) { | 213 | 0 | OPENSSL_PUT_ERROR(CRYPTO, ERR_R_OVERFLOW); | 214 | 0 | return false; | 215 | 0 | } | 216 | 45.3k | data_ = reinterpret_cast<T *>(OPENSSL_malloc(new_size * sizeof(T))); | 217 | 45.3k | if (data_ == nullptr) { | 218 | 0 | return false; | 219 | 0 | } | 220 | 45.3k | size_ = new_size; | 221 | 45.3k | return true; | 222 | 45.3k | } |
bssl::Array<unsigned short>::InitUninitialized(unsigned long) Line | Count | Source | 206 | 79.3k | bool InitUninitialized(size_t new_size) { | 207 | 79.3k | Reset(); | 208 | 79.3k | if (new_size == 0) { | 209 | 38.7k | return true; | 210 | 38.7k | } | 211 | | | 212 | 40.6k | if (new_size > SIZE_MAX / sizeof(T)) { | 213 | 0 | OPENSSL_PUT_ERROR(CRYPTO, ERR_R_OVERFLOW); | 214 | 0 | return false; | 215 | 0 | } | 216 | 40.6k | data_ = reinterpret_cast<T *>(OPENSSL_malloc(new_size * sizeof(T))); | 217 | 40.6k | if (data_ == nullptr) { | 218 | 0 | return false; | 219 | 0 | } | 220 | 40.6k | size_ = new_size; | 221 | 40.6k | return true; | 222 | 40.6k | } |
Unexecuted instantiation: bssl::Array<int>::InitUninitialized(unsigned long) bssl::Array<bool>::InitUninitialized(unsigned long) Line | Count | Source | 206 | 8 | bool InitUninitialized(size_t new_size) { | 207 | 8 | Reset(); | 208 | 8 | if (new_size == 0) { | 209 | 0 | return true; | 210 | 0 | } | 211 | | | 212 | 8 | if (new_size > SIZE_MAX / sizeof(T)) { | 213 | 0 | OPENSSL_PUT_ERROR(CRYPTO, ERR_R_OVERFLOW); | 214 | 0 | return false; | 215 | 0 | } | 216 | 8 | data_ = reinterpret_cast<T *>(OPENSSL_malloc(new_size * sizeof(T))); | 217 | 8 | if (data_ == nullptr) { | 218 | 0 | return false; | 219 | 0 | } | 220 | 8 | size_ = new_size; | 221 | 8 | return true; | 222 | 8 | } |
bssl::Array<ssl_credential_st*>::InitUninitialized(unsigned long) Line | Count | Source | 206 | 3.80k | bool InitUninitialized(size_t new_size) { | 207 | 3.80k | Reset(); | 208 | 3.80k | if (new_size == 0) { | 209 | 0 | return true; | 210 | 0 | } | 211 | | | 212 | 3.80k | if (new_size > SIZE_MAX / sizeof(T)) { | 213 | 0 | OPENSSL_PUT_ERROR(CRYPTO, ERR_R_OVERFLOW); | 214 | 0 | return false; | 215 | 0 | } | 216 | 3.80k | data_ = reinterpret_cast<T *>(OPENSSL_malloc(new_size * sizeof(T))); | 217 | 3.80k | if (data_ == nullptr) { | 218 | 0 | return false; | 219 | 0 | } | 220 | 3.80k | size_ = new_size; | 221 | 3.80k | return true; | 222 | 3.80k | } |
|
223 | | |
224 | | T *data_ = nullptr; |
225 | | size_t size_ = 0; |
226 | | }; |
227 | | |
228 | | // Vector<T> is a resizable array of elements of |T|. |
229 | | template <typename T> |
230 | | class Vector { |
231 | | public: |
232 | 46.5k | Vector() = default; bssl::Vector<std::__1::unique_ptr<bssl::ECHServerConfig, bssl::internal::Deleter> >::Vector() Line | Count | Source | 232 | 2 | Vector() = default; |
bssl::Vector<std::__1::unique_ptr<ssl_credential_st, bssl::internal::Deleter> >::Vector() Line | Count | Source | 232 | 19.3k | Vector() = default; |
bssl::Vector<bssl::CertCompressionAlg>::Vector() Line | Count | Source | 232 | 2 | Vector() = default; |
bssl::Vector<bssl::ALPSConfig>::Vector() Line | Count | Source | 232 | 19.3k | Vector() = default; |
bssl::Vector<std::__1::unique_ptr<bignum_st, bssl::internal::Deleter> >::Vector() Line | Count | Source | 232 | 3.88k | Vector() = default; |
bssl::Vector<unsigned long>::Vector() Line | Count | Source | 232 | 3.88k | Vector() = default; |
|
233 | | Vector(const Vector &) = delete; |
234 | | Vector(Vector &&other) { *this = std::move(other); } |
235 | 46.5k | ~Vector() { clear(); } Unexecuted instantiation: bssl::Vector<std::__1::unique_ptr<bssl::ECHServerConfig, bssl::internal::Deleter> >::~Vector() bssl::Vector<std::__1::unique_ptr<ssl_credential_st, bssl::internal::Deleter> >::~Vector() Line | Count | Source | 235 | 19.3k | ~Vector() { clear(); } |
Unexecuted instantiation: bssl::Vector<bssl::CertCompressionAlg>::~Vector() bssl::Vector<bssl::ALPSConfig>::~Vector() Line | Count | Source | 235 | 19.3k | ~Vector() { clear(); } |
bssl::Vector<unsigned long>::~Vector() Line | Count | Source | 235 | 3.88k | ~Vector() { clear(); } |
bssl::Vector<std::__1::unique_ptr<bignum_st, bssl::internal::Deleter> >::~Vector() Line | Count | Source | 235 | 3.88k | ~Vector() { clear(); } |
|
236 | | |
237 | | Vector &operator=(const Vector &) = delete; |
238 | | Vector &operator=(Vector &&other) { |
239 | | clear(); |
240 | | std::swap(data_, other.data_); |
241 | | std::swap(size_, other.size_); |
242 | | std::swap(capacity_, other.capacity_); |
243 | | return *this; |
244 | | } |
245 | | |
246 | | const T *data() const { return data_; } |
247 | | T *data() { return data_; } |
248 | 52.7k | size_t size() const { return size_; } bssl::Vector<bssl::CertCompressionAlg>::size() const Line | Count | Source | 248 | 23 | size_t size() const { return size_; } |
bssl::Vector<std::__1::unique_ptr<ssl_credential_st, bssl::internal::Deleter> >::size() const Line | Count | Source | 248 | 7.60k | size_t size() const { return size_; } |
bssl::Vector<std::__1::unique_ptr<bignum_st, bssl::internal::Deleter> >::size() const Line | Count | Source | 248 | 45.1k | size_t size() const { return size_; } |
|
249 | 31.4k | bool empty() const { return size_ == 0; } Unexecuted instantiation: bssl::Vector<bssl::ALPSConfig>::empty() const bssl::Vector<std::__1::unique_ptr<ssl_credential_st, bssl::internal::Deleter> >::empty() const Line | Count | Source | 249 | 2 | bool empty() const { return size_ == 0; } |
bssl::Vector<unsigned long>::empty() const Line | Count | Source | 249 | 31.4k | bool empty() const { return size_ == 0; } |
|
250 | | |
251 | 0 | const T &operator[](size_t i) const { |
252 | 0 | BSSL_CHECK(i < size_); |
253 | 0 | return data_[i]; |
254 | 0 | } Unexecuted instantiation: bssl::Vector<bssl::CertCompressionAlg>::operator[](unsigned long) const Unexecuted instantiation: bssl::Vector<std::__1::unique_ptr<ssl_credential_st, bssl::internal::Deleter> >::operator[](unsigned long) const |
255 | 45.1k | T &operator[](size_t i) { |
256 | 45.1k | BSSL_CHECK(i < size_); |
257 | 45.1k | return data_[i]; |
258 | 45.1k | } Unexecuted instantiation: bssl::Vector<std::__1::unique_ptr<ssl_credential_st, bssl::internal::Deleter> >::operator[](unsigned long) bssl::Vector<std::__1::unique_ptr<bignum_st, bssl::internal::Deleter> >::operator[](unsigned long) Line | Count | Source | 255 | 45.1k | T &operator[](size_t i) { | 256 | 45.1k | BSSL_CHECK(i < size_); | 257 | 45.1k | return data_[i]; | 258 | 45.1k | } |
|
259 | | |
260 | | T &front() { |
261 | | BSSL_CHECK(size_ != 0); |
262 | | return data_[0]; |
263 | | } |
264 | | const T &front() const { |
265 | | BSSL_CHECK(size_ != 0); |
266 | | return data_[0]; |
267 | | } |
268 | 31.4k | T &back() { |
269 | 31.4k | BSSL_CHECK(size_ != 0); |
270 | 31.4k | return data_[size_ - 1]; |
271 | 31.4k | } |
272 | | const T &back() const { |
273 | | BSSL_CHECK(size_ != 0); |
274 | | return data_[size_ - 1]; |
275 | | } |
276 | | |
277 | 26.1k | T *begin() { return data_; } bssl::Vector<std::__1::unique_ptr<bssl::ECHServerConfig, bssl::internal::Deleter> >::begin() Line | Count | Source | 277 | 206 | T *begin() { return data_; } |
Unexecuted instantiation: bssl::Vector<bssl::CertCompressionAlg>::begin() bssl::Vector<std::__1::unique_ptr<ssl_credential_st, bssl::internal::Deleter> >::begin() Line | Count | Source | 277 | 19.3k | T *begin() { return data_; } |
bssl::Vector<bssl::ALPSConfig>::begin() Line | Count | Source | 277 | 10 | T *begin() { return data_; } |
bssl::Vector<unsigned long>::begin() Line | Count | Source | 277 | 3.28k | T *begin() { return data_; } |
bssl::Vector<std::__1::unique_ptr<bignum_st, bssl::internal::Deleter> >::begin() Line | Count | Source | 277 | 3.28k | T *begin() { return data_; } |
|
278 | 0 | const T *begin() const { return data_; } Unexecuted instantiation: bssl::Vector<std::__1::unique_ptr<bssl::ECHServerConfig, bssl::internal::Deleter> >::begin() const Unexecuted instantiation: bssl::Vector<std::__1::unique_ptr<ssl_credential_st, bssl::internal::Deleter> >::begin() const |
279 | 26.1k | T *end() { return data_ + size_; } bssl::Vector<std::__1::unique_ptr<bssl::ECHServerConfig, bssl::internal::Deleter> >::end() Line | Count | Source | 279 | 206 | T *end() { return data_ + size_; } |
Unexecuted instantiation: bssl::Vector<bssl::CertCompressionAlg>::end() bssl::Vector<std::__1::unique_ptr<ssl_credential_st, bssl::internal::Deleter> >::end() Line | Count | Source | 279 | 19.3k | T *end() { return data_ + size_; } |
bssl::Vector<bssl::ALPSConfig>::end() Line | Count | Source | 279 | 10 | T *end() { return data_ + size_; } |
bssl::Vector<unsigned long>::end() Line | Count | Source | 279 | 3.28k | T *end() { return data_ + size_; } |
bssl::Vector<std::__1::unique_ptr<bignum_st, bssl::internal::Deleter> >::end() Line | Count | Source | 279 | 3.28k | T *end() { return data_ + size_; } |
|
280 | 0 | const T *end() const { return data_ + size_; } Unexecuted instantiation: bssl::Vector<std::__1::unique_ptr<bssl::ECHServerConfig, bssl::internal::Deleter> >::end() const Unexecuted instantiation: bssl::Vector<std::__1::unique_ptr<ssl_credential_st, bssl::internal::Deleter> >::end() const |
281 | | |
282 | 53.1k | void clear() { |
283 | 53.1k | std::destroy_n(data_, size_); |
284 | 53.1k | OPENSSL_free(data_); |
285 | 53.1k | data_ = nullptr; |
286 | 53.1k | size_ = 0; |
287 | 53.1k | capacity_ = 0; |
288 | 53.1k | } bssl::Vector<std::__1::unique_ptr<bssl::ECHServerConfig, bssl::internal::Deleter> >::clear() Line | Count | Source | 282 | 2 | void clear() { | 283 | 2 | std::destroy_n(data_, size_); | 284 | 2 | OPENSSL_free(data_); | 285 | 2 | data_ = nullptr; | 286 | 2 | size_ = 0; | 287 | 2 | capacity_ = 0; | 288 | 2 | } |
bssl::Vector<bssl::ALPSConfig>::clear() Line | Count | Source | 282 | 19.3k | void clear() { | 283 | 19.3k | std::destroy_n(data_, size_); | 284 | 19.3k | OPENSSL_free(data_); | 285 | 19.3k | data_ = nullptr; | 286 | 19.3k | size_ = 0; | 287 | 19.3k | capacity_ = 0; | 288 | 19.3k | } |
bssl::Vector<std::__1::unique_ptr<ssl_credential_st, bssl::internal::Deleter> >::clear() Line | Count | Source | 282 | 19.3k | void clear() { | 283 | 19.3k | std::destroy_n(data_, size_); | 284 | 19.3k | OPENSSL_free(data_); | 285 | 19.3k | data_ = nullptr; | 286 | 19.3k | size_ = 0; | 287 | 19.3k | capacity_ = 0; | 288 | 19.3k | } |
Unexecuted instantiation: bssl::Vector<bssl::CertCompressionAlg>::clear() bssl::Vector<unsigned long>::clear() Line | Count | Source | 282 | 7.17k | void clear() { | 283 | 7.17k | std::destroy_n(data_, size_); | 284 | 7.17k | OPENSSL_free(data_); | 285 | 7.17k | data_ = nullptr; | 286 | 7.17k | size_ = 0; | 287 | 7.17k | capacity_ = 0; | 288 | 7.17k | } |
bssl::Vector<std::__1::unique_ptr<bignum_st, bssl::internal::Deleter> >::clear() Line | Count | Source | 282 | 7.17k | void clear() { | 283 | 7.17k | std::destroy_n(data_, size_); | 284 | 7.17k | OPENSSL_free(data_); | 285 | 7.17k | data_ = nullptr; | 286 | 7.17k | size_ = 0; | 287 | 7.17k | capacity_ = 0; | 288 | 7.17k | } |
|
289 | | |
290 | 31.4k | void pop_back() { |
291 | 31.4k | BSSL_CHECK(size_ != 0); |
292 | 31.4k | std::destroy_at(&data_[size_ - 1]); |
293 | 31.4k | size_--; |
294 | 31.4k | } |
295 | | |
296 | | // Push adds |elem| at the end of the internal array, growing if necessary. It |
297 | | // returns false when allocation fails. |
298 | 51.0k | [[nodiscard]] bool Push(T elem) { |
299 | 51.0k | if (!MaybeGrow()) { |
300 | 0 | return false; |
301 | 0 | } |
302 | 51.0k | new (&data_[size_]) T(std::move(elem)); |
303 | 51.0k | size_++; |
304 | 51.0k | return true; |
305 | 51.0k | } bssl::Vector<std::__1::unique_ptr<bssl::ECHServerConfig, bssl::internal::Deleter> >::Push(std::__1::unique_ptr<bssl::ECHServerConfig, bssl::internal::Deleter>) Line | Count | Source | 298 | 2 | [[nodiscard]] bool Push(T elem) { | 299 | 2 | if (!MaybeGrow()) { | 300 | 0 | return false; | 301 | 0 | } | 302 | 2 | new (&data_[size_]) T(std::move(elem)); | 303 | 2 | size_++; | 304 | 2 | return true; | 305 | 2 | } |
Unexecuted instantiation: bssl::Vector<std::__1::unique_ptr<ssl_credential_st, bssl::internal::Deleter> >::Push(std::__1::unique_ptr<ssl_credential_st, bssl::internal::Deleter>) Unexecuted instantiation: bssl::Vector<bssl::ALPSConfig>::Push(bssl::ALPSConfig) Unexecuted instantiation: bssl::Vector<bssl::CertCompressionAlg>::Push(bssl::CertCompressionAlg) bssl::Vector<unsigned long>::Push(unsigned long) Line | Count | Source | 298 | 31.4k | [[nodiscard]] bool Push(T elem) { | 299 | 31.4k | if (!MaybeGrow()) { | 300 | 0 | return false; | 301 | 0 | } | 302 | 31.4k | new (&data_[size_]) T(std::move(elem)); | 303 | 31.4k | size_++; | 304 | 31.4k | return true; | 305 | 31.4k | } |
bssl::Vector<std::__1::unique_ptr<bignum_st, bssl::internal::Deleter> >::Push(std::__1::unique_ptr<bignum_st, bssl::internal::Deleter>) Line | Count | Source | 298 | 19.5k | [[nodiscard]] bool Push(T elem) { | 299 | 19.5k | if (!MaybeGrow()) { | 300 | 0 | return false; | 301 | 0 | } | 302 | 19.5k | new (&data_[size_]) T(std::move(elem)); | 303 | 19.5k | size_++; | 304 | 19.5k | return true; | 305 | 19.5k | } |
|
306 | | |
307 | | // CopyFrom replaces the contents of the array with a copy of |in|. It returns |
308 | | // true on success and false on allocation error. |
309 | | [[nodiscard]] bool CopyFrom(Span<const T> in) { |
310 | | Array<T> copy; |
311 | | if (!copy.CopyFrom(in)) { |
312 | | return false; |
313 | | } |
314 | | |
315 | | clear(); |
316 | | copy.Release(&data_, &size_); |
317 | | capacity_ = size_; |
318 | | return true; |
319 | | } |
320 | | |
321 | | private: |
322 | | // If there is no room for one more element, creates a new backing array with |
323 | | // double the size of the old one and copies elements over. |
324 | 51.0k | bool MaybeGrow() { |
325 | | // No need to grow if we have room for one more T. |
326 | 51.0k | if (size_ < capacity_) { |
327 | 44.4k | return true; |
328 | 44.4k | } |
329 | 6.58k | size_t new_capacity = kDefaultSize; |
330 | 6.58k | if (capacity_ > 0) { |
331 | | // Double the array's size if it's safe to do so. |
332 | 0 | if (capacity_ > SIZE_MAX / 2) { |
333 | 0 | OPENSSL_PUT_ERROR(CRYPTO, ERR_R_OVERFLOW); |
334 | 0 | return false; |
335 | 0 | } |
336 | 0 | new_capacity = capacity_ * 2; |
337 | 0 | } |
338 | 6.58k | if (new_capacity > SIZE_MAX / sizeof(T)) { |
339 | 0 | OPENSSL_PUT_ERROR(CRYPTO, ERR_R_OVERFLOW); |
340 | 0 | return false; |
341 | 0 | } |
342 | 6.58k | T *new_data = |
343 | 6.58k | reinterpret_cast<T *>(OPENSSL_malloc(new_capacity * sizeof(T))); |
344 | 6.58k | if (new_data == nullptr) { |
345 | 0 | return false; |
346 | 0 | } |
347 | 6.58k | size_t new_size = size_; |
348 | 6.58k | std::uninitialized_move(begin(), end(), new_data); |
349 | 6.58k | clear(); |
350 | 6.58k | data_ = new_data; |
351 | 6.58k | size_ = new_size; |
352 | 6.58k | capacity_ = new_capacity; |
353 | 6.58k | return true; |
354 | 6.58k | } bssl::Vector<std::__1::unique_ptr<bssl::ECHServerConfig, bssl::internal::Deleter> >::MaybeGrow() Line | Count | Source | 324 | 2 | bool MaybeGrow() { | 325 | | // No need to grow if we have room for one more T. | 326 | 2 | if (size_ < capacity_) { | 327 | 0 | return true; | 328 | 0 | } | 329 | 2 | size_t new_capacity = kDefaultSize; | 330 | 2 | if (capacity_ > 0) { | 331 | | // Double the array's size if it's safe to do so. | 332 | 0 | if (capacity_ > SIZE_MAX / 2) { | 333 | 0 | OPENSSL_PUT_ERROR(CRYPTO, ERR_R_OVERFLOW); | 334 | 0 | return false; | 335 | 0 | } | 336 | 0 | new_capacity = capacity_ * 2; | 337 | 0 | } | 338 | 2 | if (new_capacity > SIZE_MAX / sizeof(T)) { | 339 | 0 | OPENSSL_PUT_ERROR(CRYPTO, ERR_R_OVERFLOW); | 340 | 0 | return false; | 341 | 0 | } | 342 | 2 | T *new_data = | 343 | 2 | reinterpret_cast<T *>(OPENSSL_malloc(new_capacity * sizeof(T))); | 344 | 2 | if (new_data == nullptr) { | 345 | 0 | return false; | 346 | 0 | } | 347 | 2 | size_t new_size = size_; | 348 | 2 | std::uninitialized_move(begin(), end(), new_data); | 349 | 2 | clear(); | 350 | 2 | data_ = new_data; | 351 | 2 | size_ = new_size; | 352 | 2 | capacity_ = new_capacity; | 353 | 2 | return true; | 354 | 2 | } |
Unexecuted instantiation: bssl::Vector<std::__1::unique_ptr<ssl_credential_st, bssl::internal::Deleter> >::MaybeGrow() Unexecuted instantiation: bssl::Vector<bssl::ALPSConfig>::MaybeGrow() Unexecuted instantiation: bssl::Vector<bssl::CertCompressionAlg>::MaybeGrow() bssl::Vector<unsigned long>::MaybeGrow() Line | Count | Source | 324 | 31.4k | bool MaybeGrow() { | 325 | | // No need to grow if we have room for one more T. | 326 | 31.4k | if (size_ < capacity_) { | 327 | 28.1k | return true; | 328 | 28.1k | } | 329 | 3.28k | size_t new_capacity = kDefaultSize; | 330 | 3.28k | if (capacity_ > 0) { | 331 | | // Double the array's size if it's safe to do so. | 332 | 0 | if (capacity_ > SIZE_MAX / 2) { | 333 | 0 | OPENSSL_PUT_ERROR(CRYPTO, ERR_R_OVERFLOW); | 334 | 0 | return false; | 335 | 0 | } | 336 | 0 | new_capacity = capacity_ * 2; | 337 | 0 | } | 338 | 3.28k | if (new_capacity > SIZE_MAX / sizeof(T)) { | 339 | 0 | OPENSSL_PUT_ERROR(CRYPTO, ERR_R_OVERFLOW); | 340 | 0 | return false; | 341 | 0 | } | 342 | 3.28k | T *new_data = | 343 | 3.28k | reinterpret_cast<T *>(OPENSSL_malloc(new_capacity * sizeof(T))); | 344 | 3.28k | if (new_data == nullptr) { | 345 | 0 | return false; | 346 | 0 | } | 347 | 3.28k | size_t new_size = size_; | 348 | 3.28k | std::uninitialized_move(begin(), end(), new_data); | 349 | 3.28k | clear(); | 350 | 3.28k | data_ = new_data; | 351 | 3.28k | size_ = new_size; | 352 | 3.28k | capacity_ = new_capacity; | 353 | 3.28k | return true; | 354 | 3.28k | } |
bssl::Vector<std::__1::unique_ptr<bignum_st, bssl::internal::Deleter> >::MaybeGrow() Line | Count | Source | 324 | 19.5k | bool MaybeGrow() { | 325 | | // No need to grow if we have room for one more T. | 326 | 19.5k | if (size_ < capacity_) { | 327 | 16.2k | return true; | 328 | 16.2k | } | 329 | 3.28k | size_t new_capacity = kDefaultSize; | 330 | 3.28k | if (capacity_ > 0) { | 331 | | // Double the array's size if it's safe to do so. | 332 | 0 | if (capacity_ > SIZE_MAX / 2) { | 333 | 0 | OPENSSL_PUT_ERROR(CRYPTO, ERR_R_OVERFLOW); | 334 | 0 | return false; | 335 | 0 | } | 336 | 0 | new_capacity = capacity_ * 2; | 337 | 0 | } | 338 | 3.28k | if (new_capacity > SIZE_MAX / sizeof(T)) { | 339 | 0 | OPENSSL_PUT_ERROR(CRYPTO, ERR_R_OVERFLOW); | 340 | 0 | return false; | 341 | 0 | } | 342 | 3.28k | T *new_data = | 343 | 3.28k | reinterpret_cast<T *>(OPENSSL_malloc(new_capacity * sizeof(T))); | 344 | 3.28k | if (new_data == nullptr) { | 345 | 0 | return false; | 346 | 0 | } | 347 | 3.28k | size_t new_size = size_; | 348 | 3.28k | std::uninitialized_move(begin(), end(), new_data); | 349 | 3.28k | clear(); | 350 | 3.28k | data_ = new_data; | 351 | 3.28k | size_ = new_size; | 352 | 3.28k | capacity_ = new_capacity; | 353 | 3.28k | return true; | 354 | 3.28k | } |
|
355 | | |
356 | | // data_ is a pointer to |capacity_| objects of size |T|, the first |size_| of |
357 | | // which are constructed. |
358 | | T *data_ = nullptr; |
359 | | // |size_| is the number of elements stored in this Vector. |
360 | | size_t size_ = 0; |
361 | | // |capacity_| is the number of elements allocated in this Vector. |
362 | | size_t capacity_ = 0; |
363 | | // |kDefaultSize| is the default initial size of the backing array. |
364 | | static constexpr size_t kDefaultSize = 16; |
365 | | }; |
366 | | |
367 | | // A PackedSize is an integer that can store values from 0 to N, represented as |
368 | | // a minimal-width integer. |
369 | | template <size_t N> |
370 | | using PackedSize = std::conditional_t< |
371 | | N <= 0xff, uint8_t, |
372 | | std::conditional_t<N <= 0xffff, uint16_t, |
373 | | std::conditional_t<N <= 0xffffffff, uint32_t, size_t>>>; |
374 | | |
375 | | // An InplaceVector is like a Vector, but stores up to N elements inline in the |
376 | | // object. It is inspired by std::inplace_vector in C++26. |
377 | | template <typename T, size_t N> |
378 | | class InplaceVector { |
379 | | public: |
380 | 453k | InplaceVector() = default; bssl::InplaceVector<unsigned char, 48ul>::InplaceVector() Line | Count | Source | 380 | 260k | InplaceVector() = default; |
bssl::InplaceVector<unsigned char, 32ul>::InplaceVector() Line | Count | Source | 380 | 105k | InplaceVector() = default; |
bssl::InplaceVector<unsigned char, 12ul>::InplaceVector() Line | Count | Source | 380 | 88.0k | InplaceVector() = default; |
Unexecuted instantiation: bssl::InplaceVector<bssl::DTLSRecordNumber, 32ul>::InplaceVector() Unexecuted instantiation: bssl::InplaceVector<bssl::DTLSSentRecord, 32ul>::InplaceVector() Unexecuted instantiation: bssl::InplaceVector<std::__1::unique_ptr<bssl::DTLSWriteEpoch, bssl::internal::Deleter>, 2ul>::InplaceVector() Unexecuted instantiation: bssl::InplaceVector<bssl::DTLSOutgoingMessage, 7ul>::InplaceVector() |
381 | | InplaceVector(const InplaceVector &other) { *this = other; } |
382 | 0 | InplaceVector(InplaceVector &&other) { *this = std::move(other); } |
383 | 453k | ~InplaceVector() { clear(); } bssl::InplaceVector<unsigned char, 48ul>::~InplaceVector() Line | Count | Source | 383 | 260k | ~InplaceVector() { clear(); } |
bssl::InplaceVector<unsigned char, 32ul>::~InplaceVector() Line | Count | Source | 383 | 105k | ~InplaceVector() { clear(); } |
bssl::InplaceVector<unsigned char, 12ul>::~InplaceVector() Line | Count | Source | 383 | 88.0k | ~InplaceVector() { clear(); } |
Unexecuted instantiation: bssl::InplaceVector<bssl::DTLSRecordNumber, 32ul>::~InplaceVector() Unexecuted instantiation: bssl::InplaceVector<bssl::DTLSSentRecord, 32ul>::~InplaceVector() Unexecuted instantiation: bssl::InplaceVector<std::__1::unique_ptr<bssl::DTLSWriteEpoch, bssl::internal::Deleter>, 2ul>::~InplaceVector() Unexecuted instantiation: bssl::InplaceVector<bssl::DTLSOutgoingMessage, 7ul>::~InplaceVector() |
384 | 21.5k | InplaceVector &operator=(const InplaceVector &other) { |
385 | 21.5k | if (this != &other) { |
386 | 21.5k | CopyFrom(other); |
387 | 21.5k | } |
388 | 21.5k | return *this; |
389 | 21.5k | } bssl::InplaceVector<unsigned char, 32ul>::operator=(bssl::InplaceVector<unsigned char, 32ul> const&) Line | Count | Source | 384 | 20.4k | InplaceVector &operator=(const InplaceVector &other) { | 385 | 20.4k | if (this != &other) { | 386 | 20.4k | CopyFrom(other); | 387 | 20.4k | } | 388 | 20.4k | return *this; | 389 | 20.4k | } |
bssl::InplaceVector<unsigned char, 48ul>::operator=(bssl::InplaceVector<unsigned char, 48ul> const&) Line | Count | Source | 384 | 1.10k | InplaceVector &operator=(const InplaceVector &other) { | 385 | 1.10k | if (this != &other) { | 386 | 1.10k | CopyFrom(other); | 387 | 1.10k | } | 388 | 1.10k | return *this; | 389 | 1.10k | } |
|
390 | 0 | InplaceVector &operator=(InplaceVector &&other) { |
391 | 0 | clear(); |
392 | 0 | std::uninitialized_move(other.begin(), other.end(), data()); |
393 | 0 | size_ = other.size(); |
394 | 0 | return *this; |
395 | 0 | } |
396 | | |
397 | 272k | const T *data() const { return reinterpret_cast<const T *>(storage_); } bssl::InplaceVector<unsigned char, 48ul>::data() const Line | Count | Source | 397 | 13.6k | const T *data() const { return reinterpret_cast<const T *>(storage_); } |
bssl::InplaceVector<unsigned char, 32ul>::data() const Line | Count | Source | 397 | 258k | const T *data() const { return reinterpret_cast<const T *>(storage_); } |
Unexecuted instantiation: bssl::InplaceVector<unsigned char, 12ul>::data() const |
398 | 809k | T *data() { return reinterpret_cast<T *>(storage_); } bssl::InplaceVector<unsigned char, 48ul>::data() Line | Count | Source | 398 | 421k | T *data() { return reinterpret_cast<T *>(storage_); } |
Unexecuted instantiation: bssl::InplaceVector<std::__1::unique_ptr<bssl::DTLSWriteEpoch, bssl::internal::Deleter>, 2ul>::data() bssl::InplaceVector<unsigned char, 12ul>::data() Line | Count | Source | 398 | 109k | T *data() { return reinterpret_cast<T *>(storage_); } |
bssl::InplaceVector<unsigned char, 32ul>::data() Line | Count | Source | 398 | 279k | T *data() { return reinterpret_cast<T *>(storage_); } |
Unexecuted instantiation: bssl::InplaceVector<bssl::DTLSOutgoingMessage, 7ul>::data() Unexecuted instantiation: bssl::InplaceVector<bssl::DTLSRecordNumber, 32ul>::data() Unexecuted instantiation: bssl::InplaceVector<bssl::DTLSSentRecord, 32ul>::data() |
399 | 293k | size_t size() const { return size_; } bssl::InplaceVector<unsigned char, 48ul>::size() const Line | Count | Source | 399 | 32.6k | size_t size() const { return size_; } |
Unexecuted instantiation: bssl::InplaceVector<std::__1::unique_ptr<bssl::DTLSWriteEpoch, bssl::internal::Deleter>, 2ul>::size() const Unexecuted instantiation: bssl::InplaceVector<unsigned char, 12ul>::size() const bssl::InplaceVector<unsigned char, 32ul>::size() const Line | Count | Source | 399 | 261k | size_t size() const { return size_; } |
Unexecuted instantiation: bssl::InplaceVector<bssl::DTLSOutgoingMessage, 7ul>::size() const Unexecuted instantiation: bssl::InplaceVector<bssl::DTLSRecordNumber, 32ul>::size() const Unexecuted instantiation: bssl::InplaceVector<bssl::DTLSSentRecord, 32ul>::size() const |
400 | 171k | static constexpr size_t capacity() { return N; } bssl::InplaceVector<unsigned char, 48ul>::capacity() Line | Count | Source | 400 | 73.5k | static constexpr size_t capacity() { return N; } |
Unexecuted instantiation: bssl::InplaceVector<std::__1::unique_ptr<bssl::DTLSWriteEpoch, bssl::internal::Deleter>, 2ul>::capacity() bssl::InplaceVector<unsigned char, 32ul>::capacity() Line | Count | Source | 400 | 86.7k | static constexpr size_t capacity() { return N; } |
bssl::InplaceVector<unsigned char, 12ul>::capacity() Line | Count | Source | 400 | 10.8k | static constexpr size_t capacity() { return N; } |
Unexecuted instantiation: bssl::InplaceVector<bssl::DTLSOutgoingMessage, 7ul>::capacity() Unexecuted instantiation: bssl::InplaceVector<bssl::DTLSRecordNumber, 32ul>::capacity() Unexecuted instantiation: bssl::InplaceVector<bssl::DTLSSentRecord, 32ul>::capacity() |
401 | 778 | bool empty() const { return size_ == 0; } Unexecuted instantiation: bssl::InplaceVector<unsigned char, 12ul>::empty() const bssl::InplaceVector<unsigned char, 48ul>::empty() const Line | Count | Source | 401 | 580 | bool empty() const { return size_ == 0; } |
bssl::InplaceVector<unsigned char, 32ul>::empty() const Line | Count | Source | 401 | 198 | bool empty() const { return size_ == 0; } |
Unexecuted instantiation: bssl::InplaceVector<bssl::DTLSOutgoingMessage, 7ul>::empty() const |
402 | | |
403 | | const T &operator[](size_t i) const { |
404 | | BSSL_CHECK(i < size_); |
405 | | return data()[i]; |
406 | | } |
407 | 0 | T &operator[](size_t i) { |
408 | 0 | BSSL_CHECK(i < size_); |
409 | 0 | return data()[i]; |
410 | 0 | } Unexecuted instantiation: bssl::InplaceVector<unsigned char, 12ul>::operator[](unsigned long) Unexecuted instantiation: bssl::InplaceVector<bssl::DTLSRecordNumber, 32ul>::operator[](unsigned long) Unexecuted instantiation: bssl::InplaceVector<bssl::DTLSSentRecord, 32ul>::operator[](unsigned long) Unexecuted instantiation: bssl::InplaceVector<std::__1::unique_ptr<bssl::DTLSWriteEpoch, bssl::internal::Deleter>, 2ul>::operator[](unsigned long) Unexecuted instantiation: bssl::InplaceVector<bssl::DTLSOutgoingMessage, 7ul>::operator[](unsigned long) |
411 | | |
412 | | T &front() { |
413 | | BSSL_CHECK(size_ != 0); |
414 | | return data()[0]; |
415 | | } |
416 | | const T &front() const { |
417 | | BSSL_CHECK(size_ != 0); |
418 | | return data()[0]; |
419 | | } |
420 | | T &back() { |
421 | | BSSL_CHECK(size_ != 0); |
422 | | return data()[size_ - 1]; |
423 | | } |
424 | | const T &back() const { |
425 | | BSSL_CHECK(size_ != 0); |
426 | | return data()[size_ - 1]; |
427 | | } |
428 | | |
429 | 0 | T *begin() { return data(); } Unexecuted instantiation: bssl::InplaceVector<unsigned char, 48ul>::begin() Unexecuted instantiation: bssl::InplaceVector<bssl::DTLSRecordNumber, 32ul>::begin() Unexecuted instantiation: bssl::InplaceVector<std::__1::unique_ptr<bssl::DTLSWriteEpoch, bssl::internal::Deleter>, 2ul>::begin() Unexecuted instantiation: bssl::InplaceVector<bssl::DTLSOutgoingMessage, 7ul>::begin() |
430 | | const T *begin() const { return data(); } |
431 | 0 | T *end() { return data() + size_; } Unexecuted instantiation: bssl::InplaceVector<unsigned char, 48ul>::end() Unexecuted instantiation: bssl::InplaceVector<bssl::DTLSRecordNumber, 32ul>::end() Unexecuted instantiation: bssl::InplaceVector<std::__1::unique_ptr<bssl::DTLSWriteEpoch, bssl::internal::Deleter>, 2ul>::end() Unexecuted instantiation: bssl::InplaceVector<bssl::DTLSOutgoingMessage, 7ul>::end() |
432 | | const T *end() const { return data() + size_; } |
433 | | |
434 | 617k | void clear() { Shrink(0); } bssl::InplaceVector<unsigned char, 48ul>::clear() Line | Count | Source | 434 | 329k | void clear() { Shrink(0); } |
bssl::InplaceVector<unsigned char, 32ul>::clear() Line | Count | Source | 434 | 189k | void clear() { Shrink(0); } |
bssl::InplaceVector<unsigned char, 12ul>::clear() Line | Count | Source | 434 | 98.5k | void clear() { Shrink(0); } |
Unexecuted instantiation: bssl::InplaceVector<bssl::DTLSRecordNumber, 32ul>::clear() Unexecuted instantiation: bssl::InplaceVector<bssl::DTLSSentRecord, 32ul>::clear() Unexecuted instantiation: bssl::InplaceVector<bssl::DTLSOutgoingMessage, 7ul>::clear() Unexecuted instantiation: bssl::InplaceVector<std::__1::unique_ptr<bssl::DTLSWriteEpoch, bssl::internal::Deleter>, 2ul>::clear() |
435 | | |
436 | | void pop_back() { |
437 | | BSSL_CHECK(size_ != 0); |
438 | | Shrink(size_ - 1); |
439 | | } |
440 | | |
441 | | // Shrink resizes the vector to |new_size|, which must not be larger than the |
442 | | // current size. Unlike |Resize|, this can be called when |T| is not |
443 | | // default-constructible. |
444 | 617k | void Shrink(size_t new_size) { |
445 | 617k | BSSL_CHECK(new_size <= size_); |
446 | 617k | std::destroy_n(data() + new_size, size_ - new_size); |
447 | 617k | size_ = static_cast<PackedSize<N>>(new_size); |
448 | 617k | } bssl::InplaceVector<unsigned char, 48ul>::Shrink(unsigned long) Line | Count | Source | 444 | 329k | void Shrink(size_t new_size) { | 445 | 329k | BSSL_CHECK(new_size <= size_); | 446 | 329k | std::destroy_n(data() + new_size, size_ - new_size); | 447 | 329k | size_ = static_cast<PackedSize<N>>(new_size); | 448 | 329k | } |
bssl::InplaceVector<unsigned char, 32ul>::Shrink(unsigned long) Line | Count | Source | 444 | 189k | void Shrink(size_t new_size) { | 445 | 189k | BSSL_CHECK(new_size <= size_); | 446 | 189k | std::destroy_n(data() + new_size, size_ - new_size); | 447 | 189k | size_ = static_cast<PackedSize<N>>(new_size); | 448 | 189k | } |
bssl::InplaceVector<unsigned char, 12ul>::Shrink(unsigned long) Line | Count | Source | 444 | 98.5k | void Shrink(size_t new_size) { | 445 | 98.5k | BSSL_CHECK(new_size <= size_); | 446 | 98.5k | std::destroy_n(data() + new_size, size_ - new_size); | 447 | 98.5k | size_ = static_cast<PackedSize<N>>(new_size); | 448 | 98.5k | } |
Unexecuted instantiation: bssl::InplaceVector<bssl::DTLSRecordNumber, 32ul>::Shrink(unsigned long) Unexecuted instantiation: bssl::InplaceVector<bssl::DTLSSentRecord, 32ul>::Shrink(unsigned long) Unexecuted instantiation: bssl::InplaceVector<bssl::DTLSOutgoingMessage, 7ul>::Shrink(unsigned long) Unexecuted instantiation: bssl::InplaceVector<std::__1::unique_ptr<bssl::DTLSWriteEpoch, bssl::internal::Deleter>, 2ul>::Shrink(unsigned long) |
449 | | |
450 | | // TryResize resizes the vector to |new_size| and returns true, or returns |
451 | | // false if |new_size| is too large. Any newly-added elements are |
452 | | // value-initialized. |
453 | 884 | [[nodiscard]] bool TryResize(size_t new_size) { |
454 | 884 | if (new_size <= size_) { |
455 | 0 | Shrink(new_size); |
456 | 0 | return true; |
457 | 0 | } |
458 | 884 | if (new_size > capacity()) { |
459 | 0 | return false; |
460 | 0 | } |
461 | 884 | std::uninitialized_value_construct_n(data() + size_, new_size - size_); |
462 | 884 | size_ = static_cast<PackedSize<N>>(new_size); |
463 | 884 | return true; |
464 | 884 | } |
465 | | |
466 | | // TryResizeForOverwrite behaves like |TryResize|, but newly-added elements |
467 | | // are default-initialized, so POD types may contain uninitialized values that |
468 | | // the caller is responsible for filling in. |
469 | 6.81k | [[nodiscard]] bool TryResizeForOverwrite(size_t new_size) { |
470 | 6.81k | if (new_size <= size_) { |
471 | 83 | Shrink(new_size); |
472 | 83 | return true; |
473 | 83 | } |
474 | 6.73k | if (new_size > capacity()) { |
475 | 0 | return false; |
476 | 0 | } |
477 | 6.73k | std::uninitialized_default_construct_n(data() + size_, new_size - size_); |
478 | 6.73k | size_ = static_cast<PackedSize<N>>(new_size); |
479 | 6.73k | return true; |
480 | 6.73k | } bssl::InplaceVector<unsigned char, 32ul>::TryResizeForOverwrite(unsigned long) Line | Count | Source | 469 | 2.10k | [[nodiscard]] bool TryResizeForOverwrite(size_t new_size) { | 470 | 2.10k | if (new_size <= size_) { | 471 | 22 | Shrink(new_size); | 472 | 22 | return true; | 473 | 22 | } | 474 | 2.07k | if (new_size > capacity()) { | 475 | 0 | return false; | 476 | 0 | } | 477 | 2.07k | std::uninitialized_default_construct_n(data() + size_, new_size - size_); | 478 | 2.07k | size_ = static_cast<PackedSize<N>>(new_size); | 479 | 2.07k | return true; | 480 | 2.07k | } |
bssl::InplaceVector<unsigned char, 48ul>::TryResizeForOverwrite(unsigned long) Line | Count | Source | 469 | 4.71k | [[nodiscard]] bool TryResizeForOverwrite(size_t new_size) { | 470 | 4.71k | if (new_size <= size_) { | 471 | 61 | Shrink(new_size); | 472 | 61 | return true; | 473 | 61 | } | 474 | 4.65k | if (new_size > capacity()) { | 475 | 0 | return false; | 476 | 0 | } | 477 | 4.65k | std::uninitialized_default_construct_n(data() + size_, new_size - size_); | 478 | 4.65k | size_ = static_cast<PackedSize<N>>(new_size); | 479 | 4.65k | return true; | 480 | 4.65k | } |
|
481 | | |
482 | | // TryCopyFrom sets the vector to a copy of |in| and returns true, or returns |
483 | | // false if |in| is too large. |
484 | 163k | [[nodiscard]] bool TryCopyFrom(Span<const T> in) { |
485 | 163k | if (in.size() > capacity()) { |
486 | 6 | return false; |
487 | 6 | } |
488 | 163k | clear(); |
489 | 163k | std::uninitialized_copy(in.begin(), in.end(), data()); |
490 | 163k | size_ = in.size(); |
491 | 163k | return true; |
492 | 163k | } bssl::InplaceVector<unsigned char, 48ul>::TryCopyFrom(bssl::Span<unsigned char const>) Line | Count | Source | 484 | 68.0k | [[nodiscard]] bool TryCopyFrom(Span<const T> in) { | 485 | 68.0k | if (in.size() > capacity()) { | 486 | 3 | return false; | 487 | 3 | } | 488 | 68.0k | clear(); | 489 | 68.0k | std::uninitialized_copy(in.begin(), in.end(), data()); | 490 | 68.0k | size_ = in.size(); | 491 | 68.0k | return true; | 492 | 68.0k | } |
bssl::InplaceVector<unsigned char, 12ul>::TryCopyFrom(bssl::Span<unsigned char const>) Line | Count | Source | 484 | 10.5k | [[nodiscard]] bool TryCopyFrom(Span<const T> in) { | 485 | 10.5k | if (in.size() > capacity()) { | 486 | 0 | return false; | 487 | 0 | } | 488 | 10.5k | clear(); | 489 | 10.5k | std::uninitialized_copy(in.begin(), in.end(), data()); | 490 | 10.5k | size_ = in.size(); | 491 | 10.5k | return true; | 492 | 10.5k | } |
bssl::InplaceVector<unsigned char, 32ul>::TryCopyFrom(bssl::Span<unsigned char const>) Line | Count | Source | 484 | 84.6k | [[nodiscard]] bool TryCopyFrom(Span<const T> in) { | 485 | 84.6k | if (in.size() > capacity()) { | 486 | 3 | return false; | 487 | 3 | } | 488 | 84.6k | clear(); | 489 | 84.6k | std::uninitialized_copy(in.begin(), in.end(), data()); | 490 | 84.6k | size_ = in.size(); | 491 | 84.6k | return true; | 492 | 84.6k | } |
|
493 | | |
494 | | // TryPushBack appends |val| to the vector and returns a pointer to the |
495 | | // newly-inserted value, or nullptr if the vector is at capacity. |
496 | 0 | [[nodiscard]] T *TryPushBack(T val) { |
497 | 0 | if (size() >= capacity()) { |
498 | 0 | return nullptr; |
499 | 0 | } |
500 | 0 | T *ret = &data()[size_]; |
501 | 0 | new (ret) T(std::move(val)); |
502 | 0 | size_++; |
503 | 0 | return ret; |
504 | 0 | } Unexecuted instantiation: bssl::InplaceVector<std::__1::unique_ptr<bssl::DTLSWriteEpoch, bssl::internal::Deleter>, 2ul>::TryPushBack(std::__1::unique_ptr<bssl::DTLSWriteEpoch, bssl::internal::Deleter>) Unexecuted instantiation: bssl::InplaceVector<bssl::DTLSOutgoingMessage, 7ul>::TryPushBack(bssl::DTLSOutgoingMessage) Unexecuted instantiation: bssl::InplaceVector<bssl::DTLSRecordNumber, 32ul>::TryPushBack(bssl::DTLSRecordNumber) Unexecuted instantiation: bssl::InplaceVector<bssl::DTLSSentRecord, 32ul>::TryPushBack(bssl::DTLSSentRecord) |
505 | | |
506 | | // The following methods behave like their |Try*| counterparts, but abort the |
507 | | // program on failure. |
508 | 884 | void Resize(size_t size) { BSSL_CHECK(TryResize(size)); } |
509 | 6.81k | void ResizeForOverwrite(size_t size) { |
510 | 6.81k | BSSL_CHECK(TryResizeForOverwrite(size)); |
511 | 6.81k | } bssl::InplaceVector<unsigned char, 32ul>::ResizeForOverwrite(unsigned long) Line | Count | Source | 509 | 2.10k | void ResizeForOverwrite(size_t size) { | 510 | 2.10k | BSSL_CHECK(TryResizeForOverwrite(size)); | 511 | 2.10k | } |
bssl::InplaceVector<unsigned char, 48ul>::ResizeForOverwrite(unsigned long) Line | Count | Source | 509 | 4.71k | void ResizeForOverwrite(size_t size) { | 510 | 4.71k | BSSL_CHECK(TryResizeForOverwrite(size)); | 511 | 4.71k | } |
|
512 | 45.4k | void CopyFrom(Span<const T> in) { BSSL_CHECK(TryCopyFrom(in)); } bssl::InplaceVector<unsigned char, 48ul>::CopyFrom(bssl::Span<unsigned char const>) Line | Count | Source | 512 | 10.9k | void CopyFrom(Span<const T> in) { BSSL_CHECK(TryCopyFrom(in)); } |
bssl::InplaceVector<unsigned char, 12ul>::CopyFrom(bssl::Span<unsigned char const>) Line | Count | Source | 512 | 10.3k | void CopyFrom(Span<const T> in) { BSSL_CHECK(TryCopyFrom(in)); } |
bssl::InplaceVector<unsigned char, 32ul>::CopyFrom(bssl::Span<unsigned char const>) Line | Count | Source | 512 | 24.1k | void CopyFrom(Span<const T> in) { BSSL_CHECK(TryCopyFrom(in)); } |
|
513 | 0 | T &PushBack(T val) { |
514 | 0 | T *ret = TryPushBack(std::move(val)); |
515 | 0 | BSSL_CHECK(ret != nullptr); |
516 | 0 | return *ret; |
517 | 0 | } Unexecuted instantiation: bssl::InplaceVector<std::__1::unique_ptr<bssl::DTLSWriteEpoch, bssl::internal::Deleter>, 2ul>::PushBack(std::__1::unique_ptr<bssl::DTLSWriteEpoch, bssl::internal::Deleter>) Unexecuted instantiation: bssl::InplaceVector<bssl::DTLSRecordNumber, 32ul>::PushBack(bssl::DTLSRecordNumber) Unexecuted instantiation: bssl::InplaceVector<bssl::DTLSSentRecord, 32ul>::PushBack(bssl::DTLSSentRecord) |
518 | | |
519 | | template <typename Pred> |
520 | 0 | void EraseIf(Pred pred) { |
521 | | // See if anything needs to be erased at all. This avoids a self-move. |
522 | 0 | auto iter = std::find_if(begin(), end(), pred); |
523 | 0 | if (iter == end()) { |
524 | 0 | return; |
525 | 0 | } |
526 | | |
527 | | // Elements before the first to be erased may be left as-is. |
528 | 0 | size_t new_size = iter - begin(); |
529 | | // Swap all subsequent elements in if they are to be kept. |
530 | 0 | for (size_t i = new_size + 1; i < size(); i++) { |
531 | 0 | if (!pred((*this)[i])) { |
532 | 0 | (*this)[new_size] = std::move((*this)[i]); |
533 | 0 | new_size++; |
534 | 0 | } |
535 | 0 | } |
536 | |
|
537 | 0 | Shrink(new_size); |
538 | 0 | } |
539 | | |
540 | | private: |
541 | | alignas(T) char storage_[sizeof(T[N])]; |
542 | | PackedSize<N> size_ = 0; |
543 | | }; |
544 | | |
545 | | |
546 | | BSSL_NAMESPACE_END |
547 | | |
548 | | #endif // OPENSSL_HEADER_CRYPTO_MEM_INTERNAL_H |