/* Used as the output function of a SEC_PKCS7EncoderContext -- we feed plaintext into the crypto engine, and it calls this function with encrypted data; then this function writes a base64-encoded representation of that data to the file (by filtering it through the given MimeEncoderData object.) Also used as the output function of SEC_PKCS7Encode() -- but in that case, it's used to write the encoded representation of the signature. The only difference is which MimeEncoderData object is used. */ static void mime_crypto_write_base64 (void *closure, const char *buf, unsigned long size) { MimeEncoderData *data = (MimeEncoderData *) closure; nsresult rv = MIME_EncoderWrite (data, buf, size); PR_SetError(NS_FAILED(rv) ? rv : 0, 0); }
int nsMsgSendPart::PushBody(const char* buffer, PRInt32 length) { int status = 0; const char* encoded_data = buffer; if (m_encoder_data) { status = MIME_EncoderWrite(m_encoder_data, encoded_data, length); } else { // Merely translate all linebreaks to CRLF. const char *in = encoded_data; const char *end = in + length; char *buffer, *out; buffer = mime_get_stream_write_buffer(); if (!buffer) return NS_ERROR_OUT_OF_MEMORY; NS_ASSERTION(encoded_data != buffer, "encoded_data == buffer"); out = buffer; for (; in < end; in++) { if (m_just_hit_CR) { m_just_hit_CR = false; if (*in == '\n') { // The last thing we wrote was a CRLF from hitting a CR. // So, we don't want to do anything from a following LF; // we want to ignore it. continue; } } if (*in == '\r' || *in == '\n') { /* Write out the newline. */ *out++ = '\r'; *out++ = '\n'; status = mime_write_message_body(m_state, buffer, out - buffer); if (status < 0) return status; out = buffer; if (*in == '\r') { m_just_hit_CR = true; } out = buffer; } else { /* Fix for bug #95985. We can't assume that all lines are shorter than 4096 chars (MIME_BUFFER_SIZE), so we need to test for this here. sfraser. */ if (out - buffer >= MIME_BUFFER_SIZE) { status = mime_write_message_body(m_state, buffer, out - buffer); if (status < 0) return status; out = buffer; } *out++ = *in; } } /* Flush the last line. */ if (out > buffer) { status = mime_write_message_body(m_state, buffer, out - buffer); if (status < 0) return status; out = buffer; } } if (encoded_data && encoded_data != buffer) { PR_Free((char *) encoded_data); } return status; }