EVE 1.0
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
asn1.h
Go to the documentation of this file.
1
#ifndef EVE_ASN1_H_INCLUDED
2
#define EVE_ASN1_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 ASN.1 decoder
37
*
38
* \author DT, Jetro AS
39
*/
/******************************************************************/
40
41
/**
42
* \defgroup asn1 ASN.1 decoder
43
* \ingroup security
44
* \{
45
*
46
* EVE ASN.1 decoder
47
*/
48
49
/**********************************************************************/
50
/** Search for a SEQUENCE in ASN.1 data */
51
#define ASN1_SEQUENCE (0x30)
52
53
/**********************************************************************/
54
/** Search for a INTEGER in the ASN.1 data */
55
#define ASN1_INTEGER (0x02)
56
57
/**********************************************************************/
58
/** Encodes length of the integer */
59
#define ASN1_LENGTH(x) ((uint8_t)((x) >> 0)), ((uint8_t)((x) >> 8)), ((uint8_t)((x) >> 16)), ((uint8_t)((x) >> 24))
60
61
/**********************************************************************/
62
/** ASN.1 decoder return codes */
63
enum
asn1_rc_t
{
64
ASN1_STATE_IDLE
,
/**< Processing of the ASN.1 data was not finished yet */
65
ASN1_STATE_RDY
,
/**< Processing of the ASN.1 data was finished according to template */
66
ASN1_STATE_ERROR
,
/**< The ASN.1 data or template is not valid */
67
};
68
69
/**********************************************************************/
70
/** ASN.1 decoder state type, used internally by the decoder */
71
enum
asn1_state_t
{
72
ASN1_DECODER_STATE_TYPE,
73
ASN1_DECODER_STATE_LENGTH,
74
ASN1_DECODER_STATE_VALUE,
75
ASN1_DECODER_STATE_TOTAL_LENGTH,
76
};
77
78
/**********************************************************************/
79
/** ASN.1 decoder state */
80
struct
asn1_dec_state_t
{
81
enum
asn1_state_t
state
;
/**< Internal decoder state */
82
uint32_t
tpl_off
;
/**< Current offset in the template */
83
uint32_t
tot_size
;
/**< Total size of the ASN.1 data block */
84
uint32_t
size
;
/**< Size of the current field of the ASN.1 data block */
85
uint32_t
acc
;
/**< Internal decoder variable */
86
uint32_t
result_idx
;
/**< Current offset in the result array */
87
uint32_t
offset
;
/**< Offset in the ASN.1 data block */
88
};
89
90
/**********************************************************************/
91
/** ASN.1 result descriptor */
92
struct
asn1_result_t
{
93
void
*
value
;
/**< Pointer to the buffer for the variable */
94
uint32_t
size
;
/**< Size of the variable as obtained from the ASN.1 data block */
95
};
96
97
/**********************************************************************/
98
/**
99
* Initializes the ASN.1 decoder structure.
100
*
101
* \param s pointer to the ASN.1 decoder structure
102
*/
103
void
asn1_dec_init
(
struct
asn1_dec_state_t
*s);
104
105
/**********************************************************************/
106
/**
107
* Feeds the encoder with a single character.
108
*
109
* \param s pointer to the base64 encoder structure
110
* \param tplt parsing template, zero-terminated string of ASN1_XXX macroes
111
* \param result parsing result desctiptors, an array of asn1_result_t elements
112
* \param ch the character to be fed to the encoder
113
* \return ASN1_STATE_ERROR when the character was not accepted
114
* \return ASN1_STATE_IDLE whan the character was accepted, but the processing was not finished
115
* \return ASN1_STATE_RDY whan the character was accepted and result is available in the result array
116
*/
117
enum
asn1_rc_t
asn1_dec
(
118
struct
asn1_dec_state_t
*s,
119
const
uint8_t *tplt,
120
struct
asn1_result_t
*result,
121
uint8_t ch);
122
123
/** @} */
/* asn1 */
124
125
#endif
/* EVE_ASN1_H_INCLUDED */
asn1_result_t::value
void * value
Definition:
asn1.h:93
asn1_state_t
asn1_state_t
Definition:
asn1.h:71
asn1_dec_state_t::tpl_off
uint32_t tpl_off
Definition:
asn1.h:82
ASN1_STATE_IDLE
Definition:
asn1.h:64
asn1_dec_state_t
Definition:
asn1.h:80
asn1_dec_state_t::acc
uint32_t acc
Definition:
asn1.h:85
asn1_dec_state_t::offset
uint32_t offset
Definition:
asn1.h:87
asn1_dec_state_t::tot_size
uint32_t tot_size
Definition:
asn1.h:83
asn1_result_t
Definition:
asn1.h:92
asn1_dec
enum asn1_rc_t asn1_dec(struct asn1_dec_state_t *s, const uint8_t *tplt, struct asn1_result_t *result, uint8_t ch)
asn1_dec_init
void asn1_dec_init(struct asn1_dec_state_t *s)
asn1_rc_t
asn1_rc_t
Definition:
asn1.h:63
asn1_dec_state_t::size
uint32_t size
Definition:
asn1.h:84
asn1_dec_state_t::result_idx
uint32_t result_idx
Definition:
asn1.h:86
ASN1_STATE_RDY
Definition:
asn1.h:65
asn1_dec_state_t::state
enum asn1_state_t state
Definition:
asn1.h:81
asn1_result_t::size
uint32_t size
Definition:
asn1.h:94
ASN1_STATE_ERROR
Definition:
asn1.h:66
Core
Include
lib
asn1.h
Generated on Thu Mar 30 2017 10:16:56 for EVE 1.0 by
1.8.11