<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def digest(self, data=None):
 """ Finalizes digest operation and return digest value Optionally hashes more data before finalizing """

        if self.digest_finalized:
            return self.digest_out.raw[:self.digest_size]
        if data is not None:
            self.update(data)
        self.digest_out = create_string_buffer(256)
        length = c_long(0)
        result = libcrypto.EVP_DigestFinal_ex(self.ctx, self.digest_out,
                                              byref(length))
        if result != 1:
            raise DigestError("Unable to finalize digest")
        self.digest_finalized = True
        return self.digest_out.raw[:self.digest_size]