type_check.h revision b6d070c5081ba0ca11545eb50870817d6d72d926
1edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * All rights reserved. 3edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * 4edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * This package is an SSL implementation written 5edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * by Eric Young (eay@cryptsoft.com). 6edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * The implementation was written so as to conform with Netscapes SSL. 7edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * 8edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * This library is free for commercial and non-commercial use as long as 9edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * the following conditions are aheared to. The following conditions 10edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * apply to all code found in this distribution, be it the RC4, RSA, 11edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * included with this distribution is covered by the same copyright terms 13edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * 15edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * Copyright remains Eric Young's, and as such any Copyright notices in 16edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * the code are not to be removed. 17edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * If this package is used in a product, Eric Young should be given attribution 18edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * as the author of the parts of the library used. 19edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * This can be in the form of a textual message at program startup or 20edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * in documentation (online or textual) provided with the package. 21edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * 22076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian * Redistribution and use in source and binary forms, with or without 23edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * modification, are permitted provided that the following conditions 24edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * are met: 25edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * 1. Redistributions of source code must retain the copyright 26edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * notice, this list of conditions and the following disclaimer. 27edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * 2. Redistributions in binary form must reproduce the above copyright 283330b203039dea366d4981db1408a460134b2d2cMathias Agopian * notice, this list of conditions and the following disclaimer in the 29edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * documentation and/or other materials provided with the distribution. 309cce325fae8adcf7560a28eef394489f09bad74dMathias Agopian * 3. All advertising materials mentioning features or use of this software 319cce325fae8adcf7560a28eef394489f09bad74dMathias Agopian * must display the following acknowledgement: 32edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * "This product includes cryptographic software written by 33edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * Eric Young (eay@cryptsoft.com)" 341f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian * The word 'cryptographic' can be left out if the rouines from the library 35edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * being used are not cryptographic related :-). 36edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * 4. If you include any Windows specific code (or a derivative thereof) from 37edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * the apps directory (application code) you must include an acknowledgement: 38a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * 40edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 44edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 45edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 46ca99fb8f65f3ea249c56fb6dccefffb54e87696eMathias Agopian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 47ca99fb8f65f3ea249c56fb6dccefffb54e87696eMathias Agopian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 48ca99fb8f65f3ea249c56fb6dccefffb54e87696eMathias Agopian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49ca99fb8f65f3ea249c56fb6dccefffb54e87696eMathias Agopian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * SUCH DAMAGE. 51edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * 5296f0819f81293076e652792794a961543e6750d7Mathias Agopian * The licence and distribution terms for any publically available version or 5396f0819f81293076e652792794a961543e6750d7Mathias Agopian * derivative of this code cannot be changed. i.e. this code cannot simply be 5496f0819f81293076e652792794a961543e6750d7Mathias Agopian * copied and put under another distribution licence 551f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian * [including the GNU Public Licence.] */ 56401c257fba770a267f637184b1f532b4e03bed20Mathias Agopian 57d606de6bb6877dc4ab93ec0be0c6bda4a8ee1ce8Mathias Agopian#ifndef OPENSSL_HEADER_TYPE_CHECK_H 58b7e930db175c192464cebdeb49eb56cf6dd60114Mathias Agopian#define OPENSSL_HEADER_TYPE_CHECK_H 5916f0453fee84c6aad59fe0d1c7d36f061d46cffcGlenn Kasten 6016f0453fee84c6aad59fe0d1c7d36f061d46cffcGlenn Kasten#include <openssl/base.h> 611f7bec634f19c123410a5155c8d282e177c01930Mathias Agopian 62a138f89c5e78b7e8994823e97d6e860869762837Mathias Agopian#if defined(__cplusplus) 63733189d408e13b54fd70971b265244367efd0f51Mathias Agopianextern "C" { 64edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#endif 65edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project 66edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project 67edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project/* This header file contains some common macros for enforcing type checking. 68edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * Several, common OpenSSL structures (i.e. stack and lhash) operate on void 69bb641244d7d73312dc65b8e338df18b22e335107Mathias Agopian * pointers, but we wish to have type checking when they are used with a 70bb641244d7d73312dc65b8e338df18b22e335107Mathias Agopian * specific type. */ 71bb641244d7d73312dc65b8e338df18b22e335107Mathias Agopian 72bb641244d7d73312dc65b8e338df18b22e335107Mathias Agopian/* CHECKED_CAST casts |p| from type |from| to type |to|. */ 73b7e930db175c192464cebdeb49eb56cf6dd60114Mathias Agopian#define CHECKED_CAST(to, from, p) ((to) (1 ? (p) : (from)0)) 74b7e930db175c192464cebdeb49eb56cf6dd60114Mathias Agopian 75b7e930db175c192464cebdeb49eb56cf6dd60114Mathias Agopian/* CHECKED_PTR_OF casts a given pointer to void* and statically checks that it 76b7e930db175c192464cebdeb49eb56cf6dd60114Mathias Agopian * was a pointer to |type|. */ 77b7e930db175c192464cebdeb49eb56cf6dd60114Mathias Agopian#define CHECKED_PTR_OF(type, p) CHECKED_CAST(void*, type*, (p)) 78b7e930db175c192464cebdeb49eb56cf6dd60114Mathias Agopian 79d606de6bb6877dc4ab93ec0be0c6bda4a8ee1ce8Mathias Agopian#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L 80d606de6bb6877dc4ab93ec0be0c6bda4a8ee1ce8Mathias Agopian#define OPENSSL_COMPILE_ASSERT(cond, msg) _Static_assert(cond, #msg) 81b7e930db175c192464cebdeb49eb56cf6dd60114Mathias Agopian#else 82b7e930db175c192464cebdeb49eb56cf6dd60114Mathias Agopian#define OPENSSL_COMPILE_ASSERT(cond, msg) \ 8396f0819f81293076e652792794a961543e6750d7Mathias Agopian typedef char OPENSSL_COMPILE_ASSERT_##msg[((cond) ? 1 : -1)] OPENSSL_UNUSED 84579b3f88d03d06b897b778bd11818f5104677d1dMathias Agopian#endif 85b7e930db175c192464cebdeb49eb56cf6dd60114Mathias Agopian 86b7e930db175c192464cebdeb49eb56cf6dd60114Mathias Agopian 8796f0819f81293076e652792794a961543e6750d7Mathias Agopian#if defined(__cplusplus) 88579b3f88d03d06b897b778bd11818f5104677d1dMathias Agopian} /* extern C */ 89dd17b3eaa99f761e265ff457e335b5a0ff83dafbMathias Agopian#endif 90dd17b3eaa99f761e265ff457e335b5a0ff83dafbMathias Agopian 91dd17b3eaa99f761e265ff457e335b5a0ff83dafbMathias Agopian#endif /* OPENSSL_HEADER_TYPE_CHECK_H */ 92dd17b3eaa99f761e265ff457e335b5a0ff83dafbMathias Agopian