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

Side by Side Diff: extensions/common/crx_file.cc

Issue 15908002: Differential updates for components. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Sync to LKGR revision 207804. Created 7 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « extensions/common/crx_file.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "extensions/common/crx_file.h" 5 #include "extensions/common/crx_file.h"
6 6
7 namespace extensions { 7 namespace extensions {
8 8
9 namespace { 9 namespace {
10 10
11 // The current version of the crx format. 11 // The current version of the crx format.
12 static const uint32 kCurrentVersion = 2; 12 static const uint32 kCurrentVersion = 2;
13 13
14 // The current version of the crx diff format.
15 static const uint32 kCurrentDiffVersion = 0;
16
14 // The maximum size the crx parser will tolerate for a public key. 17 // The maximum size the crx parser will tolerate for a public key.
15 static const uint32 kMaxPublicKeySize = 1 << 16; 18 static const uint32 kMaxPublicKeySize = 1 << 16;
16 19
17 // The maximum size the crx parser will tolerate for a signature. 20 // The maximum size the crx parser will tolerate for a signature.
18 static const uint32 kMaxSignatureSize = 1 << 16; 21 static const uint32 kMaxSignatureSize = 1 << 16;
19 22
20 } // namespace 23 } // namespace
21 24
22 // The magic string embedded in the header. 25 // The magic string embedded in the header.
23 const char kCrxFileHeaderMagic[] = "Cr24"; 26 const char kCrxFileHeaderMagic[] = "Cr24";
27 const char kCrxDiffFileHeaderMagic[] = "CrOD";
24 28
25 scoped_ptr<CrxFile> CrxFile::Parse(const CrxFile::Header& header, 29 scoped_ptr<CrxFile> CrxFile::Parse(const CrxFile::Header& header,
26 CrxFile::Error* error) { 30 CrxFile::Error* error) {
27 if (HeaderIsValid(header, error)) 31 if (HeaderIsValid(header, error))
28 return scoped_ptr<CrxFile>(new CrxFile(header)); 32 return scoped_ptr<CrxFile>(new CrxFile(header));
29 return scoped_ptr<CrxFile>(); 33 return scoped_ptr<CrxFile>();
30 } 34 }
31 35
32 scoped_ptr<CrxFile> CrxFile::Create(const uint32 key_size, 36 scoped_ptr<CrxFile> CrxFile::Create(const uint32 key_size,
33 const uint32 signature_size, 37 const uint32 signature_size,
34 CrxFile::Error* error) { 38 CrxFile::Error* error) {
35 CrxFile::Header header; 39 CrxFile::Header header;
36 memcpy(&header.magic, kCrxFileHeaderMagic, kCrxFileHeaderMagicSize); 40 memcpy(&header.magic, kCrxFileHeaderMagic, kCrxFileHeaderMagicSize);
37 header.version = kCurrentVersion; 41 header.version = kCurrentVersion;
38 header.key_size = key_size; 42 header.key_size = key_size;
39 header.signature_size = signature_size; 43 header.signature_size = signature_size;
40 if (HeaderIsValid(header, error)) 44 if (HeaderIsValid(header, error))
41 return scoped_ptr<CrxFile>(new CrxFile(header)); 45 return scoped_ptr<CrxFile>(new CrxFile(header));
42 return scoped_ptr<CrxFile>(); 46 return scoped_ptr<CrxFile>();
43 } 47 }
44 48
45 CrxFile::CrxFile(const Header& header) : header_(header) { 49 CrxFile::CrxFile(const Header& header) : header_(header) {
46 } 50 }
47 51
52 bool CrxFile::HeaderIsDelta(const CrxFile::Header& header) {
53 return !strncmp(kCrxDiffFileHeaderMagic, header.magic, sizeof(header.magic));
54 }
55
48 bool CrxFile::HeaderIsValid(const CrxFile::Header& header, 56 bool CrxFile::HeaderIsValid(const CrxFile::Header& header,
49 CrxFile::Error* error) { 57 CrxFile::Error* error) {
50 bool valid = false; 58 bool valid = false;
51 if (strncmp(kCrxFileHeaderMagic, header.magic, sizeof(header.magic))) 59 bool diffCrx = false;
60 if (!strncmp(kCrxDiffFileHeaderMagic, header.magic, sizeof(header.magic)))
61 diffCrx = true;
62 if (strncmp(kCrxFileHeaderMagic, header.magic, sizeof(header.magic)) &&
63 !diffCrx)
52 *error = kWrongMagic; 64 *error = kWrongMagic;
53 else if (header.version != kCurrentVersion) 65 else if (header.version != kCurrentVersion
66 && !(diffCrx && header.version == kCurrentDiffVersion))
54 *error = kInvalidVersion; 67 *error = kInvalidVersion;
55 else if (header.key_size > kMaxPublicKeySize) 68 else if (header.key_size > kMaxPublicKeySize)
56 *error = kInvalidKeyTooLarge; 69 *error = kInvalidKeyTooLarge;
57 else if (header.key_size == 0) 70 else if (header.key_size == 0)
58 *error = kInvalidKeyTooSmall; 71 *error = kInvalidKeyTooSmall;
59 else if (header.signature_size > kMaxSignatureSize) 72 else if (header.signature_size > kMaxSignatureSize)
60 *error = kInvalidSignatureTooLarge; 73 *error = kInvalidSignatureTooLarge;
61 else if (header.signature_size == 0) 74 else if (header.signature_size == 0)
62 *error = kInvalidSignatureTooSmall; 75 *error = kInvalidSignatureTooSmall;
63 else 76 else
64 valid = true; 77 valid = true;
65 return valid; 78 return valid;
66 } 79 }
67 80
68 } // namespace extensions 81 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/crx_file.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698