Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2935)

Unified Diff: delta_performer.cc

Issue 6265001: AU: Add support for signing of update payloads after they're generated. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git@master
Patch Set: rename function Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « delta_performer.h ('k') | delta_performer_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: delta_performer.cc
diff --git a/delta_performer.cc b/delta_performer.cc
index 6eb8aea0ed494d4262862a3ad11c9e3169cc3774..117e8f5d99e717d5c8d0d2f5665e66c78ba664eb 100644
--- a/delta_performer.cc
+++ b/delta_performer.cc
@@ -194,6 +194,43 @@ void LogPartitionInfo(const DeltaArchiveManifest& manifest) {
} // namespace {}
+DeltaPerformer::MetadataParseResult DeltaPerformer::ParsePayloadMetadata(
+ const std::vector<char>& payload,
+ DeltaArchiveManifest* manifest,
+ uint64_t* metadata_size) {
+ if (payload.size() < strlen(kDeltaMagic) +
+ kDeltaVersionLength + kDeltaProtobufLengthLength) {
+ // Don't have enough bytes to know the protobuf length.
+ return kMetadataParseInsufficientData;
+ }
+ if (memcmp(payload.data(), kDeltaMagic, strlen(kDeltaMagic)) != 0) {
+ LOG(ERROR) << "Bad payload format -- invalid delta magic.";
+ return kMetadataParseError;
+ }
+ uint64_t protobuf_length;
+ COMPILE_ASSERT(sizeof(protobuf_length) == kDeltaProtobufLengthLength,
+ protobuf_length_size_mismatch);
+ memcpy(&protobuf_length,
+ &payload[strlen(kDeltaMagic) + kDeltaVersionLength],
+ kDeltaProtobufLengthLength);
+ protobuf_length = be64toh(protobuf_length); // switch big endian to host
+ if (payload.size() < strlen(kDeltaMagic) + kDeltaVersionLength +
+ kDeltaProtobufLengthLength + protobuf_length) {
+ return kMetadataParseInsufficientData;
+ }
+ // We have the full proto buffer in |payload|. Parse it.
+ const int offset = strlen(kDeltaMagic) + kDeltaVersionLength +
+ kDeltaProtobufLengthLength;
+ if (!manifest->ParseFromArray(&payload[offset], protobuf_length)) {
+ LOG(ERROR) << "Unable to parse manifest in update file.";
+ return kMetadataParseError;
+ }
+ *metadata_size = strlen(kDeltaMagic) + kDeltaVersionLength +
+ kDeltaProtobufLengthLength + protobuf_length;
+ return kMetadataParseSuccess;
+}
+
+
// Wrapper around write. Returns bytes written on success or
// -errno on error.
// This function performs as many actions as it can, given the amount of
@@ -203,37 +240,17 @@ ssize_t DeltaPerformer::Write(const void* bytes, size_t count) {
buffer_.insert(buffer_.end(), c_bytes, c_bytes + count);
if (!manifest_valid_) {
- if (buffer_.size() < strlen(kDeltaMagic) +
- kDeltaVersionLength + kDeltaProtobufLengthLength) {
- // Don't have enough bytes to know the protobuf length.
- return count;
- }
- if (memcmp(buffer_.data(), kDeltaMagic, strlen(kDeltaMagic)) != 0) {
- LOG(ERROR) << "Bad payload format -- invalid delta magic.";
+ MetadataParseResult result = ParsePayloadMetadata(buffer_,
+ &manifest_,
+ &manifest_metadata_size_);
+ if (result == kMetadataParseError) {
return -EINVAL;
}
- uint64_t protobuf_length;
- COMPILE_ASSERT(sizeof(protobuf_length) == kDeltaProtobufLengthLength,
- protobuf_length_size_mismatch);
- memcpy(&protobuf_length,
- &buffer_[strlen(kDeltaMagic) + kDeltaVersionLength],
- kDeltaProtobufLengthLength);
- protobuf_length = be64toh(protobuf_length); // switch big endian to host
- if (buffer_.size() < strlen(kDeltaMagic) + kDeltaVersionLength +
- kDeltaProtobufLengthLength + protobuf_length) {
+ if (result == kMetadataParseInsufficientData) {
return count;
}
- // We have the full proto buffer in buffer_. Parse it.
- const int offset = strlen(kDeltaMagic) + kDeltaVersionLength +
- kDeltaProtobufLengthLength;
- if (!manifest_.ParseFromArray(&buffer_[offset], protobuf_length)) {
- LOG(ERROR) << "Unable to parse manifest in update file.";
- return -EINVAL;
- }
// Remove protobuf and header info from buffer_, so buffer_ contains
// just data blobs
- manifest_metadata_size_ = strlen(kDeltaMagic) + kDeltaVersionLength +
- kDeltaProtobufLengthLength + protobuf_length;
DiscardBufferHeadBytes(manifest_metadata_size_);
LOG_IF(WARNING, !prefs_->SetInt64(kPrefsManifestMetadataSize,
manifest_metadata_size_))
« no previous file with comments | « delta_performer.h ('k') | delta_performer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698