1
0
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:
Alexander Medvednikov 2023-05-18 11:31:53 +02:00
parent 9d9785cc05
commit cc47c78f39
2 changed files with 24 additions and 16 deletions

View File

@ -6,6 +6,7 @@
- Generic functions as function parameters are now supported: `fn f[T](x T, i int, f_ Fn[T]) T { `. - 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. - Enum values now can have attributes.
- json: Enum value string serialization supports `[json:'alias']` to change its string values. - json: Enum value string serialization supports `[json:'alias']` to change its string values.
- Functions can now return fixed size arrays.
## V 0.3.4 ## V 0.3.4

View File

@ -12,9 +12,9 @@ fn init() {
$if trace_ssl ? { $if trace_ssl ? {
eprintln(@METHOD) eprintln(@METHOD)
} }
unsafe { // Unsafe is needed for taking an address of const
C.mbedtls_ctr_drbg_init(&mbedtls.ctr_drbg) C.mbedtls_ctr_drbg_init(&mbedtls.ctr_drbg)
C.mbedtls_entropy_init(&mbedtls.entropy) C.mbedtls_entropy_init(&mbedtls.entropy)
ret := C.mbedtls_ctr_drbg_seed(&mbedtls.ctr_drbg, C.mbedtls_entropy_func, &mbedtls.entropy, ret := C.mbedtls_ctr_drbg_seed(&mbedtls.ctr_drbg, C.mbedtls_entropy_func, &mbedtls.entropy,
0, 0) 0, 0)
if ret != 0 { if ret != 0 {
@ -22,6 +22,7 @@ fn init() {
panic('Failed to seed ssl context: ${ret}') panic('Failed to seed ssl context: ${ret}')
} }
} }
}
struct SSLCerts { struct SSLCerts {
cacert C.mbedtls_x509_crt cacert C.mbedtls_x509_crt
@ -110,7 +111,9 @@ fn (mut s SSLConn) init() ! {
return error_with_code('Failed to set SSL configuration', ret) 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) 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 != '' { if s.config.verify != '' || s.config.cert != '' || s.config.cert_key != '' {
s.certs = &SSLCerts{} 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) ret = C.mbedtls_x509_crt_parse(&s.certs.client_cert, s.config.cert.str, s.config.cert.len)
} }
if s.config.cert_key != '' { 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, unsafe {
0, 0, C.mbedtls_ctr_drbg_random, &mbedtls.ctr_drbg) 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 { } else {
if s.config.verify != '' { 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)) ret = C.mbedtls_x509_crt_parse_file(&s.certs.client_cert, &char(s.config.cert.str))
} }
if s.config.cert_key != '' { if s.config.cert_key != '' {
unsafe {
ret = C.mbedtls_pk_parse_keyfile(&s.certs.client_key, &char(s.config.cert_key.str), 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) 0, C.mbedtls_ctr_drbg_random, &mbedtls.ctr_drbg)
} }
} }
}
if ret < 0 { if ret < 0 {
return error_with_code('Failed to set certificates', ret) return error_with_code('Failed to set certificates', ret)
} }