1bbd80c28SJacques Vidrine /* 2*ae771770SStanislav Sedov * Copyright (c) 1999 - 2005 Kungliga Tekniska Högskolan 3bbd80c28SJacques Vidrine * (Royal Institute of Technology, Stockholm, Sweden). 4bbd80c28SJacques Vidrine * All rights reserved. 5bbd80c28SJacques Vidrine * 6*ae771770SStanislav Sedov * Portions Copyright (c) 2009 Apple Inc. All rights reserved. 7*ae771770SStanislav Sedov * 8bbd80c28SJacques Vidrine * Redistribution and use in source and binary forms, with or without 9bbd80c28SJacques Vidrine * modification, are permitted provided that the following conditions 10bbd80c28SJacques Vidrine * are met: 11bbd80c28SJacques Vidrine * 12bbd80c28SJacques Vidrine * 1. Redistributions of source code must retain the above copyright 13bbd80c28SJacques Vidrine * notice, this list of conditions and the following disclaimer. 14bbd80c28SJacques Vidrine * 15bbd80c28SJacques Vidrine * 2. Redistributions in binary form must reproduce the above copyright 16bbd80c28SJacques Vidrine * notice, this list of conditions and the following disclaimer in the 17bbd80c28SJacques Vidrine * documentation and/or other materials provided with the distribution. 18bbd80c28SJacques Vidrine * 19bbd80c28SJacques Vidrine * 3. Neither the name of the Institute nor the names of its contributors 20bbd80c28SJacques Vidrine * may be used to endorse or promote products derived from this software 21bbd80c28SJacques Vidrine * without specific prior written permission. 22bbd80c28SJacques Vidrine * 23bbd80c28SJacques Vidrine * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 24bbd80c28SJacques Vidrine * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25bbd80c28SJacques Vidrine * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26bbd80c28SJacques Vidrine * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 27bbd80c28SJacques Vidrine * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28bbd80c28SJacques Vidrine * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29bbd80c28SJacques Vidrine * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30bbd80c28SJacques Vidrine * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31bbd80c28SJacques Vidrine * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32bbd80c28SJacques Vidrine * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33bbd80c28SJacques Vidrine * SUCH DAMAGE. 34bbd80c28SJacques Vidrine */ 35bbd80c28SJacques Vidrine 36bbd80c28SJacques Vidrine struct test_case { 37bbd80c28SJacques Vidrine void *val; 38bbd80c28SJacques Vidrine int byte_len; 39c19800e8SDoug Rabson const char *bytes; 40bbd80c28SJacques Vidrine char *name; 41bbd80c28SJacques Vidrine }; 42bbd80c28SJacques Vidrine 43*ae771770SStanislav Sedov typedef int (ASN1CALL *generic_encode)(unsigned char *, size_t, void *, size_t *); 44*ae771770SStanislav Sedov typedef int (ASN1CALL *generic_length)(void *); 45*ae771770SStanislav Sedov typedef int (ASN1CALL *generic_decode)(unsigned char *, size_t, void *, size_t *); 46*ae771770SStanislav Sedov typedef int (ASN1CALL *generic_free)(void *); 47*ae771770SStanislav Sedov typedef int (ASN1CALL *generic_copy)(const void *, void *); 48bbd80c28SJacques Vidrine 49bbd80c28SJacques Vidrine int 50bbd80c28SJacques Vidrine generic_test (const struct test_case *tests, 51bbd80c28SJacques Vidrine unsigned ntests, 52bbd80c28SJacques Vidrine size_t data_size, 53*ae771770SStanislav Sedov int (ASN1CALL *encode)(unsigned char *, size_t, void *, size_t *), 54*ae771770SStanislav Sedov int (ASN1CALL *length)(void *), 55*ae771770SStanislav Sedov int (ASN1CALL *decode)(unsigned char *, size_t, void *, size_t *), 56*ae771770SStanislav Sedov int (ASN1CALL *free_data)(void *), 57*ae771770SStanislav Sedov int (*cmp)(void *a, void *b), 58*ae771770SStanislav Sedov int (ASN1CALL *copy)(const void *a, void *b)); 59bbd80c28SJacques Vidrine 60c19800e8SDoug Rabson int 61c19800e8SDoug Rabson generic_decode_fail(const struct test_case *tests, 62c19800e8SDoug Rabson unsigned ntests, 63c19800e8SDoug Rabson size_t data_size, 64*ae771770SStanislav Sedov int (ASN1CALL *decode)(unsigned char *, size_t, void *, size_t *)); 65c19800e8SDoug Rabson 66c19800e8SDoug Rabson 67c19800e8SDoug Rabson struct map_page; 68c19800e8SDoug Rabson 69c19800e8SDoug Rabson enum map_type { OVERRUN, UNDERRUN }; 70c19800e8SDoug Rabson 71c19800e8SDoug Rabson struct map_page; 72c19800e8SDoug Rabson 73c19800e8SDoug Rabson void * map_alloc(enum map_type, const void *, size_t, struct map_page **); 74c19800e8SDoug Rabson void map_free(struct map_page *, const char *, const char *); 75