1b528cefcSMark Murray /* 2ae771770SStanislav Sedov * Copyright (c) 1997 - 2006 Kungliga Tekniska Högskolan 3b528cefcSMark Murray * (Royal Institute of Technology, Stockholm, Sweden). 4b528cefcSMark Murray * All rights reserved. 5b528cefcSMark Murray * 6ae771770SStanislav Sedov * Portions Copyright (c) 2009 Apple Inc. All rights reserved. 7ae771770SStanislav Sedov * 8b528cefcSMark Murray * Redistribution and use in source and binary forms, with or without 9b528cefcSMark Murray * modification, are permitted provided that the following conditions 10b528cefcSMark Murray * are met: 11b528cefcSMark Murray * 12b528cefcSMark Murray * 1. Redistributions of source code must retain the above copyright 13b528cefcSMark Murray * notice, this list of conditions and the following disclaimer. 14b528cefcSMark Murray * 15b528cefcSMark Murray * 2. Redistributions in binary form must reproduce the above copyright 16b528cefcSMark Murray * notice, this list of conditions and the following disclaimer in the 17b528cefcSMark Murray * documentation and/or other materials provided with the distribution. 18b528cefcSMark Murray * 19b528cefcSMark Murray * 3. Neither the name of the Institute nor the names of its contributors 20b528cefcSMark Murray * may be used to endorse or promote products derived from this software 21b528cefcSMark Murray * without specific prior written permission. 22b528cefcSMark Murray * 23b528cefcSMark Murray * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 24b528cefcSMark Murray * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25b528cefcSMark Murray * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26b528cefcSMark Murray * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 27b528cefcSMark Murray * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28b528cefcSMark Murray * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29b528cefcSMark Murray * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30b528cefcSMark Murray * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31b528cefcSMark Murray * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32b528cefcSMark Murray * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33b528cefcSMark Murray * SUCH DAMAGE. 34b528cefcSMark Murray */ 35b528cefcSMark Murray 36b528cefcSMark Murray #include "der_locl.h" 37b528cefcSMark Murray 38ae771770SStanislav Sedov RCSID("$Id$"); 39b528cefcSMark Murray 40b528cefcSMark Murray int 41c19800e8SDoug Rabson der_copy_general_string (const heim_general_string *from, 42c19800e8SDoug Rabson heim_general_string *to) 43b528cefcSMark Murray { 44bbd80c28SJacques Vidrine *to = strdup(*from); 45b528cefcSMark Murray if(*to == NULL) 46b528cefcSMark Murray return ENOMEM; 47b528cefcSMark Murray return 0; 48b528cefcSMark Murray } 49b528cefcSMark Murray 50b528cefcSMark Murray int 51ae771770SStanislav Sedov der_copy_integer (const int *from, int *to) 52ae771770SStanislav Sedov { 53ae771770SStanislav Sedov *to = *from; 54ae771770SStanislav Sedov return 0; 55ae771770SStanislav Sedov } 56ae771770SStanislav Sedov 57ae771770SStanislav Sedov int 58ae771770SStanislav Sedov der_copy_unsigned (const unsigned *from, unsigned *to) 59ae771770SStanislav Sedov { 60ae771770SStanislav Sedov *to = *from; 61ae771770SStanislav Sedov return 0; 62ae771770SStanislav Sedov } 63ae771770SStanislav Sedov 64ae771770SStanislav Sedov int 65ae771770SStanislav Sedov der_copy_generalized_time (const time_t *from, time_t *to) 66ae771770SStanislav Sedov { 67ae771770SStanislav Sedov *to = *from; 68ae771770SStanislav Sedov return 0; 69ae771770SStanislav Sedov } 70ae771770SStanislav Sedov 71ae771770SStanislav Sedov int 72ae771770SStanislav Sedov der_copy_utctime (const time_t *from, time_t *to) 73ae771770SStanislav Sedov { 74ae771770SStanislav Sedov *to = *from; 75ae771770SStanislav Sedov return 0; 76ae771770SStanislav Sedov } 77ae771770SStanislav Sedov 78ae771770SStanislav Sedov int 79c19800e8SDoug Rabson der_copy_utf8string (const heim_utf8_string *from, heim_utf8_string *to) 80c19800e8SDoug Rabson { 81c19800e8SDoug Rabson return der_copy_general_string(from, to); 82c19800e8SDoug Rabson } 83c19800e8SDoug Rabson 84c19800e8SDoug Rabson int 85c19800e8SDoug Rabson der_copy_printable_string (const heim_printable_string *from, 86c19800e8SDoug Rabson heim_printable_string *to) 87c19800e8SDoug Rabson { 88ae771770SStanislav Sedov to->length = from->length; 89ae771770SStanislav Sedov to->data = malloc(to->length + 1); 90ae771770SStanislav Sedov if(to->data == NULL) 91ae771770SStanislav Sedov return ENOMEM; 92ae771770SStanislav Sedov memcpy(to->data, from->data, to->length); 93ae771770SStanislav Sedov ((char *)to->data)[to->length] = '\0'; 94ae771770SStanislav Sedov return 0; 95c19800e8SDoug Rabson } 96c19800e8SDoug Rabson 97c19800e8SDoug Rabson int 98ae771770SStanislav Sedov der_copy_ia5_string (const heim_ia5_string *from, 99ae771770SStanislav Sedov heim_ia5_string *to) 100c19800e8SDoug Rabson { 101ae771770SStanislav Sedov return der_copy_printable_string(from, to); 102c19800e8SDoug Rabson } 103c19800e8SDoug Rabson 104c19800e8SDoug Rabson int 105c19800e8SDoug Rabson der_copy_bmp_string (const heim_bmp_string *from, heim_bmp_string *to) 106c19800e8SDoug Rabson { 107c19800e8SDoug Rabson to->length = from->length; 108c19800e8SDoug Rabson to->data = malloc(to->length * sizeof(to->data[0])); 109c19800e8SDoug Rabson if(to->length != 0 && to->data == NULL) 110c19800e8SDoug Rabson return ENOMEM; 111c19800e8SDoug Rabson memcpy(to->data, from->data, to->length * sizeof(to->data[0])); 112c19800e8SDoug Rabson return 0; 113c19800e8SDoug Rabson } 114c19800e8SDoug Rabson 115c19800e8SDoug Rabson int 116c19800e8SDoug Rabson der_copy_universal_string (const heim_universal_string *from, 117c19800e8SDoug Rabson heim_universal_string *to) 118c19800e8SDoug Rabson { 119c19800e8SDoug Rabson to->length = from->length; 120c19800e8SDoug Rabson to->data = malloc(to->length * sizeof(to->data[0])); 121c19800e8SDoug Rabson if(to->length != 0 && to->data == NULL) 122c19800e8SDoug Rabson return ENOMEM; 123c19800e8SDoug Rabson memcpy(to->data, from->data, to->length * sizeof(to->data[0])); 124c19800e8SDoug Rabson return 0; 125c19800e8SDoug Rabson } 126c19800e8SDoug Rabson 127c19800e8SDoug Rabson int 128c19800e8SDoug Rabson der_copy_visible_string (const heim_visible_string *from, 129c19800e8SDoug Rabson heim_visible_string *to) 130c19800e8SDoug Rabson { 131c19800e8SDoug Rabson return der_copy_general_string(from, to); 132c19800e8SDoug Rabson } 133c19800e8SDoug Rabson 134c19800e8SDoug Rabson int 135c19800e8SDoug Rabson der_copy_octet_string (const heim_octet_string *from, heim_octet_string *to) 136b528cefcSMark Murray { 137b528cefcSMark Murray to->length = from->length; 138*ed549cb0SCy Schubert if (from->data == NULL) { 139*ed549cb0SCy Schubert to->data = NULL; 140*ed549cb0SCy Schubert return 0; 141*ed549cb0SCy Schubert } 142b528cefcSMark Murray to->data = malloc(to->length); 143b528cefcSMark Murray if (to->length != 0 && to->data == NULL) 144b528cefcSMark Murray return ENOMEM; 145b528cefcSMark Murray memcpy(to->data, from->data, to->length); 146b528cefcSMark Murray return 0; 147b528cefcSMark Murray } 1484137ff4cSJacques Vidrine 1494137ff4cSJacques Vidrine int 150c19800e8SDoug Rabson der_copy_heim_integer (const heim_integer *from, heim_integer *to) 151c19800e8SDoug Rabson { 152c19800e8SDoug Rabson to->length = from->length; 153c19800e8SDoug Rabson to->data = malloc(to->length); 154c19800e8SDoug Rabson if(to->length != 0 && to->data == NULL) 155c19800e8SDoug Rabson return ENOMEM; 156c19800e8SDoug Rabson memcpy(to->data, from->data, to->length); 157c19800e8SDoug Rabson to->negative = from->negative; 158c19800e8SDoug Rabson return 0; 159c19800e8SDoug Rabson } 160c19800e8SDoug Rabson 161c19800e8SDoug Rabson int 162c19800e8SDoug Rabson der_copy_oid (const heim_oid *from, heim_oid *to) 1634137ff4cSJacques Vidrine { 1644137ff4cSJacques Vidrine to->length = from->length; 1654137ff4cSJacques Vidrine to->components = malloc(to->length * sizeof(*to->components)); 1664137ff4cSJacques Vidrine if (to->length != 0 && to->components == NULL) 1674137ff4cSJacques Vidrine return ENOMEM; 168c19800e8SDoug Rabson memcpy(to->components, from->components, 169c19800e8SDoug Rabson to->length * sizeof(*to->components)); 170c19800e8SDoug Rabson return 0; 171c19800e8SDoug Rabson } 172c19800e8SDoug Rabson 173c19800e8SDoug Rabson int 174c19800e8SDoug Rabson der_copy_bit_string (const heim_bit_string *from, heim_bit_string *to) 175c19800e8SDoug Rabson { 176c19800e8SDoug Rabson size_t len; 177c19800e8SDoug Rabson 178c19800e8SDoug Rabson len = (from->length + 7) / 8; 179c19800e8SDoug Rabson to->length = from->length; 180c19800e8SDoug Rabson to->data = malloc(len); 181c19800e8SDoug Rabson if(len != 0 && to->data == NULL) 182c19800e8SDoug Rabson return ENOMEM; 183c19800e8SDoug Rabson memcpy(to->data, from->data, len); 1844137ff4cSJacques Vidrine return 0; 1854137ff4cSJacques Vidrine } 186