mirror of
				https://github.com/Mbed-TLS/mbedtls.git
				synced 2025-11-03 20:33:16 +03:00 
			
		
		
		
	Adapt x509write_crt.c to coding style
Avoid lines longer than 80 characters and fix indentation.
This commit is contained in:
		@@ -64,22 +64,26 @@ void mbedtls_x509write_crt_free( mbedtls_x509write_cert *ctx )
 | 
				
			|||||||
    mbedtls_platform_zeroize( ctx, sizeof( mbedtls_x509write_cert ) );
 | 
					    mbedtls_platform_zeroize( ctx, sizeof( mbedtls_x509write_cert ) );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void mbedtls_x509write_crt_set_version( mbedtls_x509write_cert *ctx, int version )
 | 
					void mbedtls_x509write_crt_set_version( mbedtls_x509write_cert *ctx,
 | 
				
			||||||
 | 
					                                        int version )
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    ctx->version = version;
 | 
					    ctx->version = version;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void mbedtls_x509write_crt_set_md_alg( mbedtls_x509write_cert *ctx, mbedtls_md_type_t md_alg )
 | 
					void mbedtls_x509write_crt_set_md_alg( mbedtls_x509write_cert *ctx,
 | 
				
			||||||
 | 
					                                       mbedtls_md_type_t md_alg )
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    ctx->md_alg = md_alg;
 | 
					    ctx->md_alg = md_alg;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void mbedtls_x509write_crt_set_subject_key( mbedtls_x509write_cert *ctx, mbedtls_pk_context *key )
 | 
					void mbedtls_x509write_crt_set_subject_key( mbedtls_x509write_cert *ctx,
 | 
				
			||||||
 | 
					                                            mbedtls_pk_context *key )
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    ctx->subject_key = key;
 | 
					    ctx->subject_key = key;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void mbedtls_x509write_crt_set_issuer_key( mbedtls_x509write_cert *ctx, mbedtls_pk_context *key )
 | 
					void mbedtls_x509write_crt_set_issuer_key( mbedtls_x509write_cert *ctx,
 | 
				
			||||||
 | 
					                                           mbedtls_pk_context *key )
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    ctx->issuer_key = key;
 | 
					    ctx->issuer_key = key;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -96,7 +100,8 @@ int mbedtls_x509write_crt_set_issuer_name( mbedtls_x509write_cert *ctx,
 | 
				
			|||||||
    return mbedtls_x509_string_to_names( &ctx->issuer, issuer_name );
 | 
					    return mbedtls_x509_string_to_names( &ctx->issuer, issuer_name );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int mbedtls_x509write_crt_set_serial( mbedtls_x509write_cert *ctx, const mbedtls_mpi *serial )
 | 
					int mbedtls_x509write_crt_set_serial( mbedtls_x509write_cert *ctx,
 | 
				
			||||||
 | 
					                                      const mbedtls_mpi *serial )
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int ret;
 | 
					    int ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -106,7 +111,8 @@ int mbedtls_x509write_crt_set_serial( mbedtls_x509write_cert *ctx, const mbedtls
 | 
				
			|||||||
    return( 0 );
 | 
					    return( 0 );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int mbedtls_x509write_crt_set_validity( mbedtls_x509write_cert *ctx, const char *not_before,
 | 
					int mbedtls_x509write_crt_set_validity( mbedtls_x509write_cert *ctx,
 | 
				
			||||||
 | 
					                                        const char *not_before,
 | 
				
			||||||
                                        const char *not_after )
 | 
					                                        const char *not_after )
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    if( strlen( not_before ) != MBEDTLS_X509_RFC5280_UTC_TIME_LEN - 1 ||
 | 
					    if( strlen( not_before ) != MBEDTLS_X509_RFC5280_UTC_TIME_LEN - 1 ||
 | 
				
			||||||
@@ -127,8 +133,8 @@ int mbedtls_x509write_crt_set_extension( mbedtls_x509write_cert *ctx,
 | 
				
			|||||||
                                 int critical,
 | 
					                                 int critical,
 | 
				
			||||||
                                 const unsigned char *val, size_t val_len )
 | 
					                                 const unsigned char *val, size_t val_len )
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return mbedtls_x509_set_extension( &ctx->extensions, oid, oid_len,
 | 
					    return( mbedtls_x509_set_extension( &ctx->extensions, oid, oid_len,
 | 
				
			||||||
                               critical, val, val_len );
 | 
					                                        critical, val, val_len ) );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int mbedtls_x509write_crt_set_basic_constraints( mbedtls_x509write_cert *ctx,
 | 
					int mbedtls_x509write_crt_set_basic_constraints( mbedtls_x509write_cert *ctx,
 | 
				
			||||||
@@ -148,18 +154,21 @@ int mbedtls_x509write_crt_set_basic_constraints( mbedtls_x509write_cert *ctx,
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        if( max_pathlen >= 0 )
 | 
					        if( max_pathlen >= 0 )
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_int( &c, buf, max_pathlen ) );
 | 
					            MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_int( &c, buf,
 | 
				
			||||||
 | 
					                                                               max_pathlen ) );
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_bool( &c, buf, 1 ) );
 | 
					        MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_bool( &c, buf, 1 ) );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, buf, len ) );
 | 
					    MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, buf, len ) );
 | 
				
			||||||
    MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( &c, buf, MBEDTLS_ASN1_CONSTRUCTED |
 | 
					    MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( &c, buf,
 | 
				
			||||||
 | 
					                                                MBEDTLS_ASN1_CONSTRUCTED |
 | 
				
			||||||
                                                MBEDTLS_ASN1_SEQUENCE ) );
 | 
					                                                MBEDTLS_ASN1_SEQUENCE ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return mbedtls_x509write_crt_set_extension( ctx, MBEDTLS_OID_BASIC_CONSTRAINTS,
 | 
					    return(
 | 
				
			||||||
 | 
					        mbedtls_x509write_crt_set_extension( ctx, MBEDTLS_OID_BASIC_CONSTRAINTS,
 | 
				
			||||||
                             MBEDTLS_OID_SIZE( MBEDTLS_OID_BASIC_CONSTRAINTS ),
 | 
					                             MBEDTLS_OID_SIZE( MBEDTLS_OID_BASIC_CONSTRAINTS ),
 | 
				
			||||||
                                        0, buf + sizeof(buf) - len, len );
 | 
					                             0, buf + sizeof(buf) - len, len ) );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(MBEDTLS_SHA1_C)
 | 
					#if defined(MBEDTLS_SHA1_C)
 | 
				
			||||||
@@ -171,7 +180,8 @@ int mbedtls_x509write_crt_set_subject_key_identifier( mbedtls_x509write_cert *ct
 | 
				
			|||||||
    size_t len = 0;
 | 
					    size_t len = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    memset( buf, 0, sizeof(buf) );
 | 
					    memset( buf, 0, sizeof(buf) );
 | 
				
			||||||
    MBEDTLS_ASN1_CHK_ADD( len, mbedtls_pk_write_pubkey( &c, buf, ctx->subject_key ) );
 | 
					    MBEDTLS_ASN1_CHK_ADD( len,
 | 
				
			||||||
 | 
					                mbedtls_pk_write_pubkey( &c, buf, ctx->subject_key ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ret = mbedtls_sha1_ret( buf + sizeof( buf ) - len, len,
 | 
					    ret = mbedtls_sha1_ret( buf + sizeof( buf ) - len, len,
 | 
				
			||||||
                            buf + sizeof( buf ) - 20 );
 | 
					                            buf + sizeof( buf ) - 20 );
 | 
				
			||||||
@@ -181,9 +191,11 @@ int mbedtls_x509write_crt_set_subject_key_identifier( mbedtls_x509write_cert *ct
 | 
				
			|||||||
    len = 20;
 | 
					    len = 20;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, buf, len ) );
 | 
					    MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, buf, len ) );
 | 
				
			||||||
    MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( &c, buf, MBEDTLS_ASN1_OCTET_STRING ) );
 | 
					    MBEDTLS_ASN1_CHK_ADD( len,
 | 
				
			||||||
 | 
					            mbedtls_asn1_write_tag( &c, buf, MBEDTLS_ASN1_OCTET_STRING ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return mbedtls_x509write_crt_set_extension( ctx, MBEDTLS_OID_SUBJECT_KEY_IDENTIFIER,
 | 
					    return mbedtls_x509write_crt_set_extension( ctx,
 | 
				
			||||||
 | 
					                 MBEDTLS_OID_SUBJECT_KEY_IDENTIFIER,
 | 
				
			||||||
                 MBEDTLS_OID_SIZE( MBEDTLS_OID_SUBJECT_KEY_IDENTIFIER ),
 | 
					                 MBEDTLS_OID_SIZE( MBEDTLS_OID_SUBJECT_KEY_IDENTIFIER ),
 | 
				
			||||||
                 0, buf + sizeof(buf) - len, len );
 | 
					                 0, buf + sizeof(buf) - len, len );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -196,7 +208,8 @@ int mbedtls_x509write_crt_set_authority_key_identifier( mbedtls_x509write_cert *
 | 
				
			|||||||
    size_t len = 0;
 | 
					    size_t len = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    memset( buf, 0, sizeof(buf) );
 | 
					    memset( buf, 0, sizeof(buf) );
 | 
				
			||||||
    MBEDTLS_ASN1_CHK_ADD( len, mbedtls_pk_write_pubkey( &c, buf, ctx->issuer_key ) );
 | 
					    MBEDTLS_ASN1_CHK_ADD( len,
 | 
				
			||||||
 | 
					                          mbedtls_pk_write_pubkey( &c, buf, ctx->issuer_key ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ret = mbedtls_sha1_ret( buf + sizeof( buf ) - len, len,
 | 
					    ret = mbedtls_sha1_ret( buf + sizeof( buf ) - len, len,
 | 
				
			||||||
                            buf + sizeof( buf ) - 20 );
 | 
					                            buf + sizeof( buf ) - 20 );
 | 
				
			||||||
@@ -206,13 +219,17 @@ int mbedtls_x509write_crt_set_authority_key_identifier( mbedtls_x509write_cert *
 | 
				
			|||||||
    len = 20;
 | 
					    len = 20;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, buf, len ) );
 | 
					    MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, buf, len ) );
 | 
				
			||||||
    MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( &c, buf, MBEDTLS_ASN1_CONTEXT_SPECIFIC | 0 ) );
 | 
					    MBEDTLS_ASN1_CHK_ADD( len,
 | 
				
			||||||
 | 
					        mbedtls_asn1_write_tag( &c, buf, MBEDTLS_ASN1_CONTEXT_SPECIFIC | 0 ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, buf, len ) );
 | 
					    MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, buf, len ) );
 | 
				
			||||||
    MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( &c, buf, MBEDTLS_ASN1_CONSTRUCTED |
 | 
					    MBEDTLS_ASN1_CHK_ADD( len,
 | 
				
			||||||
 | 
					                          mbedtls_asn1_write_tag( &c, buf,
 | 
				
			||||||
 | 
					                                                  MBEDTLS_ASN1_CONSTRUCTED |
 | 
				
			||||||
                                                  MBEDTLS_ASN1_SEQUENCE ) );
 | 
					                                                  MBEDTLS_ASN1_SEQUENCE ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return mbedtls_x509write_crt_set_extension( ctx, MBEDTLS_OID_AUTHORITY_KEY_IDENTIFIER,
 | 
					    return mbedtls_x509write_crt_set_extension(
 | 
				
			||||||
 | 
					        ctx, MBEDTLS_OID_AUTHORITY_KEY_IDENTIFIER,
 | 
				
			||||||
        MBEDTLS_OID_SIZE( MBEDTLS_OID_AUTHORITY_KEY_IDENTIFIER ),
 | 
					        MBEDTLS_OID_SIZE( MBEDTLS_OID_AUTHORITY_KEY_IDENTIFIER ),
 | 
				
			||||||
        0, buf + sizeof( buf ) - len, len );
 | 
					        0, buf + sizeof( buf ) - len, len );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -294,7 +311,8 @@ static int x509_write_time( unsigned char **p, unsigned char *start,
 | 
				
			|||||||
                                             (const unsigned char *) t + 2,
 | 
					                                             (const unsigned char *) t + 2,
 | 
				
			||||||
                                             size - 2 ) );
 | 
					                                             size - 2 ) );
 | 
				
			||||||
        MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( p, start, len ) );
 | 
					        MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( p, start, len ) );
 | 
				
			||||||
        MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( p, start, MBEDTLS_ASN1_UTC_TIME ) );
 | 
					        MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( p, start,
 | 
				
			||||||
 | 
					                                             MBEDTLS_ASN1_UTC_TIME ) );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@@ -302,13 +320,15 @@ static int x509_write_time( unsigned char **p, unsigned char *start,
 | 
				
			|||||||
                                                  (const unsigned char *) t,
 | 
					                                                  (const unsigned char *) t,
 | 
				
			||||||
                                                  size ) );
 | 
					                                                  size ) );
 | 
				
			||||||
        MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( p, start, len ) );
 | 
					        MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( p, start, len ) );
 | 
				
			||||||
        MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( p, start, MBEDTLS_ASN1_GENERALIZED_TIME ) );
 | 
					        MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( p, start,
 | 
				
			||||||
 | 
					                                             MBEDTLS_ASN1_GENERALIZED_TIME ) );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return( (int) len );
 | 
					    return( (int) len );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx, unsigned char *buf, size_t size,
 | 
					int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx,
 | 
				
			||||||
 | 
					                               unsigned char *buf, size_t size,
 | 
				
			||||||
                               int (*f_rng)(void *, unsigned char *, size_t),
 | 
					                               int (*f_rng)(void *, unsigned char *, size_t),
 | 
				
			||||||
                               void *p_rng )
 | 
					                               void *p_rng )
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@@ -352,19 +372,26 @@ int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx, unsigned char *buf,
 | 
				
			|||||||
    /* Only for v3 */
 | 
					    /* Only for v3 */
 | 
				
			||||||
    if( ctx->version == MBEDTLS_X509_CRT_VERSION_3 )
 | 
					    if( ctx->version == MBEDTLS_X509_CRT_VERSION_3 )
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        MBEDTLS_ASN1_CHK_ADD( len, mbedtls_x509_write_extensions( &c, tmp_buf, ctx->extensions ) );
 | 
					        MBEDTLS_ASN1_CHK_ADD( len,
 | 
				
			||||||
 | 
					                              mbedtls_x509_write_extensions( &c,
 | 
				
			||||||
 | 
					                                                  tmp_buf, ctx->extensions ) );
 | 
				
			||||||
        MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, tmp_buf, len ) );
 | 
					        MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, tmp_buf, len ) );
 | 
				
			||||||
        MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( &c, tmp_buf, MBEDTLS_ASN1_CONSTRUCTED |
 | 
					        MBEDTLS_ASN1_CHK_ADD( len,
 | 
				
			||||||
 | 
					                              mbedtls_asn1_write_tag( &c, tmp_buf,
 | 
				
			||||||
 | 
					                                                      MBEDTLS_ASN1_CONSTRUCTED |
 | 
				
			||||||
                                                      MBEDTLS_ASN1_SEQUENCE ) );
 | 
					                                                      MBEDTLS_ASN1_SEQUENCE ) );
 | 
				
			||||||
        MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, tmp_buf, len ) );
 | 
					        MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, tmp_buf, len ) );
 | 
				
			||||||
        MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( &c, tmp_buf, MBEDTLS_ASN1_CONTEXT_SPECIFIC |
 | 
					        MBEDTLS_ASN1_CHK_ADD( len,
 | 
				
			||||||
 | 
					                              mbedtls_asn1_write_tag( &c, tmp_buf,
 | 
				
			||||||
 | 
					                                               MBEDTLS_ASN1_CONTEXT_SPECIFIC |
 | 
				
			||||||
                                               MBEDTLS_ASN1_CONSTRUCTED | 3 ) );
 | 
					                                               MBEDTLS_ASN1_CONSTRUCTED | 3 ) );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /*
 | 
					    /*
 | 
				
			||||||
     *  SubjectPublicKeyInfo
 | 
					     *  SubjectPublicKeyInfo
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    MBEDTLS_ASN1_CHK_ADD( pub_len, mbedtls_pk_write_pubkey_der( ctx->subject_key,
 | 
					    MBEDTLS_ASN1_CHK_ADD( pub_len,
 | 
				
			||||||
 | 
					                          mbedtls_pk_write_pubkey_der( ctx->subject_key,
 | 
				
			||||||
                                                       tmp_buf, c - tmp_buf ) );
 | 
					                                                       tmp_buf, c - tmp_buf ) );
 | 
				
			||||||
    c -= pub_len;
 | 
					    c -= pub_len;
 | 
				
			||||||
    len += pub_len;
 | 
					    len += pub_len;
 | 
				
			||||||
@@ -372,7 +399,9 @@ int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx, unsigned char *buf,
 | 
				
			|||||||
    /*
 | 
					    /*
 | 
				
			||||||
     *  Subject  ::=  Name
 | 
					     *  Subject  ::=  Name
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    MBEDTLS_ASN1_CHK_ADD( len, mbedtls_x509_write_names( &c, tmp_buf, ctx->subject ) );
 | 
					    MBEDTLS_ASN1_CHK_ADD( len,
 | 
				
			||||||
 | 
					                          mbedtls_x509_write_names( &c, tmp_buf,
 | 
				
			||||||
 | 
					                                                    ctx->subject ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /*
 | 
					    /*
 | 
				
			||||||
     *  Validity ::= SEQUENCE {
 | 
					     *  Validity ::= SEQUENCE {
 | 
				
			||||||
@@ -381,32 +410,41 @@ int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx, unsigned char *buf,
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    sub_len = 0;
 | 
					    sub_len = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    MBEDTLS_ASN1_CHK_ADD( sub_len, x509_write_time( &c, tmp_buf, ctx->not_after,
 | 
					    MBEDTLS_ASN1_CHK_ADD( sub_len,
 | 
				
			||||||
 | 
					                          x509_write_time( &c, tmp_buf, ctx->not_after,
 | 
				
			||||||
                                        MBEDTLS_X509_RFC5280_UTC_TIME_LEN ) );
 | 
					                                        MBEDTLS_X509_RFC5280_UTC_TIME_LEN ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    MBEDTLS_ASN1_CHK_ADD( sub_len, x509_write_time( &c, tmp_buf, ctx->not_before,
 | 
					    MBEDTLS_ASN1_CHK_ADD( sub_len,
 | 
				
			||||||
 | 
					                          x509_write_time( &c, tmp_buf, ctx->not_before,
 | 
				
			||||||
                                        MBEDTLS_X509_RFC5280_UTC_TIME_LEN ) );
 | 
					                                        MBEDTLS_X509_RFC5280_UTC_TIME_LEN ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    len += sub_len;
 | 
					    len += sub_len;
 | 
				
			||||||
    MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, tmp_buf, sub_len ) );
 | 
					    MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, tmp_buf, sub_len ) );
 | 
				
			||||||
    MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( &c, tmp_buf, MBEDTLS_ASN1_CONSTRUCTED |
 | 
					    MBEDTLS_ASN1_CHK_ADD( len,
 | 
				
			||||||
 | 
					                          mbedtls_asn1_write_tag( &c, tmp_buf,
 | 
				
			||||||
 | 
					                                                  MBEDTLS_ASN1_CONSTRUCTED |
 | 
				
			||||||
                                                  MBEDTLS_ASN1_SEQUENCE ) );
 | 
					                                                  MBEDTLS_ASN1_SEQUENCE ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /*
 | 
					    /*
 | 
				
			||||||
     *  Issuer  ::=  Name
 | 
					     *  Issuer  ::=  Name
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    MBEDTLS_ASN1_CHK_ADD( len, mbedtls_x509_write_names( &c, tmp_buf, ctx->issuer ) );
 | 
					    MBEDTLS_ASN1_CHK_ADD( len, mbedtls_x509_write_names( &c,
 | 
				
			||||||
 | 
					                                                         tmp_buf,
 | 
				
			||||||
 | 
					                                                         ctx->issuer ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /*
 | 
					    /*
 | 
				
			||||||
     *  Signature   ::=  AlgorithmIdentifier
 | 
					     *  Signature   ::=  AlgorithmIdentifier
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_algorithm_identifier( &c, tmp_buf,
 | 
					    MBEDTLS_ASN1_CHK_ADD( len,
 | 
				
			||||||
 | 
					                          mbedtls_asn1_write_algorithm_identifier( &c, tmp_buf,
 | 
				
			||||||
                                              sig_oid, strlen( sig_oid ), 0 ) );
 | 
					                                              sig_oid, strlen( sig_oid ), 0 ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /*
 | 
					    /*
 | 
				
			||||||
     *  Serial   ::=  INTEGER
 | 
					     *  Serial   ::=  INTEGER
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_mpi( &c, tmp_buf, &ctx->serial ) );
 | 
					    MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_mpi( &c,
 | 
				
			||||||
 | 
					                                                       tmp_buf,
 | 
				
			||||||
 | 
					                                                       &ctx->serial ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /*
 | 
					    /*
 | 
				
			||||||
     *  Version  ::=  INTEGER  {  v1(0), v2(1), v3(2)  }
 | 
					     *  Version  ::=  INTEGER  {  v1(0), v2(1), v3(2)  }
 | 
				
			||||||
@@ -416,15 +454,21 @@ int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx, unsigned char *buf,
 | 
				
			|||||||
    if( ctx->version != MBEDTLS_X509_CRT_VERSION_1 )
 | 
					    if( ctx->version != MBEDTLS_X509_CRT_VERSION_1 )
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        sub_len = 0;
 | 
					        sub_len = 0;
 | 
				
			||||||
        MBEDTLS_ASN1_CHK_ADD( sub_len, mbedtls_asn1_write_int( &c, tmp_buf, ctx->version ) );
 | 
					        MBEDTLS_ASN1_CHK_ADD( sub_len,
 | 
				
			||||||
 | 
					                              mbedtls_asn1_write_int( &c, tmp_buf,
 | 
				
			||||||
 | 
					                                                      ctx->version ) );
 | 
				
			||||||
        len += sub_len;
 | 
					        len += sub_len;
 | 
				
			||||||
        MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, tmp_buf, sub_len ) );
 | 
					        MBEDTLS_ASN1_CHK_ADD( len,
 | 
				
			||||||
        MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( &c, tmp_buf, MBEDTLS_ASN1_CONTEXT_SPECIFIC |
 | 
					                              mbedtls_asn1_write_len( &c, tmp_buf, sub_len ) );
 | 
				
			||||||
 | 
					        MBEDTLS_ASN1_CHK_ADD( len,
 | 
				
			||||||
 | 
					                              mbedtls_asn1_write_tag( &c, tmp_buf,
 | 
				
			||||||
 | 
					                                               MBEDTLS_ASN1_CONTEXT_SPECIFIC |
 | 
				
			||||||
                                               MBEDTLS_ASN1_CONSTRUCTED | 0 ) );
 | 
					                                               MBEDTLS_ASN1_CONSTRUCTED | 0 ) );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, tmp_buf, len ) );
 | 
					    MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, tmp_buf, len ) );
 | 
				
			||||||
    MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( &c, tmp_buf, MBEDTLS_ASN1_CONSTRUCTED |
 | 
					    MBEDTLS_ASN1_CHK_ADD( len,
 | 
				
			||||||
 | 
					                mbedtls_asn1_write_tag( &c, tmp_buf, MBEDTLS_ASN1_CONSTRUCTED |
 | 
				
			||||||
                                                     MBEDTLS_ASN1_SEQUENCE ) );
 | 
					                                                     MBEDTLS_ASN1_SEQUENCE ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /*
 | 
					    /*
 | 
				
			||||||
@@ -436,7 +480,8 @@ int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx, unsigned char *buf,
 | 
				
			|||||||
        return( ret );
 | 
					        return( ret );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if( ( ret = mbedtls_pk_sign( ctx->issuer_key, ctx->md_alg, hash, 0, sig, &sig_len,
 | 
					    if( ( ret = mbedtls_pk_sign( ctx->issuer_key, ctx->md_alg,
 | 
				
			||||||
 | 
					                                 hash, 0, sig, &sig_len,
 | 
				
			||||||
                                 f_rng, p_rng ) ) != 0 )
 | 
					                                 f_rng, p_rng ) ) != 0 )
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return( ret );
 | 
					        return( ret );
 | 
				
			||||||
@@ -457,7 +502,8 @@ int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx, unsigned char *buf,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    len += sig_and_oid_len;
 | 
					    len += sig_and_oid_len;
 | 
				
			||||||
    MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c2, buf, len ) );
 | 
					    MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c2, buf, len ) );
 | 
				
			||||||
    MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( &c2, buf, MBEDTLS_ASN1_CONSTRUCTED |
 | 
					    MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( &c2, buf,
 | 
				
			||||||
 | 
					                                                 MBEDTLS_ASN1_CONSTRUCTED |
 | 
				
			||||||
                                                 MBEDTLS_ASN1_SEQUENCE ) );
 | 
					                                                 MBEDTLS_ASN1_SEQUENCE ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return( (int) len );
 | 
					    return( (int) len );
 | 
				
			||||||
@@ -467,7 +513,8 @@ int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx, unsigned char *buf,
 | 
				
			|||||||
#define PEM_END_CRT             "-----END CERTIFICATE-----\n"
 | 
					#define PEM_END_CRT             "-----END CERTIFICATE-----\n"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(MBEDTLS_PEM_WRITE_C)
 | 
					#if defined(MBEDTLS_PEM_WRITE_C)
 | 
				
			||||||
int mbedtls_x509write_crt_pem( mbedtls_x509write_cert *crt, unsigned char *buf, size_t size,
 | 
					int mbedtls_x509write_crt_pem( mbedtls_x509write_cert *crt,
 | 
				
			||||||
 | 
					                               unsigned char *buf, size_t size,
 | 
				
			||||||
                               int (*f_rng)(void *, unsigned char *, size_t),
 | 
					                               int (*f_rng)(void *, unsigned char *, size_t),
 | 
				
			||||||
                               void *p_rng )
 | 
					                               void *p_rng )
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user