/*
* Principal Author: Brian Wellington
- * $Id: dst_api.c,v 1.118 2004/10/01 00:10:59 marka Exp $
+ * $Id: dst_api.c,v 1.119 2004/10/14 05:55:51 marka Exp $
*/
#include <config.h>
unsigned int bits,
dns_rdataclass_t rdclass,
isc_mem_t *mctx);
-static isc_result_t read_public_key(const char *filename,
- int type,
- isc_mem_t *mctx,
- dst_key_t **keyp);
static isc_result_t write_public_key(const dst_key_t *key, int type,
const char *directory);
static isc_result_t buildfilename(dns_name_t *name,
REQUIRE(mctx != NULL);
REQUIRE(keyp != NULL && *keyp == NULL);
- result = read_public_key(filename, type, mctx, &pubkey);
+ newfilenamelen = strlen(filename) + 5;
+ newfilename = isc_mem_get(mctx, newfilenamelen);
+ if (newfilename == NULL)
+ return (ISC_R_NOMEMORY);
+ result = addsuffix(newfilename, newfilenamelen, filename, ".key");
+ INSIST(result == ISC_R_SUCCESS);
+
+ result = dst_key_read_public(newfilename, type, mctx, &pubkey);
+ isc_mem_put(mctx, newfilename, newfilenamelen);
if (result != ISC_R_SUCCESS)
return (result);
/*
* Reads a public key from disk
*/
-static isc_result_t
-read_public_key(const char *filename, int type,
- isc_mem_t *mctx, dst_key_t **keyp)
+isc_result_t
+dst_key_read_public(const char *filename, int type,
+ isc_mem_t *mctx, dst_key_t **keyp)
{
u_char rdatabuf[DST_KEY_MAXSIZE];
isc_buffer_t b;
isc_result_t ret;
dns_rdata_t rdata = DNS_RDATA_INIT;
unsigned int opt = ISC_LEXOPT_DNSMULTILINE;
- char *newfilename;
- unsigned int newfilenamelen;
dns_rdataclass_t rdclass = dns_rdataclass_in;
isc_lexspecials_t specials;
isc_uint32_t ttl;
isc_result_t result;
dns_rdatatype_t keytype;
- newfilenamelen = strlen(filename) + 5;
- newfilename = isc_mem_get(mctx, newfilenamelen);
- if (newfilename == NULL)
- return (ISC_R_NOMEMORY);
- ret = addsuffix(newfilename, newfilenamelen, filename, ".key");
- INSIST(ret == ISC_R_SUCCESS);
-
/*
* Open the file and read its formatted contents
* File format:
- * domain.name [ttl] [class] KEY <flags> <protocol> <algorithm> <key>
+ * domain.name [ttl] [class] [KEY|DNSKEY] <flags> <protocol> <algorithm> <key>
*/
/* 1500 should be large enough for any key */
isc_lex_setspecials(lex, specials);
isc_lex_setcomments(lex, ISC_LEXCOMMENT_DNSMASTERFILE);
- ret = isc_lex_openfile(lex, newfilename);
+ ret = isc_lex_openfile(lex, filename);
if (ret != ISC_R_SUCCESS)
goto cleanup;
cleanup:
if (lex != NULL)
isc_lex_destroy(&lex);
- isc_mem_put(mctx, newfilename, newfilenamelen);
-
return (ret);
}
* PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: dst.h,v 1.48 2004/06/11 00:27:01 marka Exp $ */
+/* $Id: dst.h,v 1.49 2004/10/14 05:55:52 marka Exp $ */
#ifndef DST_DST_H
#define DST_DST_H 1
* If successful, *keyp will contain a valid key.
*/
+
+isc_result_t
+dst_key_read_public(const char *filename, int type,
+ isc_mem_t *mctx, dst_key_t **keyp);
+/*
+ * Reads a public key from permanent storage. The key must be a public key.
+ *
+ * Requires:
+ * "filename" is not NULL
+ * "type" is DST_TYPE_KEY look for a KEY record otherwise DNSKEY
+ * "mctx" is a valid memory context
+ * "keyp" is not NULL and "*keyp" is NULL.
+ *
+ * Returns:
+ * ISC_R_SUCCESS
+ * DST_R_BADKEYTYPE if the key type is not the expected one
+ * ISC_R_UNEXPECTEDTOKEN if the file can not be parsed as a public key
+ * any other result indicates failure
+ *
+ * Ensures:
+ * If successful, *keyp will contain a valid key.
+ */
+
isc_result_t
dst_key_tofile(const dst_key_t *key, int type, const char *directory);
/*