createBioFromString method
Cria um BIO a partir de uma String.
Implementation
Pointer<BIO> createBioFromString(String text) {
// É mais seguro alocar memória Dart e copiar, ou usar BIO_new_mem_buf.
// BIO_new_mem_buf cria um BIO read-only se passarmos ponteiro direto.
// Para simplificar e garantir ownership, vamos criar um BIO de memória e escrever nele.
final bio = bindings.BIO_new(bindings.BIO_s_mem());
if (bio == nullptr) throw OpenSslException('Failed to create BIO');
final units = text.codeUnits;
final buffer = calloc<Uint8>(units.length);
try {
buffer.asTypedList(units.length).setAll(0, units);
final written = bindings.BIO_write(bio, buffer.cast(), units.length);
if (written <= 0) throw OpenSslException('Failed to write to BIO');
} finally {
calloc.free(buffer);
}
return bio;
}