toDer method
Exports CSR to DER bytes.
Implementation
Uint8List toDer() {
final len = _context.bindings.i2d_X509_REQ(handle, nullptr);
if (len <= 0) {
throw OpenSslException('Failed to get CSR DER length');
}
final buffer = calloc<Uint8>(len);
final out = calloc<Pointer<UnsignedChar>>();
out.value = buffer.cast<UnsignedChar>();
try {
final written = _context.bindings.i2d_X509_REQ(handle, out);
if (written <= 0) {
throw OpenSslException('Failed to encode CSR to DER');
}
return Uint8List.fromList(buffer.asTypedList(written));
} finally {
calloc.free(out);
calloc.free(buffer);
}
}