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: trunk/src/extensions/common/crx_file.cc

Issue 17551004: Revert 207805 "Differential updates for components. We are addin..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: 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 | « trunk/src/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
17 // The maximum size the crx parser will tolerate for a public key. 14 // The maximum size the crx parser will tolerate for a public key.
18 static const uint32 kMaxPublicKeySize = 1 << 16; 15 static const uint32 kMaxPublicKeySize = 1 << 16;
19 16
20 // The maximum size the crx parser will tolerate for a signature. 17 // The maximum size the crx parser will tolerate for a signature.
21 static const uint32 kMaxSignatureSize = 1 << 16; 18 static const uint32 kMaxSignatureSize = 1 << 16;
22 19
23 } // namespace 20 } // namespace
24 21
25 // The magic string embedded in the header. 22 // The magic string embedded in the header.
26 const char kCrxFileHeaderMagic[] = "Cr24"; 23 const char kCrxFileHeaderMagic[] = "Cr24";
27 const char kCrxDiffFileHeaderMagic[] = "CrOD";
28 24
29 scoped_ptr<CrxFile> CrxFile::Parse(const CrxFile::Header& header, 25 scoped_ptr<CrxFile> CrxFile::Parse(const CrxFile::Header& header,
30 CrxFile::Error* error) { 26 CrxFile::Error* error) {
31 if (HeaderIsValid(header, error)) 27 if (HeaderIsValid(header, error))
32 return scoped_ptr<CrxFile>(new CrxFile(header)); 28 return scoped_ptr<CrxFile>(new CrxFile(header));
33 return scoped_ptr<CrxFile>(); 29 return scoped_ptr<CrxFile>();
34 } 30 }
35 31
36 scoped_ptr<CrxFile> CrxFile::Create(const uint32 key_size, 32 scoped_ptr<CrxFile> CrxFile::Create(const uint32 key_size,
37 const uint32 signature_size, 33 const uint32 signature_size,
38 CrxFile::Error* error) { 34 CrxFile::Error* error) {
39 CrxFile::Header header; 35 CrxFile::Header header;
40 memcpy(&header.magic, kCrxFileHeaderMagic, kCrxFileHeaderMagicSize); 36 memcpy(&header.magic, kCrxFileHeaderMagic, kCrxFileHeaderMagicSize);
41 header.version = kCurrentVersion; 37 header.version = kCurrentVersion;
42 header.key_size = key_size; 38 header.key_size = key_size;
43 header.signature_size = signature_size; 39 header.signature_size = signature_size;
44 if (HeaderIsValid(header, error)) 40 if (HeaderIsValid(header, error))
45 return scoped_ptr<CrxFile>(new CrxFile(header)); 41 return scoped_ptr<CrxFile>(new CrxFile(header));
46 return scoped_ptr<CrxFile>(); 42 return scoped_ptr<CrxFile>();
47 } 43 }
48 44
49 CrxFile::CrxFile(const Header& header) : header_(header) { 45 CrxFile::CrxFile(const Header& header) : header_(header) {
50 } 46 }
51 47
52 bool CrxFile::HeaderIsDelta(const CrxFile::Header& header) {
53 return !strncmp(kCrxDiffFileHeaderMagic, header.magic, sizeof(header.magic));
54 }
55
56 bool CrxFile::HeaderIsValid(const CrxFile::Header& header, 48 bool CrxFile::HeaderIsValid(const CrxFile::Header& header,
57 CrxFile::Error* error) { 49 CrxFile::Error* error) {
58 bool valid = false; 50 bool valid = false;
59 bool diffCrx = false; 51 if (strncmp(kCrxFileHeaderMagic, header.magic, sizeof(header.magic)))
60 if (!strncmp(kCrxDiffFileHeaderMagic, header.magic, sizeof(header.magic)))
61 diffCrx = true;
62 if (strncmp(kCrxFileHeaderMagic, header.magic, sizeof(header.magic)) &&
63 !diffCrx)
64 *error = kWrongMagic; 52 *error = kWrongMagic;
65 else if (header.version != kCurrentVersion 53 else if (header.version != kCurrentVersion)
66 && !(diffCrx && header.version == kCurrentDiffVersion))
67 *error = kInvalidVersion; 54 *error = kInvalidVersion;
68 else if (header.key_size > kMaxPublicKeySize) 55 else if (header.key_size > kMaxPublicKeySize)
69 *error = kInvalidKeyTooLarge; 56 *error = kInvalidKeyTooLarge;
70 else if (header.key_size == 0) 57 else if (header.key_size == 0)
71 *error = kInvalidKeyTooSmall; 58 *error = kInvalidKeyTooSmall;
72 else if (header.signature_size > kMaxSignatureSize) 59 else if (header.signature_size > kMaxSignatureSize)
73 *error = kInvalidSignatureTooLarge; 60 *error = kInvalidSignatureTooLarge;
74 else if (header.signature_size == 0) 61 else if (header.signature_size == 0)
75 *error = kInvalidSignatureTooSmall; 62 *error = kInvalidSignatureTooSmall;
76 else 63 else
77 valid = true; 64 valid = true;
78 return valid; 65 return valid;
79 } 66 }
80 67
81 } // namespace extensions 68 } // namespace extensions
OLDNEW
« no previous file with comments | « trunk/src/extensions/common/crx_file.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698