build method Null safety

Pkcs7SignerInfo build()

Build the Pkcs7SignerInfo

Implementation

Pkcs7SignerInfo build() {
  final asn1 = ASN1Sequence();
  asn1.add(ASN1Integer.fromtInt(1)); // Version
  asn1.add(issuer.asn1Issuer); // Issuer and Serial

  // Digest Algorithm
  asn1.add(ASN1Sequence(elements: [
    digestAlgorithmID,
    ASN1Null(),
  ]));

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

  // Digest Encryption Algorithm
  asn1.add(ASN1Sequence(elements: [
    digestEncryptionAlgorithmID,
    ASN1Null(),
  ]));

  // Encrypted Digest
  asn1.add(ASN1OctetString(
    octets: signature,
  ));

  // Unauthenticated Attributes
  if (_unauthenticatedAttributes.isNotEmpty) {
    final certData = _unauthenticatedAttributes
        .map((x) => x.encode())
        .expand((x) => x)
        .toList();
    final cert = ASN1OctetString(
      octets: Uint8List.fromList(certData),
      tag: 0xa1,
    );
    asn1.add(cert);
  }

  return Pkcs7SignerInfo(asn1);
}