{
unsigned int length;
asn1_error_code retval;
- unsigned int sum = 0;
asn1buf *buf = NULL;
+ krb5_data *d;
+
+ *code = NULL;
- if (rep == NULL) return ASN1_MISSING_FIELD;
+ if (rep == NULL)
+ return ASN1_MISSING_FIELD;
retval = asn1buf_create(&buf);
if (retval)
retval = krb5int_asn1_encode_a_thing(buf, rep, a, &length);
if (retval)
- return retval;
- sum += length;
- retval = asn12krb5_buf(buf, code);
+ goto cleanup;
+ retval = asn12krb5_buf(buf, &d);
+ if (retval)
+ goto cleanup;
+ *code = d;
+cleanup:
asn1buf_destroy(&buf);
return retval;
}
asn1_error_code asn12krb5_buf(const asn1buf *buf, krb5_data **code)
{
unsigned int i;
- *code = (krb5_data*)calloc(1,sizeof(krb5_data));
- if (*code == NULL) return ENOMEM;
- (*code)->magic = KV5M_DATA;
- (*code)->data = NULL;
- (*code)->length = 0;
- (*code)->length = asn1buf_len(buf);
- (*code)->data = (char*)malloc((((*code)->length)+1)*sizeof(char));
- if ((*code)->data == NULL) {
- free(*code);
- *code = NULL;
+ krb5_data *d;
+
+ *code = NULL;
+
+ d = calloc(1, sizeof(krb5_data));
+ if (d == NULL)
+ return ENOMEM;
+ d->length = asn1buf_len(buf);
+ d->data = malloc(d->length + 1);
+ if (d->data == NULL) {
+ free(d);
return ENOMEM;
}
- for (i=0; i < (*code)->length; i++)
- ((*code)->data)[i] = (buf->base)[((*code)->length)-i-1];
- ((*code)->data)[(*code)->length] = '\0';
+ for (i=0; i < d->length; i++)
+ d->data[i] = buf->base[d->length - i - 1];
+ d->data[d->length] = '\0';
+ d->magic = KV5M_DATA;
+ *code = d;
return 0;
}