der_copy.c revision 55682
1202719Sgabor/*
2202719Sgabor * Copyright (c) 1997 Kungliga Tekniska H�gskolan
3202719Sgabor * (Royal Institute of Technology, Stockholm, Sweden).
4202719Sgabor * All rights reserved.
5202719Sgabor *
6202719Sgabor * Redistribution and use in source and binary forms, with or without
7202719Sgabor * modification, are permitted provided that the following conditions
8202719Sgabor * are met:
9202719Sgabor *
10202719Sgabor * 1. Redistributions of source code must retain the above copyright
11202719Sgabor *    notice, this list of conditions and the following disclaimer.
12202719Sgabor *
13202719Sgabor * 2. Redistributions in binary form must reproduce the above copyright
14202719Sgabor *    notice, this list of conditions and the following disclaimer in the
15202719Sgabor *    documentation and/or other materials provided with the distribution.
16202719Sgabor *
17202719Sgabor * 3. Neither the name of the Institute nor the names of its contributors
18202719Sgabor *    may be used to endorse or promote products derived from this software
19202719Sgabor *    without specific prior written permission.
20202719Sgabor *
21202719Sgabor * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22202719Sgabor * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23202719Sgabor * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24202719Sgabor * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25202719Sgabor * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26202719Sgabor * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27202719Sgabor * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28202719Sgabor * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29202719Sgabor * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30202719Sgabor * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31202719Sgabor * SUCH DAMAGE.
32202719Sgabor */
33202719Sgabor
34202719Sgabor#include "der_locl.h"
35202719Sgabor
36202719SgaborRCSID("$Id: der_copy.c,v 1.8 1999/12/02 17:05:01 joda Exp $");
37202719Sgabor
38202719Sgaborint
39202719Sgaborcopy_general_string (const general_string *from, general_string *to)
40202719Sgabor{
41202719Sgabor    *to = malloc(strlen(*from) + 1);
42202719Sgabor    if(*to == NULL)
43203498Sdelphij	return ENOMEM;
44202719Sgabor    strcpy(*to, *from);
45202719Sgabor    return 0;
46202719Sgabor}
47202719Sgabor
48202719Sgaborint
49202719Sgaborcopy_octet_string (const octet_string *from, octet_string *to)
50202719Sgabor{
51202719Sgabor    to->length = from->length;
52202719Sgabor    to->data   = malloc(to->length);
53202719Sgabor    if(to->length != 0 && to->data == NULL)
54202719Sgabor	return ENOMEM;
55202719Sgabor    memcpy(to->data, from->data, to->length);
56202719Sgabor    return 0;
57202719Sgabor}
58202719Sgabor