src/sock_gnutls.c
changeset 4 a3ca0f97a075
parent 3 cc94ae754e2a
child 5 a09a0797f6f0
equal deleted inserted replaced
3:cc94ae754e2a 4:a3ca0f97a075
    41  */
    41  */
    42 struct sock_gnutls_client_ctx _sock_gnutls_client_ctx;
    42 struct sock_gnutls_client_ctx _sock_gnutls_client_ctx;
    43 
    43 
    44 /*
    44 /*
    45  * Configure the given gnutls socket context to use simple anonymous client credentials
    45  * Configure the given gnutls socket context to use simple anonymous client credentials
    46  *
       
    47  * XXX: errors
       
    48  */
    46  */
    49 void sock_gnutls_client_ctx_anon (struct sock_gnutls_client_ctx *ctx)
    47 static err_t sock_gnutls_client_ctx_anon (struct sock_gnutls_client_ctx *ctx, struct error_info *err)
    50 {
    48 {
    51       gnutls_certificate_allocate_credentials(&ctx->xcred);
    49     // init to use anonymous x509 cert
       
    50     if ((ERROR_EXTRA(err) = gnutls_certificate_allocate_credentials(&ctx->xcred)) < 0)
       
    51         return SET_ERROR(err, ERR_GNUTLS_CERT_ALLOC_CRED);
       
    52 
       
    53     // done
       
    54     return SUCCESS;
    52 }
    55 }
    53 
    56 
    54 err_t sock_gnutls_init (void)
    57 err_t sock_gnutls_init (struct error_info *err)
    55 {
    58 {
    56     int _err;
       
    57 
       
    58     // global init
    59     // global init
    59     if ((_err = gnutls_global_init()) < 0)
    60     if ((ERROR_EXTRA(err) = gnutls_global_init()) < 0)
    60         errx(1, "gnutls_global_init: %s", gnutls_strerror(_err));
    61         return SET_ERROR(err, ERR_GNUTLS_GLOBAL_INIT);
    61 
    62 
    62     // init _sock_gnutls_ctx
    63     // init _sock_gnutls_ctx
    63     sock_gnutls_client_ctx_anon(&_sock_gnutls_client_ctx);
    64     if (sock_gnutls_client_ctx_anon(&_sock_gnutls_client_ctx, err))
       
    65         return ERROR_CODE(err);
    64 
    66 
    65     // done
    67     // done
    66     return SUCCESS;
    68     return SUCCESS;
    67 }
    69 }
    68 
    70