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

Side by Side Diff: components/crx_file/crx_file.h

Issue 1546143002: Switch to standard integer types in components/, part 1 of 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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
« no previous file with comments | « components/crx_file/constants.h ('k') | components/crx_file/crx_file.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #ifndef COMPONENTS_CRX_FILE_CRX_FILE_H_ 5 #ifndef COMPONENTS_CRX_FILE_CRX_FILE_H_
6 #define COMPONENTS_CRX_FILE_CRX_FILE_H_ 6 #define COMPONENTS_CRX_FILE_CRX_FILE_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include <stddef.h>
12 #include <stdint.h>
11 #include <sys/types.h> 13 #include <sys/types.h>
12 #include "base/basictypes.h"
13 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
14 15
15 namespace base { 16 namespace base {
16 class FilePath; 17 class FilePath;
17 } 18 }
18 19
19 namespace crx_file { 20 namespace crx_file {
20 21
21 // CRX files have a header that includes a magic key, version number, and 22 // CRX files have a header that includes a magic key, version number, and
22 // some signature sizing information. Use CrxFile object to validate whether 23 // some signature sizing information. Use CrxFile object to validate whether
23 // the header is valid or not. 24 // the header is valid or not.
24 class CrxFile { 25 class CrxFile {
25 public: 26 public:
26 // The size of the magic character sequence at the beginning of each crx 27 // The size of the magic character sequence at the beginning of each crx
27 // file, in bytes. This should be a multiple of 4. 28 // file, in bytes. This should be a multiple of 4.
28 static const size_t kCrxFileHeaderMagicSize = 4; 29 static const size_t kCrxFileHeaderMagicSize = 4;
29 30
30 // This header is the first data at the beginning of an extension. Its 31 // This header is the first data at the beginning of an extension. Its
31 // contents are purposely 32-bit aligned so that it can just be slurped into 32 // contents are purposely 32-bit aligned so that it can just be slurped into
32 // a struct without manual parsing. 33 // a struct without manual parsing.
33 struct Header { 34 struct Header {
34 char magic[kCrxFileHeaderMagicSize]; 35 char magic[kCrxFileHeaderMagicSize];
35 uint32 version; 36 uint32_t version;
36 uint32 key_size; // The size of the public key, in bytes. 37 uint32_t key_size; // The size of the public key, in bytes.
37 uint32 signature_size; // The size of the signature, in bytes. 38 uint32_t signature_size; // The size of the signature, in bytes.
38 // An ASN.1-encoded PublicKeyInfo structure follows. 39 // An ASN.1-encoded PublicKeyInfo structure follows.
39 // The signature follows. 40 // The signature follows.
40 }; 41 };
41 42
42 enum Error { 43 enum Error {
43 kWrongMagic, 44 kWrongMagic,
44 kInvalidVersion, 45 kInvalidVersion,
45 kInvalidKeyTooLarge, 46 kInvalidKeyTooLarge,
46 kInvalidKeyTooSmall, 47 kInvalidKeyTooSmall,
47 kInvalidSignatureTooLarge, 48 kInvalidSignatureTooLarge,
48 kInvalidSignatureTooSmall, 49 kInvalidSignatureTooSmall,
49 }; 50 };
50 51
51 // Construct a new CRX file header object with bytes of a header 52 // Construct a new CRX file header object with bytes of a header
52 // read from a CRX file. If a null scoped_ptr is returned, |error| 53 // read from a CRX file. If a null scoped_ptr is returned, |error|
53 // contains an error code with additional information. 54 // contains an error code with additional information.
54 static scoped_ptr<CrxFile> Parse(const Header& header, Error* error); 55 static scoped_ptr<CrxFile> Parse(const Header& header, Error* error);
55 56
56 // Construct a new header for the given key and signature sizes. 57 // Construct a new header for the given key and signature sizes.
57 // Returns a null scoped_ptr if erroneous values of |key_size| and/or 58 // Returns a null scoped_ptr if erroneous values of |key_size| and/or
58 // |signature_size| are provided. |error| contains an error code with 59 // |signature_size| are provided. |error| contains an error code with
59 // additional information. 60 // additional information.
60 // Use this constructor and then .header() to obtain the Header 61 // Use this constructor and then .header() to obtain the Header
61 // for writing out to a CRX file. 62 // for writing out to a CRX file.
62 static scoped_ptr<CrxFile> Create(const uint32 key_size, 63 static scoped_ptr<CrxFile> Create(const uint32_t key_size,
63 const uint32 signature_size, 64 const uint32_t signature_size,
64 Error* error); 65 Error* error);
65 66
66 // Returns the header structure for writing out to a CRX file. 67 // Returns the header structure for writing out to a CRX file.
67 const Header& header() const { return header_; } 68 const Header& header() const { return header_; }
68 69
69 // Checks a valid |header| to determine whether or not the CRX represents a 70 // Checks a valid |header| to determine whether or not the CRX represents a
70 // differential CRX. 71 // differential CRX.
71 static bool HeaderIsDelta(const Header& header); 72 static bool HeaderIsDelta(const Header& header);
72 73
73 enum class ValidateError { 74 enum class ValidateError {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 explicit CrxFile(const Header& header); 109 explicit CrxFile(const Header& header);
109 110
110 // Checks the |header| for validity and returns true if the values are valid. 111 // Checks the |header| for validity and returns true if the values are valid.
111 // If false is returned, more detailed error code is returned in |error|. 112 // If false is returned, more detailed error code is returned in |error|.
112 static bool HeaderIsValid(const Header& header, Error* error); 113 static bool HeaderIsValid(const Header& header, Error* error);
113 }; 114 };
114 115
115 } // namespace crx_file 116 } // namespace crx_file
116 117
117 #endif // COMPONENTS_CRX_FILE_CRX_FILE_H_ 118 #endif // COMPONENTS_CRX_FILE_CRX_FILE_H_
OLDNEW
« no previous file with comments | « components/crx_file/constants.h ('k') | components/crx_file/crx_file.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698