From: John Kohl Date: Tue, 9 Jan 1990 16:53:32 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: krb5-1.0-alpha2~1298 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=785a3cad2811c3851012e032c0509b83ab4a0051;p=krb5.git *** empty log message *** git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@75 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/include/krb5/asn.1/encode.h b/src/include/krb5/asn.1/encode.h new file mode 100644 index 000000000..f18ef5ebd --- /dev/null +++ b/src/include/krb5/asn.1/encode.h @@ -0,0 +1,44 @@ +/* + * $Source$ + * $Author$ + * $Id$ + * + * Copyright 1990 by the Massachusetts Institute of Technology. + * + * For copying and distribution information, please see the file + * . + * + * #defines for using generic encoder routine. + */ + +#include + +#ifndef __KRB5_ENCODE_DEFS__ +#define __KRB5_ENCODE_DEFS__ + +#define encode_krb5_authenticator(pauth, error) \ + encode_generic(pauth, error, \ + encode_KRB5_Authenticator, \ + krb5_authenticator2KRB5_Authenticator, \ + free_KRB5_Authenticator) +#define decode_krb5_authenticator(pauth, error) \ + (krb5_authenticator *) \ + decode_generic(pauth, error, \ + decode_KRB5_Authenticator, \ + KRB5_Authenticator2krb5_authenticator, \ + free_KRB5_Authenticator) + +#define encode_krb5_ticket(ptick, error) \ + encode_generic(ptick, error, \ + encode_KRB5_Ticket, \ + krb5_ticket2KRB5_Ticket, \ + free_KRB5_Ticket) + +#define decode_krb5_ticket(ptick, error) \ + (krb5_ticket *) \ + decode_generic(ptick, error, \ + decode_KRB5_Ticket, \ + KRB5_Ticket2krb5_ticket, \ + free_KRB5_Ticket) + +#endif /* __KRB5_ENCODE_DEFS__ */ diff --git a/src/lib/krb5/asn.1/encode.c b/src/lib/krb5/asn.1/encode.c new file mode 100644 index 000000000..635da34e6 --- /dev/null +++ b/src/lib/krb5/asn.1/encode.c @@ -0,0 +1,136 @@ +/* + * $Source$ + * $Author$ + * + * Copyright 1990 by the Massachusetts Institute of Technology. + * + * For copying and distribution information, please see the file + * . + * + * encoding glue routines. + */ + +#ifndef lint +static char rcsid_glue3_c[] = +"$Id$"; +#endif lint + +#include +#include +#include "KRB5-types.h" +#include +#include +#include +#include +#include +#include "glue.h" +#include "gluedefs.h" + +#include + +#ifdef __STDC__ +typedef void * pointer; +#else +typedef char * pointer; +#endif + +static char encode_buf[BUFSIZ]; + +krb5_string * +encode_generic(input, error, encoder, translator, free_translation) +pointer input; +int *error; +int (*encoder)(/* PE, int, int, char *, pointer */); +pointer (*translator)(/* pointer, int * */); +void (*free_translation)(/* pointer */); +{ + pointer isode_out; + PE pe; + PS ps; + register krb5_string *retval; + + if (!(isode_out = (*translator)(input, error))) + return(0); + if (!(ps = ps_alloc(str_open))) { + *error = ENOMEM; + free_translation(isode_out); + return(0); + } + if (str_setup(ps, encode_buf, sizeof(encode_buf), 1) != OK) { + *error = ps->ps_errno + ISODE_50_PS_ERR_NONE; + errout: + ps_free(ps); + free_translation(isode_out); + return(0); + } + if ((*encoder)(&pe, 0, 0, 0, isode_out)) { + *error = ENOMEM; + goto errout; + } + retval = (krb5_string *)malloc(sizeof(*retval)); + if (!retval) { + *error = ENOMEM; + goto errout; + } + if ((retval->length = ps_get_abs(pe)) > sizeof(encode_buf)) { + abort(); /* xxx */ + } + retval->string = malloc(ps_get_abs(pe)); + if (!retval->string) { + *error = ENOMEM; + free(retval); + goto errout; + } + if (pe2ps(ps, pe) != OK || ps_flush(ps) != OK) { + *error = ps->ps_errno + ISODE_50_PS_ERR_NONE; + free(retval->string); + free(retval); + goto errout; + } + bcopy(encode_buf, retval->string, retval->length); + ps_free(ps); + pe_free(pe); + free_translation(isode_out); + return(retval); +} + +pointer +decode_generic(input, error, decoder, translator, free_translation) +krb5_string *input; +int *error; +int (*decoder)(/* PE, int, int, char *, pointer */); +pointer (*translator)(/* pointer, int * */); +void (*free_translation)(/* pointer */); +{ + register pointer krb5_out; + pointer isode_temp; + PE pe; + PS ps; + + if (!(ps = ps_alloc(str_open))) { + *error = ENOMEM; + return(0); + } + if (str_setup(ps, input->string, input->length, 1) != OK) { + *error = ps->ps_errno + ISODE_50_PS_ERR_NONE; + ps_free(ps); + return(0); + } + if (!(pe = ps2pe(ps))) { + *error = ps->ps_errno + ISODE_50_PS_ERR_NONE; + ps_free(ps); + return(0); + } + if ((*decoder)(pe, 1, 0, 0, &isode_temp) != OK) { + *error = ISODE_50_LOCAL_ERR_BADDECODE; + pe_free(pe); + ps_free(ps); + return(0); + } + krb5_out = (*translator)(isode_temp, error); + pe_free(pe); + ps_free(ps); + free_translation(isode_temp); + return(krb5_out); /* may be error if krb5_out + failed above */ +}