pem_common.c File Reference

PEM common definitions. More...

#include "core/crypto.h"
#include "pkix/pem_common.h"
#include "encoding/oid.h"
#include "encoding/base64.h"
#include "cipher/cipher_algorithms.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL
 

Functions

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. More...
 
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. More...
 
error_t pemParseHeader (const char_t *input, size_t inputLen, PemHeader *header, size_t *consumed)
 Parse PEM encapsulated header. More...
 
void pemParseHeaderField (PemString *line, PemHeader *header)
 Parse header field. More...
 
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. More...
 
int_t pemFindChar (const PemString *s, char_t c)
 Search a string for a given character. More...
 
bool_t pemCompareString (const PemString *string, const char_t *value)
 Compare a string against the supplied value. More...
 
bool_t pemTokenizeString (PemString *s, char_t c, PemString *token)
 Split a string into tokens. More...
 
void pemTrimWhitespace (PemString *s)
 Removes all leading and trailing whitespace from a string. More...
 
const CipherAlgopemGetCipherAlgo (const PemString *algo)
 Get the cipher algorithm to be used for PEM encryption/decryption. More...
 
uint_t pemGetKeyLength (const PemString *algo)
 Get the encryption key length to be used for PEM encryption/decryption. More...
 

Detailed Description

PEM common definitions.

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneCRYPTO Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.4.0

Definition in file pem_common.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL

Definition at line 32 of file pem_common.c.

Function Documentation

◆ pemCompareString()

bool_t pemCompareString ( const PemString string,
const char_t value 
)

Compare a string against the supplied value.

Parameters
[in]stringString to be compared
[in]valueNULL-terminated string
Returns
Comparison result

Definition at line 414 of file pem_common.c.

◆ pemDecodeFile()

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.

Parameters
[in]inputPEM container to decode
[in]inputLenLength of the PEM container to decode
[in]labelLabel indicating the type of data
[out]outputASN.1 data (optional parameter)
[out]outputLenLength of the ASN.1 data
[out]headerPEM encapsulated header (optional parameter)
[out]consumedTotal number of characters that have been consumed (optional parameter)

Definition at line 58 of file pem_common.c.

◆ pemEncodeFile()

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.

Parameters
[in]inputASN.1 data to encode
[in]inputLenLength of the ASN.1 data to encode
[in]labelLabel indicating the type of data
[out]outputPEM container (optional parameter)
[out]outputLenLength of the PEM container

Definition at line 118 of file pem_common.c.

◆ pemFindChar()

int_t pemFindChar ( const PemString s,
char_t  c 
)

Search a string for a given character.

Parameters
[in]sString to be scanned
[in]cCharacter to be searched
Returns
Index of the first occurrence of the character

Definition at line 384 of file pem_common.c.

◆ pemFindTag()

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.

Parameters
[in]inputString to search
[in]inputLenLength of the string to search
[in]tag1First part of the tag (NULL-terminated string)
[in]tag2Second part of the tag (NULL-terminated string)
[in]tag3Third part of the tag (NULL-terminated string)
Returns
The index of the first occurrence of the tag in the string, or -1 if the tag does not appear in the string

Definition at line 323 of file pem_common.c.

◆ pemGetCipherAlgo()

const CipherAlgo* pemGetCipherAlgo ( const PemString algo)

Get the cipher algorithm to be used for PEM encryption/decryption.

Parameters
[in]algoEncryption algorithm
Returns
Cipher algorithm

Definition at line 526 of file pem_common.c.

◆ pemGetKeyLength()

uint_t pemGetKeyLength ( const PemString algo)

Get the encryption key length to be used for PEM encryption/decryption.

Parameters
[in]algoEncryption algorithm
Returns
Encryption key length

Definition at line 624 of file pem_common.c.

◆ pemParseHeader()

error_t pemParseHeader ( const char_t input,
size_t  inputLen,
PemHeader header,
size_t *  consumed 
)

Parse PEM encapsulated header.

Parameters
[in]inputPEM message body
[in]inputLenLength of the PEM message body
[in]headerPEM encapsulated header (optional parameter)
[out]consumedTotal number of bytes that have been consumed
Returns
Error code

Definition at line 181 of file pem_common.c.

◆ pemParseHeaderField()

void pemParseHeaderField ( PemString line,
PemHeader header 
)

Parse header field.

Parameters
[in]lineHeader field
[in]headerPEM encapsulated header (optional parameter)

Definition at line 251 of file pem_common.c.

◆ pemTokenizeString()

bool_t pemTokenizeString ( PemString s,
char_t  c,
PemString token 
)

Split a string into tokens.

Parameters
[in,out]sString to be split
[in]cDelimiter character
[out]tokenResulting token
Returns
TRUE if a token has been found, else FALSE

Definition at line 452 of file pem_common.c.

◆ pemTrimWhitespace()

void pemTrimWhitespace ( PemString s)

Removes all leading and trailing whitespace from a string.

Parameters
[in]sString to be trimmed

Definition at line 503 of file pem_common.c.