parseTimestampToken method

TimestampToken parseTimestampToken(
  1. Uint8List tokenDer
)

Parses a bare token (the CMS/PKCS#7 TimeStampToken), without the response envelope — the shape usually archived next to a signature.

Implementation

TimestampToken parseTimestampToken(Uint8List tokenDer) {
  final arena = Arena();
  Pointer<PKCS7> token = nullptr;
  Pointer<TS_TST_INFO> tstInfo = nullptr;

  try {
    token = _d2i(
      tokenDer,
      arena,
      (inOut, len) => bindings.d2i_PKCS7(nullptr, inOut, len),
      'd2i_PKCS7',
    );

    tstInfo = bindings.PKCS7_to_TS_TST_INFO(token);
    if (tstInfo == nullptr) {
      throw OpenSslException(
        'Not an RFC 3161 time-stamp token',
        bindings.ERR_get_error(),
        'PKCS7_to_TS_TST_INFO',
      );
    }

    return _readTstInfo(tstInfo, Uint8List.fromList(tokenDer));
  } finally {
    if (tstInfo != nullptr) bindings.TS_TST_INFO_free(tstInfo);
    if (token != nullptr) bindings.PKCS7_free(token);
    arena.releaseAll();
  }
}