xref: /netbsd-src/crypto/external/bsd/netpgp/dist/src/lib/writer.h (revision 4b3a3e1885075b4d9ba6f04740b0f60ae90e91b9)
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@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 Create
64  * This struct contains the required information about one writer
65  */
66 /**
67  * \ingroup Writer
68  * the writer function prototype
69  */
70 
71 typedef struct __ops_writer_info __ops_writer_info_t;
72 typedef unsigned
73 __ops_writer_t(const unsigned char *,
74 	     unsigned,
75 	     __ops_error_t **,
76 	     __ops_writer_info_t *);
77 typedef unsigned
78 __ops_writer_finaliser_t(__ops_error_t **, __ops_writer_info_t *);
79 typedef void    __ops_writer_destroyer_t(__ops_writer_info_t *);
80 
81 /** Writer settings */
82 struct __ops_writer_info {
83 	__ops_writer_t   *writer;	/* !< the writer itself */
84 	__ops_writer_finaliser_t *finaliser;	/* !< the writer's finaliser */
85 	__ops_writer_destroyer_t *destroyer;	/* !< the writer's destroyer */
86 	void           *arg;	/* writer-specific argument */
87 	__ops_writer_info_t *next;/* !< next writer in the stack */
88 };
89 
90 
91 void           *__ops_writer_get_arg(__ops_writer_info_t *);
92 unsigned
93 __ops_stacked_write(const void *, unsigned,
94 		  __ops_error_t **,
95 		  __ops_writer_info_t *);
96 
97 void
98 __ops_writer_set(__ops_createinfo_t *,
99 	       __ops_writer_t *,
100 	       __ops_writer_finaliser_t *,
101 	       __ops_writer_destroyer_t *,
102 	       void *);
103 void
104 __ops_writer_push(__ops_createinfo_t *,
105 		__ops_writer_t *,
106 		__ops_writer_finaliser_t *,
107 		__ops_writer_destroyer_t *,
108 		void *);
109 void            __ops_writer_pop(__ops_createinfo_t *);
110 void            __ops_writer_generic_destroyer(__ops_writer_info_t *);
111 unsigned
112 __ops_writer_passthrough(const unsigned char *,
113 		       unsigned,
114 		       __ops_error_t **,
115 		       __ops_writer_info_t *);
116 
117 void            __ops_writer_set_fd(__ops_createinfo_t *, int);
118 unsigned   __ops_writer_close(__ops_createinfo_t *);
119 
120 unsigned
121 __ops_write(const void *, unsigned, __ops_createinfo_t *);
122 unsigned   __ops_write_length(unsigned, __ops_createinfo_t *);
123 unsigned   __ops_write_ptag(__ops_content_tag_t, __ops_createinfo_t *);
124 unsigned __ops_write_scalar(unsigned, unsigned, __ops_createinfo_t *);
125 unsigned   __ops_write_mpi(const BIGNUM *, __ops_createinfo_t *);
126 unsigned   __ops_write_encrypted_mpi(const BIGNUM *, __ops_crypt_t *, __ops_createinfo_t *);
127 
128 void            writer_info_delete(__ops_writer_info_t *);
129 unsigned   writer_info_finalise(__ops_error_t **, __ops_writer_info_t *);
130 
131 void __ops_push_stream_enc_se_ip(__ops_createinfo_t *, const __ops_keydata_t *);
132 
133 #endif /* WRITER_H_ */
134