gsasl  1.10.0
About: GNU SASL is an implementation of the Simple Authentication and Security Layer (SASL). Development version.
  Fossies Dox: gsasl-1.10.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

xcode.c
Go to the documentation of this file.
1 /* xcode.c --- Encode and decode application payload in libgsasl session.
2  * Copyright (C) 2002-2021 Simon Josefsson
3  *
4  * This file is part of GNU SASL Library.
5  *
6  * GNU SASL Library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License
8  * as published by the Free Software Foundation; either version 2.1 of
9  * the License, or (at your option) any later version.
10  *
11  * GNU SASL Library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License License along with GNU SASL Library; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include "internal.h"
24 
25 static int
28  const char *input, size_t input_len,
29  char **output, size_t *output_len)
30 {
31 
32  if (code == NULL)
33  {
34  *output_len = input_len;
35  *output = malloc (*output_len);
36  if (!*output)
37  return GSASL_MALLOC_ERROR;
38 
39  memcpy (*output, input, input_len);
40  return GSASL_OK;
41  }
42 
43  return code (sctx, sctx->mech_data, input, input_len, output, output_len);
44 }
45 
46 /**
47  * gsasl_encode:
48  * @sctx: libgsasl session handle.
49  * @input: input byte array.
50  * @input_len: size of input byte array.
51  * @output: newly allocated output byte array.
52  * @output_len: size of output byte array.
53  *
54  * Encode data according to negotiated SASL mechanism. This might mean
55  * that data is integrity or privacy protected.
56  *
57  * The @output buffer is allocated by this function, and it is the
58  * responsibility of caller to deallocate it by calling free(@output).
59  *
60  * Return value: Returns %GSASL_OK if encoding was successful,
61  * otherwise an error code.
62  **/
63 int
65  const char *input, size_t input_len,
66  char **output, size_t *output_len)
67 {
69 
70  if (sctx->clientp)
71  code = sctx->mech->client.encode;
72  else
73  code = sctx->mech->server.encode;
74 
75  return _gsasl_code (sctx, code, input, input_len, output, output_len);
76 }
77 
78 /**
79  * gsasl_decode:
80  * @sctx: libgsasl session handle.
81  * @input: input byte array.
82  * @input_len: size of input byte array.
83  * @output: newly allocated output byte array.
84  * @output_len: size of output byte array.
85  *
86  * Decode data according to negotiated SASL mechanism. This might mean
87  * that data is integrity or privacy protected.
88  *
89  * The @output buffer is allocated by this function, and it is the
90  * responsibility of caller to deallocate it by calling free(@output).
91  *
92  * Return value: Returns %GSASL_OK if encoding was successful,
93  * otherwise an error code.
94  **/
95 int
97  const char *input, size_t input_len,
98  char **output, size_t *output_len)
99 {
101 
102  if (sctx->clientp)
103  code = sctx->mech->client.decode;
104  else
105  code = sctx->mech->server.decode;
106 
107  return _gsasl_code (sctx, code, input, input_len, output, output_len);
108 }
int code
Definition: gai_strerror.c:52
#define NULL
Definition: stddef.in.h:72
int(* Gsasl_code_function)(Gsasl_session *sctx, void *mech_data, const char *input, size_t input_len, char **output, size_t *output_len)
Definition: gsasl-mech.h:34
@ GSASL_OK
Definition: gsasl.h:171
@ GSASL_MALLOC_ERROR
Definition: gsasl.h:175
Gsasl_code_function encode
Definition: gsasl-mech.h:46
Gsasl_code_function decode
Definition: gsasl-mech.h:47
struct Gsasl_mechanism_functions server
Definition: gsasl-mech.h:57
struct Gsasl_mechanism_functions client
Definition: gsasl-mech.h:56
void * mech_data
Definition: internal.h:83
Gsasl_mechanism * mech
Definition: internal.h:82
int gsasl_decode(Gsasl_session *sctx, const char *input, size_t input_len, char **output, size_t *output_len)
Definition: xcode.c:96
static int _gsasl_code(Gsasl_session *sctx, Gsasl_code_function code, const char *input, size_t input_len, char **output, size_t *output_len)
Definition: xcode.c:26
int gsasl_encode(Gsasl_session *sctx, const char *input, size_t input_len, char **output, size_t *output_len)
Definition: xcode.c:64