1 /* 2 * Copyright (c) 2017, [Ribose Inc](https://www.ribose.com). 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without modification, 6 * are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, 9 * this list of conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, 12 * this list of conditions and the following disclaimer in the documentation 13 * and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27 #ifndef STREAM_WRITE_H_ 28 #define STREAM_WRITE_H_ 29 30 #include <stdint.h> 31 #include <stdbool.h> 32 #include <sys/types.h> 33 #include "rnp.h" 34 #include "stream-common.h" 35 #include "stream-ctx.h" 36 37 typedef struct pgp_write_handler_t { 38 pgp_password_provider_t *password_provider; 39 pgp_key_provider_t * key_provider; 40 rnp_ctx_t * ctx; 41 42 void *param; 43 } pgp_write_handler_t; 44 45 /** @brief symmetrically encrypt the input data 46 * @param handler handler to respond on stream processor callbacks 47 * @param src input source: file, stdin, memory, whatever else conforming to pgp_source_t 48 * @param dst output destination: file, stdout, memory, whatever else conforming to pgp_dest_t 49 **/ 50 rnp_result_t rnp_encrypt_src(pgp_write_handler_t *handler, pgp_source_t *src, pgp_dest_t *dst); 51 52 /** @brief sign the input data, producing attached, detached or cleartext signature. 53 * Type of the signature is controlled by clearsign and detached fields of the 54 * rnp_ctx_t structure 55 * @param handler handler to respond on stream processor callbacks, and additional processing 56 * parameters, including rnp_ctx_t 57 * @param src input source: file, stdin, memory, whatever else conforming to pgp_source_t 58 * @param dst output destination: file, stdout, memory, whatever else conforming to pgp_dest_t 59 **/ 60 rnp_result_t rnp_sign_src(pgp_write_handler_t *handler, pgp_source_t *src, pgp_dest_t *dst); 61 62 /** @brief encrypt and sign the input data. Signatures will be enrypted together with data. 63 * @param handler handler handler to respond on stream processor callbacks, and additional 64 * processing parameters, including rnp_ctx_t 65 * @param src input source: file, stdin, memory, whatever else conforming to pgp_source_t 66 * @param dst output destination: file, stdout, memory, whatever else conforming to pgp_dest_t 67 **/ 68 rnp_result_t rnp_encrypt_sign_src(pgp_write_handler_t *handler, 69 pgp_source_t * src, 70 pgp_dest_t * dst); 71 72 /* Following functions are used only in tests currently. Later could be used in CLI for debug 73 * commands like --wrap-literal, --encrypt-raw, --compress-raw, etc. */ 74 75 rnp_result_t rnp_compress_src(pgp_source_t & src, 76 pgp_dest_t & dst, 77 pgp_compression_type_t zalg, 78 int zlevel); 79 80 rnp_result_t rnp_wrap_src(pgp_source_t & src, 81 pgp_dest_t & dst, 82 const std::string &filename, 83 uint32_t modtime); 84 85 rnp_result_t rnp_raw_encrypt_src(pgp_source_t & src, 86 pgp_dest_t & dst, 87 const std::string &password); 88 89 #endif 90