pem_common.h
Go to the documentation of this file.
1 /**
2  * @file pem_common.h
3  * @brief PEM common definitions
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2025 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneCRYPTO Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.5.2
29  **/
30 
31 #ifndef _PEM_COMMON_H
32 #define _PEM_COMMON_H
33 
34 //Dependencies
35 #include "core/crypto.h"
36 
37 //C++ guard
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 
43 /**
44  * @brief String representation
45  **/
46 
47 typedef struct
48 {
49  const char_t *value;
50  size_t length;
51 } PemString;
52 
53 
54 /**
55  * @brief "Proc-Type" header field
56  **/
57 
58 typedef struct
59 {
62 } PemProcType;
63 
64 
65 /**
66  * @brief "DEK-Info" header field
67  **/
68 
69 typedef struct
70 {
73 } PemDekInfo;
74 
75 
76 /**
77  * @brief PEM encapsulated header
78  **/
79 
80 typedef struct
81 {
84 } PemHeader;
85 
86 
87 //PEM related functions
88 error_t pemDecodeFile(const char_t *input, size_t inputLen, const char_t *label,
89  uint8_t *output, size_t *outputLen, PemHeader *header, size_t *consumed);
90 
91 error_t pemEncodeFile(const void *input, size_t inputLen, const char_t *label,
92  char_t *output, size_t *outputLen);
93 
94 error_t pemParseHeader(const char_t *input, size_t inputLen,
95  PemHeader *header, size_t *consumed);
96 
97 void pemParseHeaderField(PemString *line, PemHeader *header);
98 
99 int_t pemFindTag(const char_t *input, size_t inputLen, const char_t *tag1,
100  const char_t *tag2, const char_t *tag3);
101 
103 bool_t pemCompareString(const PemString *string, const char_t *value);
106 
107 //C++ guard
108 #ifdef __cplusplus
109 }
110 #endif
111 
112 #endif
String representation.
Definition: pem_common.h:48
"DEK-Info" header field
Definition: pem_common.h:70
int bool_t
Definition: compiler_port.h:61
bool_t pemTokenizeString(PemString *s, char_t c, PemString *token)
Split a string into tokens.
Definition: pem_common.c:460
signed int int_t
Definition: compiler_port.h:56
bool_t pemCompareString(const PemString *string, const char_t *value)
Compare a string against the supplied value.
Definition: pem_common.c:422
void pemTrimWhitespace(PemString *s)
Removes all leading and trailing whitespace from a string.
Definition: pem_common.c:511
PEM encapsulated header.
Definition: pem_common.h:81
PemString version
Definition: pem_common.h:60
error_t
Error codes.
Definition: error.h:43
"Proc-Type" header field
Definition: pem_common.h:59
PemDekInfo dekInfo
Definition: pem_common.h:83
int_t pemFindChar(const PemString *s, char_t c)
Search a string for a given character.
Definition: pem_common.c:392
General definitions for cryptographic algorithms.
PemString iv
Definition: pem_common.h:72
error_t pemDecodeFile(const char_t *input, size_t inputLen, const char_t *label, uint8_t *output, size_t *outputLen, PemHeader *header, size_t *consumed)
Convert PEM container to ASN.1 format.
Definition: pem_common.c:58
PemString type
Definition: pem_common.h:61
error_t pemParseHeader(const char_t *input, size_t inputLen, PemHeader *header, size_t *consumed)
Parse PEM encapsulated header.
Definition: pem_common.c:189
PemString algo
Definition: pem_common.h:71
char char_t
Definition: compiler_port.h:55
int_t pemFindTag(const char_t *input, size_t inputLen, const char_t *tag1, const char_t *tag2, const char_t *tag3)
Search a string for a given tag.
Definition: pem_common.c:331
error_t pemEncodeFile(const void *input, size_t inputLen, const char_t *label, char_t *output, size_t *outputLen)
Convert ASN.1 data to PEM encoding.
Definition: pem_common.c:122
size_t length
Definition: pem_common.h:50
void pemParseHeaderField(PemString *line, PemHeader *header)
Parse header field.
Definition: pem_common.c:259
uint8_t value[]
Definition: tcp.h:376
const char_t * value
Definition: pem_common.h:49
uint8_t s
Definition: igmp_common.h:234
PemProcType procType
Definition: pem_common.h:82
uint8_t c
Definition: ndp.h:514
uint8_t token[]
Definition: coap_common.h:181