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.
5 #ifndef EXTENSIONS_COMMON_CRX_FILE_H_
6 #define EXTENSIONS_COMMON_CRX_FILE_H_
9 #include "base/basictypes.h"
10 #include "base/memory/scoped_ptr.h"
12 namespace extensions
{
14 // CRX files have a header that includes a magic key, version number, and
15 // some signature sizing information. Use CrxFile object to validate whether
16 // the header is valid or not.
20 // The size of the magic character sequence at the beginning of each crx
21 // file, in bytes. This should be a multiple of 4.
22 static const size_t kCrxFileHeaderMagicSize
= 4;
24 // This header is the first data at the beginning of an extension. Its
25 // contents are purposely 32-bit aligned so that it can just be slurped into
26 // a struct without manual parsing.
28 char magic
[kCrxFileHeaderMagicSize
];
30 uint32 key_size
; // The size of the public key, in bytes.
31 uint32 signature_size
; // The size of the signature, in bytes.
32 // An ASN.1-encoded PublicKeyInfo structure follows.
33 // The signature follows.
41 kInvalidSignatureTooLarge
,
42 kInvalidSignatureTooSmall
,
45 // Construct a new CRX file header object with bytes of a header
46 // read from a CRX file. If a null scoped_ptr is returned, |error|
47 // contains an error code with additional information.
48 static scoped_ptr
<CrxFile
> Parse(const Header
& header
, Error
* error
);
50 // Construct a new header for the given key and signature sizes.
51 // Returns a null scoped_ptr if erroneous values of |key_size| and/or
52 // |signature_size| are provided. |error| contains an error code with
53 // additional information.
54 // Use this constructor and then .header() to obtain the Header
55 // for writing out to a CRX file.
56 static scoped_ptr
<CrxFile
> Create(const uint32 key_size
,
57 const uint32 signature_size
,
60 // Returns the header structure for writing out to a CRX file.
61 const Header
& header() const { return header_
; }
63 // Checks a valid |header| to determine whether or not the CRX represents a
65 static bool HeaderIsDelta(const Header
& header
);
70 // Constructor is private. Clients should use static factory methods above.
71 explicit CrxFile(const Header
& header
);
73 // Checks the |header| for validity and returns true if the values are valid.
74 // If false is returned, more detailed error code is returned in |error|.
75 static bool HeaderIsValid(const Header
& header
, Error
* error
);
78 } // namespace extensions
80 #endif // EXTENSIONS_COMMON_CRX_FILE_H_