Commit 1d58763c authored by Brian Wellington's avatar Brian Wellington
Browse files

Added dst_key_parsefilename

parent 70cd89aa
......@@ -19,11 +19,13 @@
/*
* Principal Author: Brian Wellington
* $Id: dst_api.c,v 1.35 2000/05/15 21:02:28 bwelling Exp $
* $Id: dst_api.c,v 1.36 2000/05/15 23:14:41 bwelling Exp $
*/
#include <config.h>
#include <stdlib.h>
#include <isc/buffer.h>
#include <isc/dir.h>
#include <isc/lex.h>
......@@ -773,6 +775,97 @@ dst_key_buildfilename(const dst_key_t *key, const int type, isc_buffer_t *out) {
return (ISC_R_SUCCESS);
}
isc_result_t
dst_key_parsefilename(isc_buffer_t *source, isc_mem_t *mctx, char **name,
isc_uint16_t *id, int *alg, char **suffix)
{
isc_result_t result = ISC_R_SUCCESS;
char c, str[6], *p, *endp;
isc_region_t r;
unsigned int length;
REQUIRE(source != NULL);
REQUIRE(mctx != NULL);
REQUIRE(name != NULL && *name == NULL);
REQUIRE(id != NULL);
REQUIRE(alg != NULL);
REQUIRE(suffix == NULL || *suffix == NULL);
if (isc_buffer_remaininglength(source) < 1)
return (ISC_R_UNEXPECTEDEND);
c = (char) isc_buffer_getuint8(source);
if (c != 'K') {
result = ISC_R_INVALIDFILE;
goto fail;
}
isc_buffer_remainingregion(source, &r);
p = (char *)r.base;
length = r.length;
while (length > 0 && *p != '+') {
length--;
p++;
}
if (length == 0)
return (ISC_R_UNEXPECTEDEND);
length = p - (char *) r.base;
*name = isc_mem_get(mctx, length + 1);
if (*name == NULL)
return (ISC_R_NOMEMORY);
memcpy(*name, r.base, length);
(*name)[length] = 0;
isc_buffer_forward(source, length);
if (isc_buffer_remaininglength(source) < 1 + 3 + 1 + 5) {
result = ISC_R_UNEXPECTEDEND;
goto fail;
}
c = (char) isc_buffer_getuint8(source);
if (c != '+') {
result = ISC_R_INVALIDFILE;
goto fail;
}
isc_buffer_remainingregion(source, &r);
memcpy(str, r.base, 3);
str[3] = 0;
*alg = strtol(str, &endp, 10);
if (*endp != '\0') {
result = ISC_R_INVALIDFILE;
goto fail;
}
isc_buffer_forward(source, 3);
c = (char) isc_buffer_getuint8(source);
if (c != '+') {
result = ISC_R_INVALIDFILE;
goto fail;
}
isc_buffer_remainingregion(source, &r);
memcpy(str, r.base, 5);
str[5] = 0;
*id = strtol(str, &endp, 10);
if (*endp != '\0') {
result = ISC_R_INVALIDFILE;
goto fail;
}
isc_buffer_forward(source, 5);
if (suffix == NULL)
return (ISC_R_SUCCESS);
isc_buffer_remainingregion(source, &r);
*suffix = isc_mem_get(mctx, r.length + 1);
if (*suffix == NULL) {
result = ISC_R_NOMEMORY;
goto fail;
}
if (r.length > 0)
memcpy(*suffix, r.base, r.length);
(*suffix)[r.length] = 0;
return (ISC_R_SUCCESS);
fail:
if (*name != NULL)
isc_mem_put(mctx, name, strlen(*name) + 1);
return (result);
}
/*
* dst_sig_size
* Computes the maximum size of a signature generated by the given key
......
......@@ -317,6 +317,25 @@ dst_key_buildfilename(const dst_key_t *key, const int type, isc_buffer_t *out);
* be advanced.
*/
isc_result_t
dst_key_parsefilename(isc_buffer_t *source, isc_mem_t *mctx, char **name,
isc_uint16_t *id, int *alg, char **suffix);
/*
* Parses a dst key filename into its components.
*
* Requires:
* "source" is a valid buffer
* "mctx" is a valid memory context
* "name" is not NULL and "*name" is NULL
* "id" and "alg" are not NULL
* Either "suffix" is NULL or "suffix" is not NULL and "*suffix" is NULL
*
* Ensures:
* "*name" will point to allocated memory, as will "*suffix" if suffix
* is not NULL (strlen() + 1 bytes). The current pointer in source
* will be advanced.
*/
isc_result_t
dst_sig_size(const dst_key_t *key, unsigned int *n);
/*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment