Index: components/crx_file/crx2_file.h |
diff --git a/components/crx_file/crx2_file.h b/components/crx_file/crx2_file.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3e118e6c850123d592e43c5264f5a9f85e164751 |
--- /dev/null |
+++ b/components/crx_file/crx2_file.h |
@@ -0,0 +1,75 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
Sorin Jianu
2017/05/15 19:49:52
2017
waffles
2017/05/16 00:29:01
Are we supposed to update the Copyright when movin
|
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef COMPONENTS_CRX_FILE_CRX2_FILE_H_ |
+#define COMPONENTS_CRX_FILE_CRX2_FILE_H_ |
+ |
+#include <stddef.h> |
+#include <stdint.h> |
+#include <sys/types.h> |
+ |
+#include <memory> |
+#include <string> |
+#include <vector> |
+ |
+namespace crx_file { |
+ |
+// The magic string embedded in the header. |
+constexpr char kCrx2FileHeaderMagic[] = "Cr24"; |
+constexpr char kCrxDiffFileHeaderMagic[] = "CrOD"; |
+constexpr int kCrx2FileHeaderMagicSize = 4; |
+ |
+// CRX files have a header that includes a magic key, version number, and |
+// some signature sizing information. Use Crx2File object to validate whether |
+// the header is valid or not. |
+class Crx2File { |
+ public: |
+ // This header is the first data at the beginning of an extension. Its |
+ // contents are purposely 32-bit aligned so that it can just be slurped into |
+ // a struct without manual parsing. |
+ struct Header { |
+ char magic[kCrx2FileHeaderMagicSize]; |
+ uint32_t version; |
+ uint32_t key_size; // The size of the public key, in bytes. |
+ uint32_t signature_size; // The size of the signature, in bytes. |
+ // An ASN.1-encoded PublicKeyInfo structure follows. |
+ // The signature follows. |
+ }; |
+ |
+ enum Error { |
+ kWrongMagic, |
+ kInvalidVersion, |
+ kInvalidKeyTooLarge, |
+ kInvalidKeyTooSmall, |
+ kInvalidSignatureTooLarge, |
+ kInvalidSignatureTooSmall, |
+ }; |
+ |
+ // Construct a new header for the given key and signature sizes. |
+ // Returns a null scoped_ptr if erroneous values of |key_size| and/or |
Sorin Jianu
2017/05/15 19:49:52
Returns null if...
waffles
2017/05/16 00:29:01
Done.
|
+ // |signature_size| are provided. |error| contains an error code with |
+ // additional information. |
+ // Use this constructor and then .header() to obtain the Header |
+ // for writing out to a CRX file. |
+ static std::unique_ptr<Crx2File> Create(const uint32_t key_size, |
+ const uint32_t signature_size, |
+ Error* error); |
+ |
+ // Returns the header structure for writing out to a CRX file. |
+ const Header& header() const { return header_; } |
+ |
+ private: |
+ Header header_; |
+ |
+ // Constructor is private. Clients should use static factory methods above. |
+ explicit Crx2File(const Header& header); |
+ |
+ // Checks the |header| for validity and returns true if the values are valid. |
+ // If false is returned, more detailed error code is returned in |error|. |
+ static bool HeaderIsValid(const Header& header, Error* error); |
+}; |
+ |
+} // namespace crx_file |
+ |
+#endif // COMPONENTS_CRX_FILE_CRX2_FILE_H_ |