xref: /titanic_41/usr/src/lib/gss_mechs/mech_krb5/krb5/asn.1/krb5_encode.c (revision ba7b222e36bac28710a7f43739283302b617e7f5)
1 /* -*- mode: c; indent-tabs-mode: nil -*- */
2 /*
3  * src/lib/krb5/asn.1/krb5_encode.c
4  *
5  * Copyright 1994, 2008 by the Massachusetts Institute of Technology.
6  * All Rights Reserved.
7  *
8  * Export of this software from the United States of America may
9  *   require a specific license from the United States Government.
10  *   It is the responsibility of any person or organization contemplating
11  *   export to obtain such a license before exporting.
12  *
13  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
14  * distribute this software and its documentation for any purpose and
15  * without fee is hereby granted, provided that the above copyright
16  * notice appear in all copies and that both that copyright notice and
17  * this permission notice appear in supporting documentation, and that
18  * the name of M.I.T. not be used in advertising or publicity pertaining
19  * to distribution of the software without specific, written prior
20  * permission.  Furthermore if you modify this software you must label
21  * your software as modified software and not distribute it in such a
22  * fashion that it might be confused with the original M.I.T. software.
23  * M.I.T. makes no representations about the suitability of
24  * this software for any purpose.  It is provided "as is" without express
25  * or implied warranty.
26  */
27 
28 #include "k5-int.h"
29 #include "asn1_k_encode.h"
30 #include "asn1_encode.h"
31 #include "krbasn1.h"
32 #include "asn1buf.h"
33 #include "asn1_make.h"
34 
35 /**************** Macros (these save a lot of typing) ****************/
36 
37 /* setup() -- create and initialize bookkeeping variables
38      retval: stores error codes returned from subroutines
39      buf: the coding buffer
40      length: length of the most-recently produced encoding
41      sum: cumulative length of the entire encoding */
42 #define krb5_setup()\
43   asn1_error_code retval;\
44   unsigned int length, sum = 0;\
45   asn1buf *buf=NULL;\
46   krb5_data *tmpcode;\
47 \
48   *code = NULL;\
49 \
50   if (rep == NULL) return ASN1_MISSING_FIELD;\
51 \
52   retval = asn1buf_create(&buf);\
53   if (retval) return retval
54 
55 /* produce the final output and clean up the workspace */
56 #define krb5_cleanup()\
57   retval = asn12krb5_buf(buf,&tmpcode);\
58 error:\
59   asn1buf_destroy(&buf);\
60   if (retval)\
61     return retval;\
62   *code = tmpcode;\
63   return 0
64 
65 #ifndef DISABLE_PKINIT
encode_krb5_pa_pk_as_req(const krb5_pa_pk_as_req * rep,krb5_data ** code)66 krb5_error_code encode_krb5_pa_pk_as_req(const krb5_pa_pk_as_req *rep, krb5_data **code)
67 {
68     krb5_setup();
69     retval = asn1_encode_pa_pk_as_req(buf,rep,&length);
70     if (retval) goto error;
71     sum += length;
72     krb5_cleanup();
73 }
74 
encode_krb5_pa_pk_as_req_draft9(const krb5_pa_pk_as_req_draft9 * rep,krb5_data ** code)75 krb5_error_code encode_krb5_pa_pk_as_req_draft9(const krb5_pa_pk_as_req_draft9 *rep, krb5_data **code)
76 {
77     krb5_setup();
78     retval = asn1_encode_pa_pk_as_req_draft9(buf,rep,&length);
79     if (retval) goto error;
80     sum += length;
81     krb5_cleanup();
82 }
83 
encode_krb5_pa_pk_as_rep(const krb5_pa_pk_as_rep * rep,krb5_data ** code)84 krb5_error_code encode_krb5_pa_pk_as_rep(const krb5_pa_pk_as_rep *rep, krb5_data **code)
85 {
86     krb5_setup();
87     retval = asn1_encode_pa_pk_as_rep(buf,rep,&length);
88     if (retval) goto error;
89     sum += length;
90     krb5_cleanup();
91 }
92 
encode_krb5_pa_pk_as_rep_draft9(const krb5_pa_pk_as_rep_draft9 * rep,krb5_data ** code)93 krb5_error_code encode_krb5_pa_pk_as_rep_draft9(const krb5_pa_pk_as_rep_draft9 *rep, krb5_data **code)
94 {
95     krb5_setup();
96     retval = asn1_encode_pa_pk_as_rep_draft9(buf,rep,&length);
97     if (retval) goto error;
98     sum += length;
99     krb5_cleanup();
100 }
101 
encode_krb5_auth_pack(const krb5_auth_pack * rep,krb5_data ** code)102 krb5_error_code encode_krb5_auth_pack(const krb5_auth_pack *rep, krb5_data **code)
103 {
104     krb5_setup();
105     retval = asn1_encode_auth_pack(buf,rep,&length);
106     if (retval) goto error;
107     sum += length;
108     krb5_cleanup();
109 }
110 
encode_krb5_auth_pack_draft9(const krb5_auth_pack_draft9 * rep,krb5_data ** code)111 krb5_error_code encode_krb5_auth_pack_draft9(const krb5_auth_pack_draft9 *rep, krb5_data **code)
112 {
113     krb5_setup();
114     retval = asn1_encode_auth_pack_draft9(buf,rep,&length);
115     if (retval) goto error;
116     sum += length;
117     krb5_cleanup();
118 }
119 
encode_krb5_kdc_dh_key_info(const krb5_kdc_dh_key_info * rep,krb5_data ** code)120 krb5_error_code encode_krb5_kdc_dh_key_info(const krb5_kdc_dh_key_info *rep, krb5_data **code)
121 {
122     krb5_setup();
123     retval = asn1_encode_kdc_dh_key_info(buf,rep,&length);
124     if (retval) goto error;
125     sum += length;
126     krb5_cleanup();
127 }
128 
encode_krb5_reply_key_pack(const krb5_reply_key_pack * rep,krb5_data ** code)129 krb5_error_code encode_krb5_reply_key_pack(const krb5_reply_key_pack *rep, krb5_data **code)
130 {
131     krb5_setup();
132     retval = asn1_encode_reply_key_pack(buf,rep,&length);
133     if (retval) goto error;
134     sum += length;
135     krb5_cleanup();
136 }
137 
encode_krb5_reply_key_pack_draft9(const krb5_reply_key_pack_draft9 * rep,krb5_data ** code)138 krb5_error_code encode_krb5_reply_key_pack_draft9(const krb5_reply_key_pack_draft9 *rep, krb5_data **code)
139 {
140     krb5_setup();
141     retval = asn1_encode_reply_key_pack_draft9(buf,rep,&length);
142     if (retval) goto error;
143     sum += length;
144     krb5_cleanup();
145 }
146 
encode_krb5_td_trusted_certifiers(const krb5_external_principal_identifier ** rep,krb5_data ** code)147 krb5_error_code encode_krb5_td_trusted_certifiers(const krb5_external_principal_identifier **rep, krb5_data **code)
148 {
149     krb5_setup();
150     retval = asn1_encode_td_trusted_certifiers(buf,rep,&length);
151     if (retval) goto error;
152     sum += length;
153     krb5_cleanup();
154 }
155 
encode_krb5_td_dh_parameters(const krb5_algorithm_identifier ** rep,krb5_data ** code)156 krb5_error_code encode_krb5_td_dh_parameters(const krb5_algorithm_identifier **rep, krb5_data **code)
157 {
158     krb5_setup();
159     retval = asn1_encode_sequence_of_algorithm_identifier(buf,rep,&length);
160     if (retval) goto error;
161     sum += length;
162     krb5_cleanup();
163 }
164 #endif /* DISABLE_PKINIT */
165 
encode_krb5_typed_data(const krb5_typed_data ** rep,krb5_data ** code)166 krb5_error_code encode_krb5_typed_data(const krb5_typed_data **rep, krb5_data **code)
167 {
168     krb5_setup();
169     retval = asn1_encode_sequence_of_typed_data(buf,rep,&length);
170     if (retval) goto error;
171     sum += length;
172     krb5_cleanup();
173 }
174 
175