1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/modules/libmar/src/mar_private.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,79 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim:set ts=2 sw=2 sts=2 et cindent: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef MAR_PRIVATE_H__ 1.11 +#define MAR_PRIVATE_H__ 1.12 + 1.13 +#include "limits.h" 1.14 +#include "mozilla/Assertions.h" 1.15 +#include <stdint.h> 1.16 + 1.17 +#define BLOCKSIZE 4096 1.18 +#define ROUND_UP(n, incr) (((n) / (incr) + 1) * (incr)) 1.19 + 1.20 +#define MAR_ID "MAR1" 1.21 +#define MAR_ID_SIZE 4 1.22 + 1.23 +/* The signature block comes directly after the header block 1.24 + which is 16 bytes */ 1.25 +#define SIGNATURE_BLOCK_OFFSET 16 1.26 + 1.27 +/* Make sure the file is less than 500MB. We do this to protect against 1.28 + invalid MAR files. */ 1.29 +#define MAX_SIZE_OF_MAR_FILE ((int64_t)524288000) 1.30 + 1.31 +/* Existing code makes assumptions that the file size is 1.32 + smaller than LONG_MAX. */ 1.33 +MOZ_STATIC_ASSERT(MAX_SIZE_OF_MAR_FILE < ((int64_t)LONG_MAX), 1.34 + "max mar file size is too big"); 1.35 + 1.36 +/* We store at most the size up to the signature block + 4 1.37 + bytes per BLOCKSIZE bytes */ 1.38 +MOZ_STATIC_ASSERT(sizeof(BLOCKSIZE) < \ 1.39 + (SIGNATURE_BLOCK_OFFSET + sizeof(uint32_t)), 1.40 + "BLOCKSIZE is too big"); 1.41 + 1.42 +/* The maximum size of any signature supported by current and future 1.43 + implementations of the signmar program. */ 1.44 +#define MAX_SIGNATURE_LENGTH 2048 1.45 + 1.46 +/* Each additional block has a unique ID. 1.47 + The product information block has an ID of 1. */ 1.48 +#define PRODUCT_INFO_BLOCK_ID 1 1.49 + 1.50 +#define MAR_ITEM_SIZE(namelen) (3*sizeof(uint32_t) + (namelen) + 1) 1.51 + 1.52 +/* Product Information Block (PIB) constants */ 1.53 +#define PIB_MAX_MAR_CHANNEL_ID_SIZE 63 1.54 +#define PIB_MAX_PRODUCT_VERSION_SIZE 31 1.55 + 1.56 +/* The mar program is compiled as a host bin so we don't have access to NSPR at 1.57 + runtime. For that reason we use ntohl, htonl, and define HOST_TO_NETWORK64 1.58 + instead of the NSPR equivalents. */ 1.59 +#ifdef XP_WIN 1.60 +#include <winsock2.h> 1.61 +#define ftello _ftelli64 1.62 +#define fseeko _fseeki64 1.63 +#else 1.64 +#define _FILE_OFFSET_BITS 64 1.65 +#include <netinet/in.h> 1.66 +#include <unistd.h> 1.67 +#endif 1.68 + 1.69 +#include <stdio.h> 1.70 + 1.71 +#define HOST_TO_NETWORK64(x) ( \ 1.72 + ((((uint64_t) x) & 0xFF) << 56) | \ 1.73 + ((((uint64_t) x) >> 8) & 0xFF) << 48) | \ 1.74 + (((((uint64_t) x) >> 16) & 0xFF) << 40) | \ 1.75 + (((((uint64_t) x) >> 24) & 0xFF) << 32) | \ 1.76 + (((((uint64_t) x) >> 32) & 0xFF) << 24) | \ 1.77 + (((((uint64_t) x) >> 40) & 0xFF) << 16) | \ 1.78 + (((((uint64_t) x) >> 48) & 0xFF) << 8) | \ 1.79 + (((uint64_t) x) >> 56) 1.80 +#define NETWORK_TO_HOST64 HOST_TO_NETWORK64 1.81 + 1.82 +#endif /* MAR_PRIVATE_H__ */