1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef MAR_PRIVATE_H__
8 #define MAR_PRIVATE_H__
11 #include "mozilla/Assertions.h"
14 #define BLOCKSIZE 4096
15 #define ROUND_UP(n, incr) (((n) / (incr) + 1) * (incr))
20 /* The signature block comes directly after the header block
22 #define SIGNATURE_BLOCK_OFFSET 16
24 /* Make sure the file is less than 500MB. We do this to protect against
26 #define MAX_SIZE_OF_MAR_FILE ((int64_t)524288000)
28 /* Existing code makes assumptions that the file size is
29 smaller than LONG_MAX. */
30 MOZ_STATIC_ASSERT(MAX_SIZE_OF_MAR_FILE
< ((int64_t)LONG_MAX
),
31 "max mar file size is too big");
33 /* We store at most the size up to the signature block + 4
34 bytes per BLOCKSIZE bytes */
35 MOZ_STATIC_ASSERT(sizeof(BLOCKSIZE
) < \
36 (SIGNATURE_BLOCK_OFFSET
+ sizeof(uint32_t)),
37 "BLOCKSIZE is too big");
39 /* The maximum size of any signature supported by current and future
40 implementations of the signmar program. */
41 #define MAX_SIGNATURE_LENGTH 2048
43 /* Each additional block has a unique ID.
44 The product information block has an ID of 1. */
45 #define PRODUCT_INFO_BLOCK_ID 1
47 #define MAR_ITEM_SIZE(namelen) (3*sizeof(uint32_t) + (namelen) + 1)
49 /* Product Information Block (PIB) constants */
50 #define PIB_MAX_MAR_CHANNEL_ID_SIZE 63
51 #define PIB_MAX_PRODUCT_VERSION_SIZE 31
53 /* The mar program is compiled as a host bin so we don't have access to NSPR at
54 runtime. For that reason we use ntohl, htonl, and define HOST_TO_NETWORK64
55 instead of the NSPR equivalents. */
58 #define ftello _ftelli64
59 #define fseeko _fseeki64
61 #define _FILE_OFFSET_BITS 64
62 #include <netinet/in.h>
68 #define HOST_TO_NETWORK64(x) ( \
69 ((((uint64_t) x) & 0xFF) << 56) | \
70 ((((uint64_t) x) >> 8) & 0xFF) << 48) | \
71 (((((uint64_t) x) >> 16) & 0xFF) << 40) | \
72 (((((uint64_t) x) >> 24) & 0xFF) << 32) | \
73 (((((uint64_t) x) >> 32) & 0xFF) << 24) | \
74 (((((uint64_t) x) >> 40) & 0xFF) << 16) | \
75 (((((uint64_t) x) >> 48) & 0xFF) << 8) | \
76 (((uint64_t) x) >> 56)
77 #define NETWORK_TO_HOST64 HOST_TO_NETWORK64
79 #endif /* MAR_PRIVATE_H__ */