~mdw
/
catacomb
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Optionally turn off checking of keys.
[catacomb]
/
key-pack.c
diff --git
a/key-pack.c
b/key-pack.c
index
cc0f20a
..
fed144a
100644
(file)
--- a/
key-pack.c
+++ b/
key-pack.c
@@
-1,6
+1,6
@@
/* -*-c-*-
*
/* -*-c-*-
*
- * $Id
: key-pack.c,v 1.3 2004/04/08 01:36:15 mdw Exp
$
+ * $Id$
*
* Packing and unpacking key data
*
*
* Packing and unpacking key data
*
@@
-39,7
+39,7
@@
/* --- @key_pack@ --- *
*
* Arguments: @key_packdef *kp@ = pointer to packing structure
/* --- @key_pack@ --- *
*
* Arguments: @key_packdef *kp@ = pointer to packing structure
- * @key_data *
kd@ = pointer to destination key data
+ * @key_data *
*kd@ = where to put the key data pointer
* @dstr *d@ = pointer to tag string for the key data
*
* Returns: Error code, or zero.
* @dstr *d@ = pointer to tag string for the key data
*
* Returns: Error code, or zero.
@@
-47,23
+47,25
@@
* Use: Packs a key from a data structure.
*/
* Use: Packs a key from a data structure.
*/
-int key_pack(key_packdef *kp, key_data *kd, dstr *d)
+int key_pack(key_packdef *kp, key_data *
*
kd, dstr *d)
{
{
- switch (kp->
kd.
e & KF_ENCMASK) {
+ switch (kp->e & KF_ENCMASK) {
/* --- Binary and integer keys are easy --- */
/* --- Binary and integer keys are easy --- */
- case KENC_BINARY:
- kd->u.k = *(key_bin *)kp->p;
+ case KENC_BINARY: {
+ key_bin *b = kp->p;
+ *kd = key_newbinary(kp->e, b->k, b->sz);
return (0);
return (0);
+ }
case KENC_MP:
case KENC_MP:
-
kd->u.m = *(mp **)kp->p
;
+
*kd = key_newmp(kp->e, *(mp **)kp->p)
;
return (0);
case KENC_STRING:
return (0);
case KENC_STRING:
-
kd->u.p = *(char **)kp->p
;
+
*kd = key_newstring(kp->e, *(char **)kp->p)
;
return (0);
case KENC_EC:
return (0);
case KENC_EC:
-
kd->u.e = *(ec *)kp->p
;
+
*kd = key_newec(kp->e, (ec *)kp->p)
;
return (0);
/* --- Encrypted keys are a little tricky --- *
return (0);
/* --- Encrypted keys are a little tricky --- *
@@
-72,12
+74,11
@@
int key_pack(key_packdef *kp, key_data *kd, dstr *d)
*/
case KENC_ENCRYPT: {
*/
case KENC_ENCRYPT: {
- key_data kkd;
+ key_data
*
kkd;
int err = key_pack(kp->p, &kkd, d);
if (!err) {
int err = key_pack(kp->p, &kkd, d);
if (!err) {
- if (key_plock(d->buf, &kkd, kd))
- err = KERR_BADPASS;
- key_destroy(&kkd);
+ err = key_plock(kd, kkd, d->buf);
+ key_drop(kkd);
}
return (err);
}
}
return (err);
}
@@
-89,25
+90,25
@@
int key_pack(key_packdef *kp, key_data *kd, dstr *d)
key_packstruct *p;
size_t l = d->len;
key_packstruct *p;
size_t l = d->len;
-
key_structure(kd
);
+
*kd = key_newstruct(
);
DPUTC(d, '.');
for (p = kp->p; p->name; p++) {
key_data *kkd;
d->len = l + 1;
DPUTS(d, p->name);
DPUTC(d, '.');
for (p = kp->p; p->name; p++) {
key_data *kkd;
d->len = l + 1;
DPUTS(d, p->name);
- kkd = key_structcreate(kd, p->name);
- if ((err = key_pack(&p->kp, kkd, d)) != 0) {
- key_destroy(kd);
+ if ((err = key_pack(&p->kp, &kkd, d)) != 0) {
+ key_drop(*kd);
return (err);
}
return (err);
}
+ key_structsteal(*kd, p->name, kkd);
}
d->len = l;
d->buf[l] = 0;
return (0);
}
}
d->len = l;
d->buf[l] = 0;
return (0);
}
+ default:
+ abort();
}
}
-
- return (KERR_BADTYPE);
}
/* --- @key_unpack@ --- *
}
/* --- @key_unpack@ --- *
@@
-123,24
+124,21
@@
int key_pack(key_packdef *kp, key_data *kd, dstr *d)
int key_unpack(key_packdef *kp, key_data *kd, dstr *d)
{
int key_unpack(key_packdef *kp, key_data *kd, dstr *d)
{
- unsigned e = kp->
kd.
e & KF_ENCMASK;
+ unsigned e = kp->e & KF_ENCMASK;
int err;
/* --- Decrypt the encrypted key --- */
int err;
/* --- Decrypt the encrypted key --- */
- while ((kd->e & KF_ENCMASK) == KENC_ENCRYPT) {
- if (key_punlock(d->buf, kd, &kp->kd)) {
- err = KERR_BADPASS;
+ if ((kd->e & KF_ENCMASK) == KENC_ENCRYPT) {
+ if ((err = key_punlock(&kp->kd, kd, d->buf)) != 0)
goto fail;
goto fail;
- }
- kd = &kp->kd;
- kd->e |= KF_TEMP;
+ kd = kp->kd;
}
/* --- Ensure that the key has the right type --- */
if ((kd->e & KF_ENCMASK) != e) {
}
/* --- Ensure that the key has the right type --- */
if ((kd->e & KF_ENCMASK) != e) {
- err = KERR_
BAD
TYPE;
+ err = KERR_
WRONG
TYPE;
goto fail;
}
goto fail;
}
@@
-186,7
+184,7
@@
int key_unpack(key_packdef *kp, key_data *kd, dstr *d)
/* --- Find and unpack the subkey --- */
if ((kkd = key_structfind(kd, p->name)) == 0) {
/* --- Find and unpack the subkey --- */
if ((kkd = key_structfind(kd, p->name)) == 0) {
- if (!(p->kp.
kd.
e & KF_OPT)) {
+ if (!(p->kp.e & KF_OPT)) {
err = KERR_NOTFOUND;
goto tidy;
}
err = KERR_NOTFOUND;
goto tidy;
}
@@
-209,6
+207,9
@@
int key_unpack(key_packdef *kp, key_data *kd, dstr *d)
key_unpackdone(&q->kp);
goto fail;
}
key_unpackdone(&q->kp);
goto fail;
}
+
+ default:
+ abort();
}
return (0);
}
return (0);
@@
-216,8
+217,10
@@
int key_unpack(key_packdef *kp, key_data *kd, dstr *d)
/* --- Something went wrong --- */
fail:
/* --- Something went wrong --- */
fail:
- if (kd == &kp->kd)
- key_destroy(kd);
+ if (kp->kd) {
+ key_drop(kp->kd);
+ kp->kd = 0;
+ }
return (err);
}
return (err);
}
@@
-233,9
+236,11
@@
fail:
void key_unpackdone(key_packdef *kp)
{
void key_unpackdone(key_packdef *kp)
{
- if (kp->kd.e & KF_TEMP)
- key_destroy(&kp->kd);
- if ((kp->kd.e & KF_ENCMASK) == KENC_STRUCT) {
+ if (kp->kd) {
+ key_drop(kp->kd);
+ kp->kd = 0;
+ }
+ if ((kp->e & KF_ENCMASK) == KENC_STRUCT) {
key_packstruct *p;
for (p = kp->p; p->name; p++)
key_unpackdone(&p->kp);
key_packstruct *p;
for (p = kp->p; p->name; p++)
key_unpackdone(&p->kp);