Pkcs7 constructor Null safety

Pkcs7(
  1. ASN1Sequence asn1
)

Creates a Pkcs7 message from an ASN1Sequence.

Implementation

factory Pkcs7(ASN1Sequence asn1) {
  final data =
      ASN1Parser(asn1.elements![1].valueBytes).nextObject() as ASN1Sequence;

  ASN1Object? cert;

  ASN1Object? crl;

  ASN1Set? signerInfo;

  for (final e in data.elements!.sublist(3)) {
    if (e.tag == 0xa0) {
      cert = e;
    } else if (e.tag == 0xa1) {
      crl = e;
    } else if (e is ASN1Set) {
      signerInfo = e;
    }
  }

  final pkcs7 = Pkcs7._(asn1, data, cert, crl, signerInfo);

  if (pkcs7.contentType.objectIdentifierAsString != Pkcs.signedData) {
    throw UnsupportedError(
        'Not a Pkcs7 signature message (${pkcs7.contentType.objectIdentifierAsString})');
  }

  return pkcs7;
}