encodeCms method
Encodes a CMS/PKCS#7 structure to DER.
Implementation
Uint8List encodeCms(CmsContent cms) {
final len = bindings.i2d_CMS_ContentInfo(cms.handle, nullptr);
if (len <= 0) {
throw OpenSslException('i2d_CMS_ContentInfo length failed');
}
final buffer = calloc<Uint8>(len);
final out = calloc<Pointer<UnsignedChar>>();
out.value = buffer.cast<UnsignedChar>();
final written = bindings.i2d_CMS_ContentInfo(cms.handle, out);
calloc.free(out);
if (written <= 0) {
calloc.free(buffer);
throw OpenSslException('i2d_CMS_ContentInfo encode failed');
}
final bytes = Uint8List.fromList(buffer.asTypedList(written));
calloc.free(buffer);
return bytes;
}