2N/A/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2N/A/*
2N/A * src/lib/krb5/asn.1/krb5_encode.c
2N/A *
2N/A * Copyright 1994, 2008 by the Massachusetts Institute of Technology.
2N/A * All Rights Reserved.
2N/A *
2N/A * Export of this software from the United States of America may
2N/A * require a specific license from the United States Government.
2N/A * It is the responsibility of any person or organization contemplating
2N/A * export to obtain such a license before exporting.
2N/A *
2N/A * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
2N/A * distribute this software and its documentation for any purpose and
2N/A * without fee is hereby granted, provided that the above copyright
2N/A * notice appear in all copies and that both that copyright notice and
2N/A * this permission notice appear in supporting documentation, and that
2N/A * the name of M.I.T. not be used in advertising or publicity pertaining
2N/A * to distribution of the software without specific, written prior
2N/A * permission. Furthermore if you modify this software you must label
2N/A * your software as modified software and not distribute it in such a
2N/A * fashion that it might be confused with the original M.I.T. software.
2N/A * M.I.T. makes no representations about the suitability of
2N/A * this software for any purpose. It is provided "as is" without express
2N/A * or implied warranty.
2N/A */
2N/A
2N/A#include "k5-int.h"
2N/A#include "asn1_k_encode.h"
2N/A#include "asn1_encode.h"
2N/A#include "krbasn1.h"
2N/A#include "asn1buf.h"
2N/A#include "asn1_make.h"
2N/A
2N/A/**************** Macros (these save a lot of typing) ****************/
2N/A
2N/A/*
2N/A * setup() -- create and initialize bookkeeping variables
2N/A * retval: stores error codes returned from subroutines
2N/A * buf: the coding buffer
2N/A * length: length of the most-recently produced encoding
2N/A * sum: cumulative length of the entire encoding
2N/A */
2N/A#define krb5_setup() \
2N/A asn1_error_code retval; \
2N/A unsigned int length, sum = 0; \
2N/A asn1buf *buf=NULL; \
2N/A krb5_data *tmpcode; \
2N/A \
2N/A *code = NULL; \
2N/A \
2N/A if (rep == NULL) return ASN1_MISSING_FIELD; \
2N/A \
2N/A retval = asn1buf_create(&buf); \
2N/A if (retval) return retval
2N/A
2N/A/* produce the final output and clean up the workspace */
2N/A#define krb5_cleanup() \
2N/A retval = asn12krb5_buf(buf,&tmpcode); \
2N/Aerror: \
2N/Aasn1buf_destroy(&buf); \
2N/Aif (retval) \
2N/A return retval; \
2N/A*code = tmpcode; \
2N/Areturn 0
2N/A
2N/A#ifndef DISABLE_PKINIT
2N/Akrb5_error_code
2N/Aencode_krb5_pa_pk_as_req(const krb5_pa_pk_as_req *rep, krb5_data **code)
2N/A{
2N/A krb5_setup();
2N/A retval = asn1_encode_pa_pk_as_req(buf,rep,&length);
2N/A if (retval) goto error;
2N/A sum += length;
2N/A krb5_cleanup();
2N/A}
2N/A
2N/Akrb5_error_code
2N/Aencode_krb5_pa_pk_as_req_draft9(const krb5_pa_pk_as_req_draft9 *rep,
2N/A krb5_data **code)
2N/A{
2N/A krb5_setup();
2N/A retval = asn1_encode_pa_pk_as_req_draft9(buf,rep,&length);
2N/A if (retval) goto error;
2N/A sum += length;
2N/A krb5_cleanup();
2N/A}
2N/A
2N/Akrb5_error_code
2N/Aencode_krb5_pa_pk_as_rep(const krb5_pa_pk_as_rep *rep, krb5_data **code)
2N/A{
2N/A krb5_setup();
2N/A retval = asn1_encode_pa_pk_as_rep(buf,rep,&length);
2N/A if (retval) goto error;
2N/A sum += length;
2N/A krb5_cleanup();
2N/A}
2N/A
2N/Akrb5_error_code
2N/Aencode_krb5_pa_pk_as_rep_draft9(const krb5_pa_pk_as_rep_draft9 *rep, krb5_data **code)
2N/A{
2N/A krb5_setup();
2N/A retval = asn1_encode_pa_pk_as_rep_draft9(buf,rep,&length);
2N/A if (retval) goto error;
2N/A sum += length;
2N/A krb5_cleanup();
2N/A}
2N/A
2N/Akrb5_error_code
2N/Aencode_krb5_auth_pack(const krb5_auth_pack *rep, krb5_data **code)
2N/A{
2N/A krb5_setup();
2N/A retval = asn1_encode_auth_pack(buf,rep,&length);
2N/A if (retval) goto error;
2N/A sum += length;
2N/A krb5_cleanup();
2N/A}
2N/A
2N/Akrb5_error_code
2N/Aencode_krb5_auth_pack_draft9(const krb5_auth_pack_draft9 *rep,
2N/A krb5_data **code)
2N/A{
2N/A krb5_setup();
2N/A retval = asn1_encode_auth_pack_draft9(buf,rep,&length);
2N/A if (retval) goto error;
2N/A sum += length;
2N/A krb5_cleanup();
2N/A}
2N/A
2N/Akrb5_error_code
2N/Aencode_krb5_kdc_dh_key_info(const krb5_kdc_dh_key_info *rep, krb5_data **code)
2N/A{
2N/A krb5_setup();
2N/A retval = asn1_encode_kdc_dh_key_info(buf,rep,&length);
2N/A if (retval) goto error;
2N/A sum += length;
2N/A krb5_cleanup();
2N/A}
2N/A
2N/Akrb5_error_code
2N/Aencode_krb5_reply_key_pack(const krb5_reply_key_pack *rep, krb5_data **code)
2N/A{
2N/A krb5_setup();
2N/A retval = asn1_encode_reply_key_pack(buf,rep,&length);
2N/A if (retval) goto error;
2N/A sum += length;
2N/A krb5_cleanup();
2N/A}
2N/A
2N/Akrb5_error_code
2N/Aencode_krb5_reply_key_pack_draft9(const krb5_reply_key_pack_draft9 *rep,
2N/A krb5_data **code)
2N/A{
2N/A krb5_setup();
2N/A retval = asn1_encode_reply_key_pack_draft9(buf,rep,&length);
2N/A if (retval) goto error;
2N/A sum += length;
2N/A krb5_cleanup();
2N/A}
2N/A
2N/Akrb5_error_code
2N/Aencode_krb5_td_trusted_certifiers(
2N/A const krb5_external_principal_identifier **rep, krb5_data **code)
2N/A{
2N/A krb5_setup();
2N/A retval = asn1_encode_td_trusted_certifiers(buf,rep,&length);
2N/A if (retval) goto error;
2N/A sum += length;
2N/A krb5_cleanup();
2N/A}
2N/A
2N/Akrb5_error_code
2N/Aencode_krb5_td_dh_parameters(const krb5_algorithm_identifier **rep,
2N/A krb5_data **code)
2N/A{
2N/A krb5_setup();
2N/A retval = asn1_encode_sequence_of_algorithm_identifier(buf,rep,&length);
2N/A if (retval) goto error;
2N/A sum += length;
2N/A krb5_cleanup();
2N/A}
2N/A#endif /* DISABLE_PKINIT */
2N/A
2N/Akrb5_error_code
2N/Aencode_krb5_typed_data(const krb5_typed_data **rep, krb5_data **code)
2N/A{
2N/A krb5_setup();
2N/A retval = asn1_encode_sequence_of_typed_data(buf,rep,&length);
2N/A if (retval) goto error;
2N/A sum += length;
2N/A krb5_cleanup();
2N/A}