EVE 1.0
base64.h
Go to the documentation of this file.
1 #ifndef EVE_BASE64_H_INCLUDED
2 #define EVE_BASE64_H_INCLUDED
3 
4 /**********************************************************************/
5 /*
6  * Copyright (c) 2014-2015, Jetro AS
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without modification,
10  * are permitted provided that the following conditions are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  * 3. The name of the author may not be used to endorse or promote products
18  * derived from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONRIBUTORS ``AS IS'' AND ANY EXPRESS
21  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
23  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
25  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
28  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
29  * OF SUCH DAMAGE.
30  *
31  * This file is part of the EVE platform.
32  */
33 
34  /**
35  * \file
36  * \brief Header file for the EVE base64 encoder / decoder
37  *
38  * \author DT, Jetro AS
39  */ /******************************************************************/
40 
41 /**
42  * \defgroup base64 base64 encoder/decoder
43  * \ingroup security
44  * @{
45  */
46 
47 /**********************************************************************/
48 /** Static initializer of the base64 decoder structure */
49 #define BASE64_DEC_INIT {.step = 0,}
50 
51 /**********************************************************************/
52 /** Static initializer of the base64 encoder structure */
53 #define BASE64_ENC_INIT {.step = 0,}
54 
55 /**********************************************************************/
56 /** base64 encoder/decoder return codes */
58  BASE64_STATE_IDLE, /**< No output was produced */
59  BASE64_STATE_RDY, /**< A one byte output was produced, available as encoded[0] or decoded */
60  BASE64_STATE_ERROR, /**< An error occured */
61  BASE64_STATE_RDY2, /**< Two bytes output was produced, available as encoded[1], encoded[0] */
62 };
63 
64 /**********************************************************************/
65 /** base6464 decoder state */
67  uint8_t decoded; /**< Contains decoded character */
68  uint8_t pfix; /**< Internally used by the decoder */
69  uint8_t step; /**< Internally used by the decoder */
70  uint8_t user; /**< Not used, available for calling code */
71 };
72 
73 /**********************************************************************/
74 /** base6464 encoder state */
76  uint8_t encoded[2]; /**< Contains encoded characters */
77  uint8_t step; /**< nternally used by the encoder */
78  uint8_t user; /**< Not used, available for calling code */
79 };
80 
81 /**********************************************************************/
82 /**
83  * Initializes the base64 decoder structure.
84  *
85  * \param s pointer to the base64 decoder structure
86  */
87 void base64_dec_init(struct base64_dec_state_t *s);
88 
89 /**********************************************************************/
90 /**
91  * Feeds the decoder with a single character.
92  *
93  * \param s pointer to the base64 decoder structure
94  * \param ch the character to be fed to the decoder
95  * \return BASE64_STATE_IDLE when the character was accepted, but no output was produced
96  * \return BASE64_STATE_ERROR when the character was not accepted
97  * \return BASE64_STATE_RDY whan the character was accepted and one byte of decoded data was produced
98  */
99 enum base64_rc_t base64_dec(struct base64_dec_state_t *s, uint8_t ch);
100 
101 /**********************************************************************/
102 /**
103  * Initializes the base64 encoder structure.
104  *
105  * \param s pointer to the base64 encoder structure
106  */
107 void base64_enc_init(struct base64_enc_state_t *s);
108 
109 /**********************************************************************/
110 /**
111  * Feeds the encoder with a single character.
112  *
113  * \param s pointer to the base64 encoder structure
114  * \param ch the character to be fed to the encoder
115  * \return BASE64_STATE_ERROR when the character was not accepted
116  * \return BASE64_STATE_RDY whan the character was accepted and one byte of encoded data was set in encoded[0]
117  * \return BASE64_STATE_RDY2 whan the character was accepted and two bytes of encoded data were set in encoded[1], encoded[0]
118  */
119 enum base64_rc_t base64_enc(struct base64_enc_state_t *s, uint8_t ch);
120 
121 /**********************************************************************/
122 /**
123  * Tells the encoder about end of input data.
124  *
125  * \param s pointer to the base64 encoder structure
126  * \return BASE64_STATE_IDLE when no additional data bytes were produced
127  * \return BASE64_STATE_RDY whan one byte of encoded data was set in encoded[0]
128  * \return BASE64_STATE_RDY2 whan two bytes of encoded data were set in encoded[1], encoded[0]
129  */
131 
132 /** @} */ /* base64 */
133 
134 #endif /* EVE_BASE64_H_INCLUDED */
void base64_dec_init(struct base64_dec_state_t *s)
uint8_t user
Definition: base64.h:70
base64_rc_t
Definition: base64.h:57
void base64_enc_init(struct base64_enc_state_t *s)
uint8_t step
Definition: base64.h:77
enum base64_rc_t base64_dec(struct base64_dec_state_t *s, uint8_t ch)
enum base64_rc_t base64_enc(struct base64_enc_state_t *s, uint8_t ch)
enum base64_rc_t base64_enc_eof(struct base64_enc_state_t *s)
uint8_t pfix
Definition: base64.h:68
uint8_t user
Definition: base64.h:78
uint8_t step
Definition: base64.h:69
uint8_t decoded
Definition: base64.h:67