|
gsasl
1.7.6
|
00001 /* xcode.c --- Encode and decode application payload in libgsasl session. 00002 * Copyright (C) 2002-2012 Simon Josefsson 00003 * 00004 * This file is part of GNU SASL Library. 00005 * 00006 * GNU SASL Library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public License 00008 * as published by the Free Software Foundation; either version 2.1 of 00009 * the License, or (at your option) any later version. 00010 * 00011 * GNU SASL Library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License License along with GNU SASL Library; if not, write to the 00018 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 * Boston, MA 02110-1301, USA. 00020 * 00021 */ 00022 00023 #include "internal.h" 00024 00025 static int 00026 _gsasl_code (Gsasl_session * sctx, 00027 Gsasl_code_function code, 00028 const char *input, size_t input_len, 00029 char **output, size_t * output_len) 00030 { 00031 00032 if (code == NULL) 00033 { 00034 *output_len = input_len; 00035 *output = malloc (*output_len); 00036 if (!*output) 00037 return GSASL_MALLOC_ERROR; 00038 00039 memcpy (*output, input, input_len); 00040 return GSASL_OK; 00041 } 00042 00043 return code (sctx, sctx->mech_data, input, input_len, output, output_len); 00044 } 00045 00063 int 00064 gsasl_encode (Gsasl_session * sctx, 00065 const char *input, size_t input_len, 00066 char **output, size_t * output_len) 00067 { 00068 Gsasl_code_function code; 00069 00070 if (sctx->clientp) 00071 code = sctx->mech->client.encode; 00072 else 00073 code = sctx->mech->server.encode; 00074 00075 return _gsasl_code (sctx, code, input, input_len, output, output_len); 00076 } 00077 00095 int 00096 gsasl_decode (Gsasl_session * sctx, 00097 const char *input, size_t input_len, 00098 char **output, size_t * output_len) 00099 { 00100 Gsasl_code_function code; 00101 00102 if (sctx->clientp) 00103 code = sctx->mech->client.decode; 00104 else 00105 code = sctx->mech->server.decode; 00106 00107 return _gsasl_code (sctx, code, input, input_len, output, output_len); 00108 }
1.7.6.1