def add_signature_block(src_fileobj, dest_fileobj, signing_algorithm, signature=None):
algo_id = {'<STR_LIT>': <NUM_LIT:1>, '<STR_LIT>': <NUM_LIT:2>}[signing_algorithm]<EOL>if not signature:<EOL><INDENT>signature = make_dummy_signature(algo_id)<EOL><DEDENT>src_fileobj.seek(<NUM_LIT:0>)<EOL>mardata = mar.parse_stream(src_fileobj)<EOL>header = mardata.header<EOL>dest_fileobj.write(mar_header.build(header))<EOL>sig = dict(algorithm_id=algo_id,<EOL>size=len(signature),<EOL>signature=signature,<EOL>)<EOL>filesize = <NUM_LIT:0><EOL>sigs_offset = dest_fileobj.tell()<EOL>sigs = sigs_header.build(dict(<EOL>filesize=filesize,<EOL>count=<NUM_LIT:1>,<EOL>sigs=[sig],<EOL>))<EOL>dest_fileobj.write(sigs)<EOL>dest_fileobj.write(extras_header.build(mardata.additional))<EOL>data_offset = dest_fileobj.tell()<EOL>src_fileobj.seek(mardata.data_offset)<EOL>write_to_file(takeexactly(src_fileobj, mardata.data_length), dest_fileobj)<EOL>index_offset = dest_fileobj.tell()<EOL>index = mardata.index<EOL>data_offset_delta = data_offset - mardata.data_offset<EOL>for e in index.entries:<EOL><INDENT>e.offset += data_offset_delta<EOL><DEDENT>dest_fileobj.write(index_header.build(index))<EOL>filesize = dest_fileobj.tell()<EOL>dest_fileobj.seek(<NUM_LIT:0>)<EOL>header.index_offset = index_offset<EOL>dest_fileobj.write(mar_header.build(header))<EOL>dest_fileobj.seek(sigs_offset)<EOL>sigs = sigs_header.build(dict(<EOL>filesize=filesize,<EOL>count=<NUM_LIT:1>,<EOL>sigs=[sig],<EOL>))<EOL>dest_fileobj.write(sigs)<EOL>
Add a signature block to marfile, a MarReader object.

    Productversion and channel are preserved, but any existing signatures are overwritten.

    Args:
        src_fileobj (file object): The input MAR file to add a signature to
        dest_fileobj (file object): File object to write new MAR file to. Must be open in w+b mode.
        signing_algorithm (str): One of 'sha1', or 'sha384'
        signature (bytes): Signature to write, or None to use a dummy signature