addEntry method

void addEntry(
  1. String field,
  2. String value
)

Adds a text entry to the name. field is the short name (e.g., "CN", "O", "C", "OU"). value is the value.

Implementation

void addEntry(String field, String value) {
  if (_isDisposed) {
    throw StateError('Cannot add entry to disposed X509Name');
  }
  // Use Arena to ensure proper memory management
  final arena = Arena();
  try {
    final fieldPtr = field.toNativeUtf8(allocator: arena);
    final valuePtr = value.toNativeUtf8(allocator: arena);
    // MBSTRING_UTF8 = 0x1000
    final result = _context.bindings.X509_NAME_add_entry_by_txt(
      handle,
      fieldPtr.cast(),
      0x1000,
      valuePtr.cast(),
      -1, // use strlen
      -1, // append
      0   // set
    );
    if (result != 1) {
       throw OpenSslException('Failed to add entry $field=$value to X509_NAME');
    }
  } finally {
    arena.releaseAll();
  }
}