-
Notifications
You must be signed in to change notification settings - Fork 900
/
Copy pathprivate_cdn_helper.cc
40 lines (29 loc) · 1.13 KB
/
private_cdn_helper.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */
#include "brave/components/brave_private_cdn/private_cdn_helper.h"
#include "base/big_endian.h"
namespace brave {
bool PrivateCdnHelper::RemovePadding(base::StringPiece* padded_string) const {
if (!padded_string) {
return false;
}
if (padded_string->size() < sizeof(uint32_t)) {
return false; // Missing length field
}
// Read payload length from the header.
uint32_t data_length;
base::ReadBigEndian(padded_string->data(), &data_length);
// Remove length header.
padded_string->remove_prefix(sizeof(uint32_t));
if (padded_string->size() < data_length) {
return false; // Payload shorter than expected length
}
// Remove padding.
padded_string->remove_suffix(padded_string->size() - data_length);
return true;
}
PrivateCdnHelper::PrivateCdnHelper() = default;
PrivateCdnHelper::~PrivateCdnHelper() = default;
} // namespace brave