build method Null safety

Pkcs7 build()

Generate the Pkcs7 message

Implementation

Pkcs7 build() {
  final asn1 = ASN1Sequence();
  asn1.add(ASN1ObjectIdentifier([1, 2, 840, 113549, 1, 7, 2]));

  final data = ASN1Sequence();
  data.add(ASN1Integer.fromtInt(1)); // Version
  data.add(ASN1Set(elements: _digestAlgorithms.toList())); // digestAlgorithms
  data.add(_contentInfo); // contentInfo

  if (_certificates.isNotEmpty) {
    final certData =
        _certificates.map((x) => x.asn1.encode()).expand((x) => x).toList();
    final cert = ASN1OctetString(
      octets: Uint8List.fromList(certData),
      tag: 0xa0,
    );
    data.add(cert); // Certificates
  }

  if (_crl.isNotEmpty) {
    final crlData =
        _crl.map((x) => x.asn1.encode()).expand((x) => x).toList();
    final cert = ASN1OctetString(
      octets: Uint8List.fromList(crlData),
      tag: 0xa1,
    );
    data.add(cert); // Certificates
  }

  final signerInfo = ASN1Set(
    elements: _signerInfos.map((i) => i.build().asn1).toList(),
  );
  data.add(signerInfo); // Signer Info

  asn1.add(ASN1OctetString(octets: data.encode(), tag: 0xa0));
  asn1.encode();

  return Pkcs7(asn1);
}