mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
net.mbedtls: make compile with -prod
This commit is contained in:
parent
9d9785cc05
commit
cc47c78f39
@ -6,6 +6,7 @@
|
||||
- Generic functions as function parameters are now supported: `fn f[T](x T, i int, f_ Fn[T]) T { `.
|
||||
- Enum values now can have attributes.
|
||||
- json: Enum value string serialization supports `[json:'alias']` to change its string values.
|
||||
- Functions can now return fixed size arrays.
|
||||
|
||||
## V 0.3.4
|
||||
|
||||
|
@ -12,15 +12,16 @@ fn init() {
|
||||
$if trace_ssl ? {
|
||||
eprintln(@METHOD)
|
||||
}
|
||||
unsafe { // Unsafe is needed for taking an address of const
|
||||
C.mbedtls_ctr_drbg_init(&mbedtls.ctr_drbg)
|
||||
C.mbedtls_entropy_init(&mbedtls.entropy)
|
||||
|
||||
ret := C.mbedtls_ctr_drbg_seed(&mbedtls.ctr_drbg, C.mbedtls_entropy_func, &mbedtls.entropy,
|
||||
0, 0)
|
||||
if ret != 0 {
|
||||
C.mbedtls_ctr_drbg_free(&mbedtls.ctr_drbg)
|
||||
panic('Failed to seed ssl context: ${ret}')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct SSLCerts {
|
||||
@ -110,7 +111,9 @@ fn (mut s SSLConn) init() ! {
|
||||
return error_with_code('Failed to set SSL configuration', ret)
|
||||
}
|
||||
|
||||
unsafe {
|
||||
C.mbedtls_ssl_conf_rng(&s.conf, C.mbedtls_ctr_drbg_random, &mbedtls.ctr_drbg)
|
||||
}
|
||||
|
||||
if s.config.verify != '' || s.config.cert != '' || s.config.cert_key != '' {
|
||||
s.certs = &SSLCerts{}
|
||||
@ -127,8 +130,10 @@ fn (mut s SSLConn) init() ! {
|
||||
ret = C.mbedtls_x509_crt_parse(&s.certs.client_cert, s.config.cert.str, s.config.cert.len)
|
||||
}
|
||||
if s.config.cert_key != '' {
|
||||
ret = C.mbedtls_pk_parse_key(&s.certs.client_key, s.config.cert_key.str, s.config.cert_key.len,
|
||||
0, 0, C.mbedtls_ctr_drbg_random, &mbedtls.ctr_drbg)
|
||||
unsafe {
|
||||
ret = C.mbedtls_pk_parse_key(&s.certs.client_key, s.config.cert_key.str,
|
||||
s.config.cert_key.len, 0, 0, C.mbedtls_ctr_drbg_random, &mbedtls.ctr_drbg)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if s.config.verify != '' {
|
||||
@ -138,10 +143,12 @@ fn (mut s SSLConn) init() ! {
|
||||
ret = C.mbedtls_x509_crt_parse_file(&s.certs.client_cert, &char(s.config.cert.str))
|
||||
}
|
||||
if s.config.cert_key != '' {
|
||||
unsafe {
|
||||
ret = C.mbedtls_pk_parse_keyfile(&s.certs.client_key, &char(s.config.cert_key.str),
|
||||
0, C.mbedtls_ctr_drbg_random, &mbedtls.ctr_drbg)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ret < 0 {
|
||||
return error_with_code('Failed to set certificates', ret)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user