Home | History | Annotate | Line # | Download | only in lib
      1 /*-
      2  * Copyright (c) 2009 The NetBSD Foundation, Inc.
      3  * All rights reserved.
      4  *
      5  * This code is derived from software contributed to The NetBSD Foundation
      6  * by Alistair Crooks (agc (at) NetBSD.org)
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  *
     17  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     20  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     21  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     27  * POSSIBILITY OF SUCH DAMAGE.
     28  */
     29 /*
     30  * Copyright (c) 2005-2008 Nominet UK (www.nic.uk)
     31  * All rights reserved.
     32  * Contributors: Ben Laurie, Rachel Willmer. The Contributors have asserted
     33  * their moral rights under the UK Copyright Design and Patents Act 1988 to
     34  * be recorded as the authors of this copyright work.
     35  *
     36  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
     37  * use this file except in compliance with the License.
     38  *
     39  * You may obtain a copy of the License at
     40  *     http://www.apache.org/licenses/LICENSE-2.0
     41  *
     42  * Unless required by applicable law or agreed to in writing, software
     43  * distributed under the License is distributed on an "AS IS" BASIS,
     44  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     45  *
     46  * See the License for the specific language governing permissions and
     47  * limitations under the License.
     48  */
     49 
     50 /** \file
     51  */
     52 
     53 #ifndef WRITER_H_
     54 #define WRITER_H_
     55 
     56 #include "types.h"
     57 #include "packet.h"
     58 #include "crypto.h"
     59 #include "errors.h"
     60 #include "keyring.h"
     61 
     62 /**
     63  * \ingroup Writer
     64  * the writer function prototype
     65  */
     66 
     67 typedef struct pgp_writer_t	pgp_writer_t;
     68 typedef unsigned pgp_writer_func_t(const uint8_t *,
     69 	     unsigned,
     70 	     pgp_error_t **,
     71 	     pgp_writer_t *);
     72 typedef unsigned
     73 pgp_writer_finaliser_t(pgp_error_t **, pgp_writer_t *);
     74 typedef void    pgp_writer_destroyer_t(pgp_writer_t *);
     75 
     76 /** Writer settings */
     77 struct pgp_writer_t {
     78 	pgp_writer_func_t	 *writer;	/* the writer itself */
     79 	pgp_writer_finaliser_t *finaliser;	/* the writer's finaliser */
     80 	pgp_writer_destroyer_t *destroyer;	/* the writer's destroyer */
     81 	void			 *arg;	/* writer-specific argument */
     82 	pgp_writer_t	 	 *next;	/* next writer in the stack */
     83 	pgp_io_t		 *io;	/* IO for errors and output */
     84 };
     85 
     86 
     87 void *pgp_writer_get_arg(pgp_writer_t *);
     88 
     89 void pgp_writer_set(pgp_output_t *,
     90 	       pgp_writer_func_t *,
     91 	       pgp_writer_finaliser_t *,
     92 	       pgp_writer_destroyer_t *,
     93 	       void *);
     94 void pgp_writer_push(pgp_output_t *,
     95 		pgp_writer_func_t *,
     96 		pgp_writer_finaliser_t *,
     97 		pgp_writer_destroyer_t *,
     98 		void *);
     99 void pgp_writer_pop(pgp_output_t *);
    100 unsigned pgp_writer_passthrough(const uint8_t *,
    101 		       unsigned,
    102 		       pgp_error_t **,
    103 		       pgp_writer_t *);
    104 
    105 void pgp_writer_set_fd(pgp_output_t *, int);
    106 unsigned pgp_writer_close(pgp_output_t *);
    107 
    108 unsigned pgp_write(pgp_output_t *, const void *, unsigned);
    109 unsigned pgp_write_length(pgp_output_t *, unsigned);
    110 unsigned pgp_write_ptag(pgp_output_t *, pgp_content_enum);
    111 unsigned pgp_write_scalar(pgp_output_t *, unsigned, unsigned);
    112 unsigned pgp_write_mpi(pgp_output_t *, const BIGNUM *);
    113 
    114 void pgp_writer_info_delete(pgp_writer_t *);
    115 unsigned pgp_writer_info_finalise(pgp_error_t **, pgp_writer_t *);
    116 
    117 void pgp_push_stream_enc_se_ip(pgp_output_t *, const pgp_key_t *, const char *);
    118 
    119 #endif /* WRITER_H_ */
    120