summaryrefslogtreecommitdiffstats
path: root/src/lib/krb5/asn.1/decode.c
blob: bc6db5b3ca6ec1e60f0500c318a70211d8d1d794 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
 * $Source$
 * $Author$
 *
 * Copyright 1990 by the Massachusetts Institute of Technology.
 *
 * For copying and distribution information, please see the file
 * <krb5/copyright.h>.
 *
 * decoding glue routines.
 */

#if !defined(lint) && !defined(SABER)
static char rcsid_decode_c[] =
"$Id$";
#endif	/* lint || saber */

#include <krb5/copyright.h>
#include <isode/psap.h>
#include <krb5/krb5.h>
#include <krb5/asn1.h>

#include <krb5/ext-proto.h>

#include <stdio.h>

krb5_error_code
krb5_decode_generic(input, output, decoder, translator, free_translation)
const krb5_data *input;
register krb5_pointer *output;
int (*decoder) PROTOTYPE((PE, int, int, char *, krb5_pointer));
krb5_pointer (*translator) PROTOTYPE((krb5_pointer, int * ));
void (*free_translation) PROTOTYPE((krb5_pointer ));
{
    krb5_pointer isode_temp;
    PE pe;
    PS ps;
    krb5_error_code error = 0;

    if (!(ps = ps_alloc(str_open))) {
	return(ENOMEM);
    }
    if (str_setup(ps, input->data, input->length, 1) != OK) {
	error = ps->ps_errno + ISODE_50_PS_ERR_NONE;
	ps_free(ps);
	return(error);
    }
    if (!(pe = ps2pe(ps))) {
	error = ps->ps_errno + ISODE_50_PS_ERR_NONE;
	ps_free(ps);
	return(error);
    }
    if ((*decoder)(pe, 1, 0, 0, &isode_temp) != OK) {
	error = ISODE_50_LOCAL_ERR_BADDECODE;
	pe_free(pe);
	ps_free(ps);
	return(error);
    }
    *output = (*translator)(isode_temp, &error);
    pe_free(pe);
    ps_free(ps);
    free_translation(isode_temp);
    return(error);			/* may be error if output
					   failed above */
}