<commit_before>/**
 * \file x509write.h
 *
 * \brief X509 buffer writing functionality
 *
 *  Copyright (C) 2006-2013, Brainspark B.V.
 *
 *  This file is part of PolarSSL (http://www.polarssl.org)
 *  Lead Maintainer: <NAME> <polarssl_maintainer at polarssl.org>
 *
 *  All rights reserved.
 *
 *  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.
 */
#ifndef POLARSSL_X509_WRITE_H
#define POLARSSL_X509_WRITE_H

#include "config.h"

#include "rsa.h"

#define POLARSSL_ERR_X509WRITE_UNKNOWN_OID                -0x5F80  /**< Requested OID is unknown. */
#define POLARSSL_ERR_X509WRITE_BAD_INPUT_DATA             -0x5F00  /**< Failed to allocate memory. */
#define POLARSSL_ERR_X509WRITE_MALLOC_FAILED              -0x5E80  /**< Failed to allocate memory. */


#ifdef __cplusplus
extern "C" {
#endif

typedef struct _x509_req_name
{
    char oid[128];
    char name[128];

    struct _x509_req_name *next;
}
x509_req_name;

typedef struct _x509_csr
{
    rsa_context *rsa;
    x509_req_name *subject;
    md_type_t md_alg;
}
x509_csr;

void x509write_csr_init( x509_csr *ctx );
int x509write_csr_set_subject_name( x509_csr *ctx, char *subject_name );
void x509write_csr_set_rsa_key( x509_csr *ctx, rsa_context *rsa );
void x509write_csr_set_md_alg( x509_csr *ctx, md_type_t md_alg );
void x509write_csr_free( x509_csr *ctx );

int x509write_pubkey_der( rsa_context *rsa, unsigned char *buf, size_t size );
int x509write_key_der( rsa_context *rsa, unsigned char *buf, size_t size );
int x509write_csr_der( x509_csr *ctx, unsigned char *buf, size_t size );

#ifdef __cplusplus
}
#endif

#endif /* POLARSSL_X509_WRITE_H */<commit_msg>Doxygen documentation added to x509write.h<commit_after>/**
 * \file x509write.h
 *
 * \brief X509 buffer writing functionality
 *
 *  Copyright (C) 2006-2013, Brainspark B.V.
 *
 *  This file is part of PolarSSL (http://www.polarssl.org)
 *  Lead Maintainer: <NAME> <polarssl_maintainer at polarssl.org>
 *
 *  All rights reserved.
 *
 *  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.
 */
#ifndef POLARSSL_X509_WRITE_H
#define POLARSSL_X509_WRITE_H

#include "config.h"

#include "rsa.h"

/**
 * \addtogroup x509_module
 * \{
 */

/**
 * \name X509 Write Error codes
 * \{
 */
#define POLARSSL_ERR_X509WRITE_UNKNOWN_OID                -0x5F80  /**< Requested OID is unknown. */
#define POLARSSL_ERR_X509WRITE_BAD_INPUT_DATA             -0x5F00  /**< Failed to allocate memory. */
#define POLARSSL_ERR_X509WRITE_MALLOC_FAILED              -0x5E80  /**< Failed to allocate memory. */
/* \} name */
/* \} addtogroup x509_module */

#ifdef __cplusplus
extern "C" {
#endif

/**
 * \addtogroup x509_module
 * \{
 */

/**
 * \name Structures for writing X.509 CSRs (Certificate Signing Request) 
 * \{
 */

/**
 * Container for CSR named objects
 */
typedef struct _x509_req_name
{
    char oid[128];
    char name[128];

    struct _x509_req_name *next;
}
x509_req_name;

/**
 * Container for a CSR
 */
typedef struct _x509_csr
{
    rsa_context *rsa;
    x509_req_name *subject;
    md_type_t md_alg;
}
x509_csr;

/* \} addtogroup x509_module */

/**
 * \brief           Initialize a CSR context
 *
 * \param ctx       CSR context to initialize
 */
void x509write_csr_init( x509_csr *ctx );

/**
 * \brief           Set the subject name for a CSR
 *                  Subject names should contain a comma-separated list
 *                  of OID types and values:
 *                  e.g. "C=NL,O=Offspark,CN=PolarSSL Server 1"
 *
 * \param ctx           CSR context to use
 * \param subject_name  subject name to set
 *
 * \return          0 if subject name was parsed successfully, or
 *                  a specific error code
 */
int x509write_csr_set_subject_name( x509_csr *ctx, char *subject_name );

/**
 * \brief           Set the RSA key for a CSR (public key will be included,
 *                  private key used to sign the CSR when writing it)
 *
 * \param ctx       CSR context to use
 * \param rsa       RSA key to include
 */
void x509write_csr_set_rsa_key( x509_csr *ctx, rsa_context *rsa );

/**
 * \brief           Set the MD algorithm to use for the signature
 *                  (e.g. POLARSSL_MD_SHA1)
 *
 * \param ctx       CSR context to use
 * \param md_ald    MD algorithm to use
 */
void x509write_csr_set_md_alg( x509_csr *ctx, md_type_t md_alg );

/**
 * \brief           Free the contents of a CSR context
 *
 * \param ctx       CSR context to free
 */
void x509write_csr_free( x509_csr *ctx );

/**
 * \brief           Write a RSA public key to a PKCS#1 DER structure
 *                  Note: data is written at the end of the buffer! Use the
 *                        return value to determine where you should start
 *                        using the buffer
 *
 * \param rsa       RSA to write away
 * \param buf       buffer to write to
 * \param size      size of the buffer
 *
 * \return          length of data written if successful, or a specific
 *                  error code
 */
int x509write_pubkey_der( rsa_context *rsa, unsigned char *buf, size_t size );

/**
 * \brief           Write a RSA key to a PKCS#1 DER structure
 *                  Note: data is written at the end of the buffer! Use the
 *                        return value to determine where you should start
 *                        using the buffer
 *
 * \param rsa       RSA to write away
 * \param buf       buffer to write to
 * \param size      size of the buffer
 *
 * \return          length of data written if successful, or a specific
 *                  error code
 */
int x509write_key_der( rsa_context *rsa, unsigned char *buf, size_t size );

/**
 * \brief           Write a CSR (Certificate Signing Request) to a
 *                  DER structure
 *                  Note: data is written at the end of the buffer! Use the
 *                        return value to determine where you should start
 *                        using the buffer
 *
 * \param rsa       CSR to write away
 * \param buf       buffer to write to
 * \param size      size of the buffer
 *
 * \return          length of data written if successful, or a specific
 *                  error code
 */
int x509write_csr_der( x509_csr *ctx, unsigned char *buf, size_t size );

#ifdef __cplusplus
}
#endif

#endif /* POLARSSL_X509_WRITE_H */
{'fraction_non_alphanumeric': 0.08106687688871371, 'fraction_numerical': 0.035474970437524636, 'mean_word_length': 2.56868260665729, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2333883', 'n_tokens_mistral': 2627, 'n_tokens_neox': 2382, 'n_words': 870}