mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-03-24 19:43:32 +00:00
Add accessor to get buf from mbedtls_pem_context
Co-authored-by: Gilles Peskine <gilles.peskine@arm.com> Signed-off-by: Glenn Strauss <gstrauss@gluelogic.com>
This commit is contained in:
parent
6a0b1ef27e
commit
72bd4e4d6a
2
ChangeLog.d/mbedtls_pem_get_der.txt
Normal file
2
ChangeLog.d/mbedtls_pem_get_der.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
Features
|
||||||
|
* Add accessor to get the raw buffer pointer from a PEM context.
|
@ -27,6 +27,11 @@
|
|||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
|
||||||
|
!defined(inline) && !defined(__cplusplus)
|
||||||
|
#define inline __inline
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \name PEM Error codes
|
* \name PEM Error codes
|
||||||
* These error codes are returned in case of errors reading the
|
* These error codes are returned in case of errors reading the
|
||||||
@ -96,6 +101,10 @@ void mbedtls_pem_init( mbedtls_pem_context *ctx );
|
|||||||
* the decrypted text starts with an ASN.1 sequence of
|
* the decrypted text starts with an ASN.1 sequence of
|
||||||
* appropriate length
|
* appropriate length
|
||||||
*
|
*
|
||||||
|
* \note \c mbedtls_pem_free must be called on PEM context before
|
||||||
|
* the PEM context can be reused in another call to
|
||||||
|
* \c mbedtls_pem_read_buffer
|
||||||
|
*
|
||||||
* \return 0 on success, or a specific PEM error code
|
* \return 0 on success, or a specific PEM error code
|
||||||
*/
|
*/
|
||||||
int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const char *footer,
|
int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const char *footer,
|
||||||
@ -103,6 +112,25 @@ int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const
|
|||||||
const unsigned char *pwd,
|
const unsigned char *pwd,
|
||||||
size_t pwdlen, size_t *use_len );
|
size_t pwdlen, size_t *use_len );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Get the pointer to the decoded binary data in a PEM context.
|
||||||
|
*
|
||||||
|
* \param ctx PEM context to access.
|
||||||
|
* \param buflen On success, this will contain the length of the binary data.
|
||||||
|
* This must be a valid (non-null) pointer.
|
||||||
|
*
|
||||||
|
* \return A pointer to the decoded binary data.
|
||||||
|
*
|
||||||
|
* \note The returned pointer remains valid only until \p ctx is
|
||||||
|
modified or freed.
|
||||||
|
*/
|
||||||
|
static inline const unsigned char *mbedtls_pem_get_buffer( mbedtls_pem_context *ctx, size_t *buflen )
|
||||||
|
{
|
||||||
|
*buflen = ctx->MBEDTLS_PRIVATE(buflen);
|
||||||
|
return( ctx->MBEDTLS_PRIVATE(buf) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief PEM context memory freeing
|
* \brief PEM context memory freeing
|
||||||
*
|
*
|
||||||
|
@ -40,12 +40,21 @@ void mbedtls_pem_read_buffer( char *header, char *footer, char *data,
|
|||||||
int ret;
|
int ret;
|
||||||
size_t use_len = 0;
|
size_t use_len = 0;
|
||||||
size_t pwd_len = strlen( pwd );
|
size_t pwd_len = strlen( pwd );
|
||||||
|
const unsigned char *buf;
|
||||||
|
|
||||||
mbedtls_pem_init( &ctx );
|
mbedtls_pem_init( &ctx );
|
||||||
|
|
||||||
ret = mbedtls_pem_read_buffer( &ctx, header, footer, (unsigned char *)data,
|
ret = mbedtls_pem_read_buffer( &ctx, header, footer, (unsigned char *)data,
|
||||||
(unsigned char *)pwd, pwd_len, &use_len );
|
(unsigned char *)pwd, pwd_len, &use_len );
|
||||||
TEST_ASSERT( ret == res );
|
TEST_ASSERT( ret == res );
|
||||||
|
if( ret != 0 )
|
||||||
|
goto exit;
|
||||||
|
|
||||||
|
TEST_EQUAL( use_len, ctx.buflen );
|
||||||
|
use_len = 0;
|
||||||
|
buf = mbedtls_pem_get_buffer( &ctx, &use_len );
|
||||||
|
TEST_ASSERT( buf == ctx.buf );
|
||||||
|
TEST_EQUAL( use_len, ctx.buflen );
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
mbedtls_pem_free( &ctx );
|
mbedtls_pem_free( &ctx );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user