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

Side by Side Diff: chrome/browser/extensions/crx_file.cc

Issue 12578008: Move CrxFile, FileReader, ExtensionResource to src/extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 9 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 | « chrome/browser/extensions/crx_file.h ('k') | chrome/browser/extensions/crx_installer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/crx_file.h"
6
7 namespace extensions {
8
9 namespace {
10
11 // The current version of the crx format.
12 static const uint32 kCurrentVersion = 2;
13
14 // The maximum size the crx parser will tolerate for a public key.
15 static const uint32 kMaxPublicKeySize = 1 << 16;
16
17 // The maximum size the crx parser will tolerate for a signature.
18 static const uint32 kMaxSignatureSize = 1 << 16;
19
20 } // namespace
21
22 // The magic string embedded in the header.
23 const char kCrxFileHeaderMagic[] = "Cr24";
24
25 scoped_ptr<CrxFile> CrxFile::Parse(const CrxFile::Header& header,
26 CrxFile::Error* error) {
27 if (HeaderIsValid(header, error))
28 return scoped_ptr<CrxFile>(new CrxFile(header));
29 return scoped_ptr<CrxFile>();
30 }
31
32 scoped_ptr<CrxFile> CrxFile::Create(const uint32 key_size,
33 const uint32 signature_size,
34 CrxFile::Error* error) {
35 CrxFile::Header header;
36 memcpy(&header.magic, kCrxFileHeaderMagic, kCrxFileHeaderMagicSize);
37 header.version = kCurrentVersion;
38 header.key_size = key_size;
39 header.signature_size = signature_size;
40 if (HeaderIsValid(header, error))
41 return scoped_ptr<CrxFile>(new CrxFile(header));
42 return scoped_ptr<CrxFile>();
43 }
44
45 CrxFile::CrxFile(const Header& header) : header_(header) {
46 }
47
48 bool CrxFile::HeaderIsValid(const CrxFile::Header& header,
49 CrxFile::Error* error) {
50 bool valid = false;
51 if (strncmp(kCrxFileHeaderMagic, header.magic, sizeof(header.magic)))
52 *error = kWrongMagic;
53 else if (header.version != kCurrentVersion)
54 *error = kInvalidVersion;
55 else if (header.key_size > kMaxPublicKeySize)
56 *error = kInvalidKeyTooLarge;
57 else if (header.key_size == 0)
58 *error = kInvalidKeyTooSmall;
59 else if (header.signature_size > kMaxSignatureSize)
60 *error = kInvalidSignatureTooLarge;
61 else if (header.signature_size == 0)
62 *error = kInvalidSignatureTooSmall;
63 else
64 valid = true;
65 return valid;
66 }
67
68 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/crx_file.h ('k') | chrome/browser/extensions/crx_installer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698