Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/gcm_driver/crypto/message_payload_parser.h" | |
| 6 | |
| 7 #include "base/big_endian.h" | |
| 8 | |
| 9 namespace gcm { | |
| 10 | |
| 11 namespace { | |
| 12 | |
| 13 // Size, in bytes, of the salt included in the message header. | |
| 14 constexpr size_t kSaltSize = 16; | |
| 15 | |
| 16 // Size, in bytes, of the uncompressed point included in the message header. | |
| 17 constexpr size_t kUncompressedPointSize = 65; | |
|
johnme
2017/05/22 16:18:39
Nit: perhaps stick to "keyid" for consistency with
Peter Beverloo
2017/05/22 17:25:12
I've updated the header instead.
| |
| 18 | |
| 19 // Size, in bytes, of the smallest allowable record_size value. | |
| 20 constexpr size_t kMinimumRecordSize = 18; | |
| 21 | |
| 22 // Size, in bytes, of an empty message with the minimum amount of padding. | |
| 23 constexpr size_t kMinimumMessageSize = | |
| 24 kSaltSize + sizeof(uint32_t) + sizeof(uint8_t) + kUncompressedPointSize + | |
|
johnme
2017/05/22 16:18:39
Nit: perhaps use sizeof(record_size_) instead of s
Peter Beverloo
2017/05/22 17:25:12
That's a private class member, so it'd be a bit aw
| |
| 25 kMinimumRecordSize; | |
| 26 | |
| 27 } // namespace | |
| 28 | |
| 29 MessagePayloadParser::MessagePayloadParser(base::StringPiece message) { | |
| 30 if (message.size() < kMinimumMessageSize) | |
| 31 return; | |
| 32 | |
| 33 salt_ = message.substr(0, kSaltSize); | |
| 34 message.remove_prefix(kSaltSize); | |
| 35 | |
| 36 base::ReadBigEndian(message.data(), &record_size_); | |
|
johnme
2017/05/22 16:18:39
Do we need to worry about the "This would cause SI
Peter Beverloo
2017/05/22 17:25:12
Looking at code search, it doesn't look like we su
| |
| 37 message.remove_prefix(sizeof(record_size_)); | |
| 38 | |
| 39 if (record_size_ < kMinimumRecordSize) | |
| 40 return; | |
| 41 | |
| 42 uint8_t public_key_length; | |
| 43 base::ReadBigEndian(message.data(), &public_key_length); | |
| 44 message.remove_prefix(sizeof(public_key_length)); | |
| 45 | |
| 46 if (public_key_length != kUncompressedPointSize) | |
| 47 return; | |
| 48 | |
| 49 public_key_ = message.substr(0, kUncompressedPointSize); | |
|
johnme
2017/05/22 16:18:39
It's a little surprising that you mention in the c
Peter Beverloo
2017/05/22 17:25:12
Done.
| |
| 50 message.remove_prefix(kUncompressedPointSize); | |
| 51 | |
| 52 ciphertext_ = message; | |
| 53 | |
| 54 if (ciphertext_.size() < kMinimumRecordSize) | |
|
johnme
2017/05/22 16:18:39
Shouldn't this be `(ciphertext_.size() != record_s
Peter Beverloo
2017/05/22 17:25:12
No, because record_size_ can be larger too. (We de
| |
| 55 return; | |
| 56 | |
| 57 is_valid_ = true; | |
| 58 } | |
| 59 | |
| 60 MessagePayloadParser::~MessagePayloadParser() = default; | |
| 61 | |
| 62 } // namespace gcm | |
| OLD | NEW |