Add an implicit CBS to Span<const uint8_t> conversion.
They are exactly the same structure. Doing it in CBS allows us to switch bssl::Span to absl::Span or a standard std::span in the future. Bug: 132 Change-Id: Ibc96673c23233d557a1dd4d8768d2659d7a4ca0c Reviewed-on: https://boringssl-review.googlesource.com/20669 Reviewed-by: David Benjamin <davidben@google.com> Commit-Queue: David Benjamin <davidben@google.com> CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
This commit is contained in:
parent
cf0ce676d6
commit
6b3ab72602
@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
#include <openssl/base.h>
|
#include <openssl/base.h>
|
||||||
|
|
||||||
|
#include <openssl/span.h>
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
@ -37,6 +39,13 @@ extern "C" {
|
|||||||
struct cbs_st {
|
struct cbs_st {
|
||||||
const uint8_t *data;
|
const uint8_t *data;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
|
#if !defined(BORINGSSL_NO_CXX)
|
||||||
|
// Allow implicit conversions to bssl::Span<const uint8_t>.
|
||||||
|
operator bssl::Span<const uint8_t>() const {
|
||||||
|
return bssl::MakeConstSpan(data, len);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
// CBS_init sets |cbs| to point to |data|. It does not take ownership of
|
// CBS_init sets |cbs| to point to |data|. It does not take ownership of
|
||||||
|
@ -1180,9 +1180,7 @@ static enum ssl_hs_wait_t do_read_client_key_exchange(SSL_HANDSHAKE *hs) {
|
|||||||
|
|
||||||
// Compute the premaster.
|
// Compute the premaster.
|
||||||
uint8_t alert = SSL_AD_DECODE_ERROR;
|
uint8_t alert = SSL_AD_DECODE_ERROR;
|
||||||
if (!hs->key_share->Finish(
|
if (!hs->key_share->Finish(&premaster_secret, &alert, peer_key)) {
|
||||||
&premaster_secret, &alert,
|
|
||||||
MakeConstSpan(CBS_data(&peer_key), CBS_len(&peer_key)))) {
|
|
||||||
ssl3_send_alert(ssl, SSL3_AL_FATAL, alert);
|
ssl3_send_alert(ssl, SSL3_AL_FATAL, alert);
|
||||||
return ssl_hs_error;
|
return ssl_hs_error;
|
||||||
}
|
}
|
||||||
|
@ -2174,9 +2174,7 @@ int ssl_ext_key_share_parse_serverhello(SSL_HANDSHAKE *hs,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hs->key_share->Finish(
|
if (!hs->key_share->Finish(out_secret, out_alert, peer_key)) {
|
||||||
out_secret, out_alert,
|
|
||||||
MakeConstSpan(CBS_data(&peer_key), CBS_len(&peer_key)))) {
|
|
||||||
*out_alert = SSL_AD_INTERNAL_ERROR;
|
*out_alert = SSL_AD_INTERNAL_ERROR;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -2238,10 +2236,9 @@ int ssl_ext_key_share_parse_clienthello(SSL_HANDSHAKE *hs, bool *out_found,
|
|||||||
Array<uint8_t> secret;
|
Array<uint8_t> secret;
|
||||||
ScopedCBB public_key;
|
ScopedCBB public_key;
|
||||||
UniquePtr<SSLKeyShare> key_share = SSLKeyShare::Create(group_id);
|
UniquePtr<SSLKeyShare> key_share = SSLKeyShare::Create(group_id);
|
||||||
if (!key_share || !CBB_init(public_key.get(), 32) ||
|
if (!key_share ||
|
||||||
!key_share->Accept(
|
!CBB_init(public_key.get(), 32) ||
|
||||||
public_key.get(), &secret, out_alert,
|
!key_share->Accept(public_key.get(), &secret, out_alert, peer_key) ||
|
||||||
MakeConstSpan(CBS_data(&peer_key), CBS_len(&peer_key))) ||
|
|
||||||
!CBB_finish(public_key.get(), &hs->ecdh_public_key,
|
!CBB_finish(public_key.get(), &hs->ecdh_public_key,
|
||||||
&hs->ecdh_public_key_len)) {
|
&hs->ecdh_public_key_len)) {
|
||||||
*out_alert = SSL_AD_ILLEGAL_PARAMETER;
|
*out_alert = SSL_AD_ILLEGAL_PARAMETER;
|
||||||
|
Loading…
Reference in New Issue
Block a user