1 /* $NetBSD: openpgpkey_61.c,v 1.1.1.2 2015/09/03 07:21:39 christos Exp $ */
4 * Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
19 #ifndef RDATA_GENERIC_OPENPGPKEY_61_C
20 #define RDATA_GENERIC_OPENPGPKEY_61_C
22 #define RRTYPE_OPENPGPKEY_ATTRIBUTES 0
24 static inline isc_result_t
25 fromtext_openpgpkey(ARGS_FROMTEXT
) {
38 return (isc_base64_tobuffer(lexer
, target
, -1));
41 static inline isc_result_t
42 totext_openpgpkey(ARGS_TOTEXT
) {
45 REQUIRE(rdata
->type
== 61);
46 REQUIRE(rdata
->length
!= 0);
48 dns_rdata_toregion(rdata
, &sr
);
53 if ((tctx
->flags
& DNS_STYLEFLAG_MULTILINE
) != 0)
54 RETERR(str_totext("( ", target
));
56 if ((tctx
->flags
& DNS_STYLEFLAG_NOCRYPTO
) == 0) {
57 if (tctx
->width
== 0) /* No splitting */
58 RETERR(isc_base64_totext(&sr
, 60, "", target
));
60 RETERR(isc_base64_totext(&sr
, tctx
->width
- 2,
61 tctx
->linebreak
, target
));
63 RETERR(str_totext("[omitted]", target
));
65 if ((tctx
->flags
& DNS_STYLEFLAG_MULTILINE
) != 0)
66 RETERR(str_totext(" )", target
));
68 return (ISC_R_SUCCESS
);
71 static inline isc_result_t
72 fromwire_openpgpkey(ARGS_FROMWIRE
) {
85 isc_buffer_activeregion(source
, &sr
);
87 return (ISC_R_UNEXPECTEDEND
);
88 isc_buffer_forward(source
, sr
.length
);
89 return (mem_tobuffer(target
, sr
.base
, sr
.length
));
92 static inline isc_result_t
93 towire_openpgpkey(ARGS_TOWIRE
) {
96 REQUIRE(rdata
->type
== 61);
97 REQUIRE(rdata
->length
!= 0);
101 dns_rdata_toregion(rdata
, &sr
);
102 return (mem_tobuffer(target
, sr
.base
, sr
.length
));
106 compare_openpgpkey(ARGS_COMPARE
) {
110 REQUIRE(rdata1
->type
== rdata2
->type
);
111 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
112 REQUIRE(rdata1
->type
== 61);
113 REQUIRE(rdata1
->length
!= 0);
114 REQUIRE(rdata2
->length
!= 0);
116 dns_rdata_toregion(rdata1
, &r1
);
117 dns_rdata_toregion(rdata2
, &r2
);
118 return (isc_region_compare(&r1
, &r2
));
121 static inline isc_result_t
122 fromstruct_openpgpkey(ARGS_FROMSTRUCT
) {
123 dns_rdata_openpgpkey_t
*sig
= source
;
126 REQUIRE(source
!= NULL
);
127 REQUIRE(sig
->common
.rdtype
== type
);
128 REQUIRE(sig
->common
.rdclass
== rdclass
);
129 REQUIRE(sig
->keyring
!= NULL
&& sig
->length
!= 0);
137 return (mem_tobuffer(target
, sig
->keyring
, sig
->length
));
140 static inline isc_result_t
141 tostruct_openpgpkey(ARGS_TOSTRUCT
) {
143 dns_rdata_openpgpkey_t
*sig
= target
;
145 REQUIRE(rdata
->type
== 61);
146 REQUIRE(target
!= NULL
);
147 REQUIRE(rdata
->length
!= 0);
149 sig
->common
.rdclass
= rdata
->rdclass
;
150 sig
->common
.rdtype
= rdata
->type
;
151 ISC_LINK_INIT(&sig
->common
, link
);
153 dns_rdata_toregion(rdata
, &sr
);
158 sig
->length
= sr
.length
;
159 sig
->keyring
= mem_maybedup(mctx
, sr
.base
, sig
->length
);
160 if (sig
->keyring
== NULL
)
164 return (ISC_R_SUCCESS
);
167 return (ISC_R_NOMEMORY
);
171 freestruct_openpgpkey(ARGS_FREESTRUCT
) {
172 dns_rdata_openpgpkey_t
*sig
= (dns_rdata_openpgpkey_t
*) source
;
174 REQUIRE(source
!= NULL
);
175 REQUIRE(sig
->common
.rdtype
== 61);
177 if (sig
->mctx
== NULL
)
180 if (sig
->keyring
!= NULL
)
181 isc_mem_free(sig
->mctx
, sig
->keyring
);
185 static inline isc_result_t
186 additionaldata_openpgpkey(ARGS_ADDLDATA
) {
187 REQUIRE(rdata
->type
== 61);
193 return (ISC_R_SUCCESS
);
196 static inline isc_result_t
197 digest_openpgpkey(ARGS_DIGEST
) {
200 REQUIRE(rdata
->type
== 61);
202 dns_rdata_toregion(rdata
, &r
);
204 return ((digest
)(arg
, &r
));
207 static inline isc_boolean_t
208 checkowner_openpgpkey(ARGS_CHECKOWNER
) {
220 static inline isc_boolean_t
221 checknames_openpgpkey(ARGS_CHECKNAMES
) {
223 REQUIRE(rdata
->type
== 61);
233 casecompare_openpgpkey(ARGS_COMPARE
) {
237 REQUIRE(rdata1
->type
== rdata2
->type
);
238 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
239 REQUIRE(rdata1
->type
== 61);
240 REQUIRE(rdata1
->length
!= 0);
241 REQUIRE(rdata2
->length
!= 0);
243 dns_rdata_toregion(rdata1
, &r1
);
244 dns_rdata_toregion(rdata2
, &r2
);
246 return (isc_region_compare(&r1
, &r2
));
249 #endif /* RDATA_GENERIC_OPENPGPKEY_61_C */