int i;
char *ret;
- if (x == NULL) return(NULL);
+ if (x == NULL)
+ return(NULL);
i=i2d(x,NULL);
b=malloc(i+10);
- if (b == NULL)
- {
- ASN1err(ASN1_F_ASN1_DUP,ERR_R_MALLOC_FAILURE); return(NULL);
+ if (b == NULL) {
+ ASN1err(ASN1_F_ASN1_DUP,ERR_R_MALLOC_FAILURE);
+ return(NULL);
}
p= b;
i=i2d(x,&p);
long i;
void *ret;
- if (x == NULL) return(NULL);
+ if (x == NULL)
+ return(NULL);
i=ASN1_item_i2d(x,&b,it);
- if (b == NULL)
- {
- ASN1err(ASN1_F_ASN1_ITEM_DUP,ERR_R_MALLOC_FAILURE); return(NULL);
+ if (b == NULL) {
+ ASN1err(ASN1_F_ASN1_ITEM_DUP,ERR_R_MALLOC_FAILURE);
+ return(NULL);
}
p= b;
ret=ASN1_item_d2i(NULL,&p,i, it);
long d;
a->type=V_ASN1_ENUMERATED;
- if (a->length < (int)(sizeof(long)+1))
- {
+ if (a->length < (int)(sizeof(long)+1)) {
if (a->data != NULL)
free(a->data);
if ((a->data=(unsigned char *)malloc(sizeof(long)+1)) != NULL)
memset((char *)a->data,0,sizeof(long)+1);
}
- if (a->data == NULL)
- {
+ if (a->data == NULL) {
ASN1err(ASN1_F_ASN1_ENUMERATED_SET,ERR_R_MALLOC_FAILURE);
return(0);
}
d=v;
- if (d < 0)
- {
+ if (d < 0) {
d= -d;
a->type=V_ASN1_NEG_ENUMERATED;
}
- for (i=0; i<sizeof(long); i++)
- {
+ for (i=0; i<sizeof(long); i++) {
if (d == 0) break;
buf[i]=(int)d&0xff;
d>>=8;
else if (i != V_ASN1_ENUMERATED)
return -1;
- if (a->length > (int)sizeof(long))
- {
+ if (a->length > (int)sizeof(long)) {
/* hmm... a bit ugly */
return(0xffffffffL);
}
if (a->data == NULL)
return 0;
- for (i=0; i<a->length; i++)
- {
+ for (i=0; i<a->length; i++) {
r<<=8;
r|=(unsigned char)a->data[i];
}
ret=M_ASN1_ENUMERATED_new();
else
ret=ai;
- if (ret == NULL)
- {
+ if (ret == NULL) {
ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_NESTED_ASN1_ERROR);
goto err;
}
else ret->type=V_ASN1_ENUMERATED;
j=BN_num_bits(bn);
len=((j == 0)?0:((j/8)+1));
- if (ret->length < len+4)
- {
+ if (ret->length < len+4) {
unsigned char *new_data=realloc(ret->data, len+4);
if (!new_data)
{
* field so make first two fields 00 to 99
*/
if (l < 13) goto err;
- for (i=0; i<7; i++)
- {
+ for (i=0; i<7; i++) {
if ((i == 6) && ((a[o] == 'Z') ||
(a[o] == '+') || (a[o] == '-')))
{ i++; break; }
if (a[o] == 'Z')
o++;
- else if ((a[o] == '+') || (a[o] == '-'))
- {
+ else if ((a[o] == '+') || (a[o] == '-')) {
o++;
if (o+4 > l) goto err;
- for (i=7; i<9; i++)
- {
+ for (i=7; i<9; i++) {
if ((a[o] < '0') || (a[o] > '9')) goto err;
n= a[o]-'0';
o++;
if ((n < min[i]) || (n > max[i])) goto err;
o++;
}
- }
- else
- {
+ } else {
/* Missing time zone information. */
goto err;
}
t.type=V_ASN1_GENERALIZEDTIME;
t.length=strlen(str);
t.data=(unsigned char *)str;
- if (ASN1_GENERALIZEDTIME_check(&t))
- {
- if (s != NULL)
- {
+ if (ASN1_GENERALIZEDTIME_check(&t)) {
+ if (s != NULL) {
if (!ASN1_STRING_set((ASN1_STRING *)s,
(unsigned char *)str,t.length))
return 0;
if (ts == NULL)
return(NULL);
- if (offset_day || offset_sec)
- {
+ if (offset_day || offset_sec) {
if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec))
return NULL;
}
p=(char *)s->data;
- if ((p == NULL) || ((size_t)s->length < len))
- {
+ if ((p == NULL) || ((size_t)s->length < len)) {
p=malloc(len);
- if (p == NULL)
- {
+ if (p == NULL) {
ASN1err(ASN1_F_ASN1_GENERALIZEDTIME_ADJ,
ERR_R_MALLOC_FAILURE);
return(NULL);
BIO *b;
int ret;
- if ((b=BIO_new(BIO_s_file())) == NULL)
- {
+ if ((b=BIO_new(BIO_s_file())) == NULL) {
ASN1err(ASN1_F_ASN1_I2D_FP,ERR_R_BUF_LIB);
return(0);
}
n=i2d(x,NULL);
b=(char *)malloc(n);
- if (b == NULL)
- {
+ if (b == NULL) {
ASN1err(ASN1_F_ASN1_I2D_BIO,ERR_R_MALLOC_FAILURE);
return(0);
}
p=(unsigned char *)b;
i2d(x,&p);
- for (;;)
- {
+ for (;;) {
i=BIO_write(out,&(b[j]),n);
if (i == n) break;
- if (i <= 0)
- {
+ if (i <= 0) {
ret=0;
break;
}
BIO *b;
int ret;
- if ((b=BIO_new(BIO_s_file())) == NULL)
- {
+ if ((b=BIO_new(BIO_s_file())) == NULL) {
ASN1err(ASN1_F_ASN1_ITEM_I2D_FP,ERR_R_BUF_LIB);
return(0);
}
int i,j=0,n,ret=1;
n = ASN1_item_i2d(x, &b, it);
- if (b == NULL)
- {
+ if (b == NULL) {
ASN1err(ASN1_F_ASN1_ITEM_I2D_BIO,ERR_R_MALLOC_FAILURE);
return(0);
}
- for (;;)
- {
+ for (;;) {
i=BIO_write(out,&(b[j]),n);
if (i == n) break;
- if (i <= 0)
- {
+ if (i <= 0) {
ret=0;
break;
}
int neg, ret;
/* Compare signs */
neg = x->type & V_ASN1_NEG;
- if (neg != (y->type & V_ASN1_NEG))
- {
+ if (neg != (y->type & V_ASN1_NEG)) {
if (neg)
return -1;
else
neg=a->type & V_ASN1_NEG;
if (a->length == 0)
ret=1;
- else
- {
+ else {
ret=a->length;
i=a->data[0];
if (!neg && (i > 127)) {
unsigned char *to,*s;
int i;
- if ((a == NULL) || ((*a) == NULL))
- {
+ if ((a == NULL) || ((*a) == NULL)) {
if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL);
ret->type=V_ASN1_INTEGER;
}
/* We must malloc stuff, even for 0 bytes otherwise it
* signifies a missing NULL parameter. */
s=(unsigned char *)malloc((int)len+1);
- if (s == NULL)
- {
+ if (s == NULL) {
i=ERR_R_MALLOC_FAILURE;
goto err;
}
* tolerate it.
*/
ret->type=V_ASN1_INTEGER;
-} else if (*p & 0x80) /* a negative number */
- {
+ } else if (*p & 0x80) /* a negative number */ {
ret->type=V_ASN1_NEG_INTEGER;
if ((*p == 0xff) && (len != 1)) {
p++;
len--;
- }
+ }
i = len;
p += i - 1;
to += i - 1;
*(to--) = 0;
i--;
p--;
- }
+ }
/* Special case: if all zeros then the number will be of
* the form FF followed by n zero bytes: this corresponds to
* 1 followed by n zero bytes. We've already written n zeros
*s = 1;
s[len] = 0;
len++;
- } else {
+ } else {
*(to--) = (*(p--) ^ 0xff) + 1;
i--;
for(;i > 0; i--) *(to--) = *(p--) ^ 0xff;
- }
-} else {
+ }
+ } else {
ret->type=V_ASN1_INTEGER;
- if ((*p == 0) && (len != 1))
- {
+ if ((*p == 0) && (len != 1)) {
p++;
len--;
}
memcpy(s,p,(int)len);
-}
+ }
if (ret->data != NULL) free(ret->data);
ret->data=s;
int inf,tag,xclass;
int i;
- if ((a == NULL) || ((*a) == NULL))
- {
+ if ((a == NULL) || ((*a) == NULL)) {
if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL);
ret->type=V_ASN1_INTEGER;
- }
- else
+ } else
ret=(*a);
p= *pp;
inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
- if (inf & 0x80)
- {
+ if (inf & 0x80) {
i=ASN1_R_BAD_OBJECT_HEADER;
goto err;
}
- if (tag != V_ASN1_INTEGER)
- {
+ if (tag != V_ASN1_INTEGER) {
i=ASN1_R_EXPECTING_AN_INTEGER;
goto err;
}
/* We must malloc stuff, even for 0 bytes otherwise it
* signifies a missing NULL parameter. */
s=(unsigned char *)malloc((int)len+1);
- if (s == NULL)
- {
+ if (s == NULL) {
i=ERR_R_MALLOC_FAILURE;
goto err;
}
ret->type=V_ASN1_INTEGER;
if(len) {
- if ((*p == 0) && (len != 1))
- {
+ if ((*p == 0) && (len != 1)) {
p++;
len--;
}
memcpy(s,p,(int)len);
p+=len;
-}
+ }
if (ret->data != NULL) free(ret->data);
ret->data=s;
long d;
a->type=V_ASN1_INTEGER;
- if (a->length < (int)(sizeof(long)+1))
- {
+ if (a->length < (int)(sizeof(long)+1)) {
if (a->data != NULL)
free(a->data);
if ((a->data=(unsigned char *)malloc(sizeof(long)+1)) != NULL)
memset((char *)a->data,0,sizeof(long)+1);
}
- if (a->data == NULL)
- {
+ if (a->data == NULL) {
ASN1err(ASN1_F_ASN1_INTEGER_SET,ERR_R_MALLOC_FAILURE);
return(0);
}
d=v;
- if (d < 0)
- {
+ if (d < 0) {
d= -d;
a->type=V_ASN1_NEG_INTEGER;
}
- for (i=0; i<sizeof(long); i++)
- {
+ for (i=0; i<sizeof(long); i++) {
if (d == 0) break;
buf[i]=(int)d&0xff;
d>>=8;
else if (i != V_ASN1_INTEGER)
return -1;
- if (a->length > (int)sizeof(long))
- {
+ if (a->length > (int)sizeof(long)) {
/* hmm... a bit ugly, return all ones */
return -1;
}
if (a->data == NULL)
return 0;
- for (i=0; i<a->length; i++)
- {
+ for (i=0; i<a->length; i++) {
r<<=8;
r|=(unsigned char)a->data[i];
}
ret=M_ASN1_INTEGER_new();
else
ret=ai;
- if (ret == NULL)
- {
+ if (ret == NULL) {
ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_NESTED_ASN1_ERROR);
goto err;
}
else ret->type=V_ASN1_INTEGER;
j=BN_num_bits(bn);
len=((j == 0)?0:((j/8)+1));
- if (ret->length < len+4)
- {
+ if (ret->length < len+4) {
unsigned char *new_data=realloc(ret->data, len+4);
- if (!new_data)
- {
+ if (!new_data) {
ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_MALLOC_FAILURE);
goto err;
}
}
ret->length=BN_bn2bin(bn,ret->data);
/* Correct zero case */
- if(!ret->length)
- {
+ if(!ret->length) {
ret->data[0] = 0;
ret->length = 1;
}
p=buf;
c= *(p++);
num--;
- if ((c >= '0') && (c <= '2'))
- {
+ if ((c >= '0') && (c <= '2')) {
first= c-'0';
- }
- else
- {
+ } else {
ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_FIRST_NUM_TOO_LARGE);
goto err;
}
- if (num <= 0)
- {
+ if (num <= 0) {
ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_MISSING_SECOND_NUMBER);
goto err;
}
c= *(p++);
num--;
- for (;;)
- {
+ for (;;) {
if (num <= 0) break;
- if ((c != '.') && (c != ' '))
- {
+ if ((c != '.') && (c != ' ')) {
ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_SEPARATOR);
goto err;
}
l=0;
use_bn = 0;
- for (;;)
- {
+ for (;;) {
if (num <= 0) break;
num--;
c= *(p++);
if ((c == ' ') || (c == '.'))
break;
- if ((c < '0') || (c > '9'))
- {
+ if ((c < '0') || (c > '9')) {
ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_DIGIT);
goto err;
}
- if (!use_bn && l >= ((ULONG_MAX - 80) / 10L))
- {
+ if (!use_bn && l >= ((ULONG_MAX - 80) / 10L)) {
use_bn = 1;
if (!bl)
bl = BN_new();
if (!bl || !BN_set_word(bl, l))
goto err;
}
- if (use_bn)
- {
+ if (use_bn) {
if (!BN_mul_word(bl, 10L)
|| !BN_add_word(bl, c-'0'))
goto err;
else
l=l*10L+(long)(c-'0');
}
- if (len == 0)
- {
- if ((first < 2) && (l >= 40))
- {
+ if (len == 0) {
+ if ((first < 2) && (l >= 40)) {
ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_SECOND_NUMBER_TOO_LARGE);
goto err;
}
- if (use_bn)
- {
+ if (use_bn) {
if (!BN_add_word(bl, first * 40))
goto err;
}
l+=(long)first*40;
}
i=0;
- if (use_bn)
- {
+ if (use_bn) {
int blsize;
blsize = BN_num_bits(bl);
blsize = (blsize + 6)/7;
- if (blsize > tmpsize)
- {
+ if (blsize > tmpsize) {
if (tmp != ftmp)
free(tmp);
tmpsize = blsize + 32;
}
while(blsize--)
tmp[i++] = (unsigned char)BN_div_word(bl, 0x80L);
- }
- else
- {
+ } else {
- for (;;)
- {
+ for (;;) {
tmp[i++]=(unsigned char)l&0x7f;
l>>=7L;
if (l == 0L) break;
}
}
- if (out != NULL)
- {
- if (len+i > olen)
- {
+ if (out != NULL) {
+ if (len+i > olen) {
ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_BUFFER_TOO_SMALL);
goto err;
}
if ((a == NULL) || (a->data == NULL))
return(BIO_write(bp,"NULL",4));
i=i2t_ASN1_OBJECT(buf,sizeof buf,a);
- if (i > (int)(sizeof(buf) - 1))
- {
+ if (i > (int)(sizeof(buf) - 1)) {
p = malloc(i + 1);
if (!p)
return -1;
ASN1_OBJECT *ret = NULL;
p= *pp;
inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
- if (inf & 0x80)
- {
+ if (inf & 0x80) {
i=ASN1_R_BAD_OBJECT_HEADER;
goto err;
}
- if (tag != V_ASN1_OBJECT)
- {
+ if (tag != V_ASN1_OBJECT) {
i=ASN1_R_EXPECTING_AN_OBJECT;
goto err;
}
/* Sanity check OID encoding: can't have leading 0x80 in
* subidentifiers, see: X.690 8.19.2
*/
- for (i = 0, p = *pp; i < len; i++, p++)
- {
- if (*p == 0x80 && (!i || !(p[-1] & 0x80)))
- {
+ for (i = 0, p = *pp; i < len; i++, p++) {
+ if (*p == 0x80 && (!i || !(p[-1] & 0x80))) {
ASN1err(ASN1_F_C2I_ASN1_OBJECT,ASN1_R_INVALID_OBJECT_ENCODING);
return NULL;
}
/* only the ASN1_OBJECTs from the 'table' will have values
* for ->sn or ->ln */
if ((a == NULL) || ((*a) == NULL) ||
- !((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC))
- {
+ !((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC)) {
if ((ret=ASN1_OBJECT_new()) == NULL) return(NULL);
}
else ret=(*a);
data = (unsigned char *)ret->data;
ret->data = NULL;
/* once detached we can change it */
- if ((data == NULL) || (ret->length < len))
- {
+ if ((data == NULL) || (ret->length < len)) {
ret->length=0;
if (data != NULL) free(data);
data=(unsigned char *)malloc(len ? (int)len : 1);
- if (data == NULL)
- { i=ERR_R_MALLOC_FAILURE; goto err; }
+ if (data == NULL) { i=ERR_R_MALLOC_FAILURE; goto err; }
ret->flags|=ASN1_OBJECT_FLAG_DYNAMIC_DATA;
}
memcpy(data,p,(int)len);
ASN1_OBJECT *ret;
ret=(ASN1_OBJECT *)malloc(sizeof(ASN1_OBJECT));
- if (ret == NULL)
- {
+ if (ret == NULL) {
ASN1err(ASN1_F_ASN1_OBJECT_NEW,ERR_R_MALLOC_FAILURE);
return(NULL);
}
void ASN1_OBJECT_free(ASN1_OBJECT *a)
{
if (a == NULL) return;
- if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS)
- {
+ if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS) {
#ifndef CONST_STRICT /* disable purely for compile-time strict const checking. Doing this on a "real" compile will cause memory leaks */
if (a->sn != NULL) free((void *)a->sn);
if (a->ln != NULL) free((void *)a->ln);
#endif
a->sn=a->ln=NULL;
}
- if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA)
- {
+ if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA) {
if (a->data != NULL) free((void *)a->data);
a->data=NULL;
a->length=0;
if (len <= 0) len= -1;
if (s == NULL) return(V_ASN1_PRINTABLESTRING);
- while ((*s) && (len-- != 0))
- {
+ while ((*s) && (len-- != 0)) {
c= *(s++);
if (!( ((c >= 'a') && (c <= 'z')) ||
((c >= 'A') && (c <= 'Z')) ||
if (s->type != V_ASN1_UNIVERSALSTRING) return(0);
if ((s->length%4) != 0) return(0);
p=s->data;
- for (i=0; i<s->length; i+=4)
- {
+ for (i=0; i<s->length; i+=4) {
if ((p[0] != '\0') || (p[1] != '\0') || (p[2] != '\0'))
break;
else
}
if (i < s->length) return(0);
p=s->data;
- for (i=3; i<s->length; i+=4)
- {
+ for (i=3; i<s->length; i+=4) {
*(p++)=s->data[i];
}
*(p)='\0';
{
EVP_MD_CTX ctx;
EVP_MD_CTX_init(&ctx);
- if (!EVP_DigestSignInit(&ctx, NULL, type, NULL, pkey))
- {
+ if (!EVP_DigestSignInit(&ctx, NULL, type, NULL, pkey)) {
EVP_MD_CTX_cleanup(&ctx);
return 0;
}
type = EVP_MD_CTX_md(ctx);
pkey = EVP_PKEY_CTX_get0_pkey(ctx->pctx);
- if (!type || !pkey)
- {
+ if (!type || !pkey) {
ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ASN1_R_CONTEXT_NOT_INITIALISED);
return 0;
}
- if (pkey->ameth->item_sign)
- {
+ if (pkey->ameth->item_sign) {
rv = pkey->ameth->item_sign(ctx, it, asn, algor1, algor2,
signature);
if (rv == 1)
else
rv = 2;
- if (rv == 2)
- {
- if (type->flags & EVP_MD_FLAG_PKEY_METHOD_SIGNATURE)
- {
+ if (rv == 2) {
+ if (type->flags & EVP_MD_FLAG_PKEY_METHOD_SIGNATURE) {
if (!pkey->ameth ||
!OBJ_find_sigid_by_algs(&signid,
EVP_MD_nid(type),
- pkey->ameth->pkey_id))
- {
+ pkey->ameth->pkey_id)) {
ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX,
ASN1_R_DIGEST_AND_KEY_TYPE_NOT_SUPPORTED);
return 0;
inl=ASN1_item_i2d(asn,&buf_in, it);
outll=outl=EVP_PKEY_size(pkey);
buf_out=malloc((unsigned int)outl);
- if ((buf_in == NULL) || (buf_out == NULL))
- {
+ if ((buf_in == NULL) || (buf_out == NULL)) {
outl=0;
ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX,ERR_R_MALLOC_FAILURE);
goto err;
}
if (!EVP_DigestSignUpdate(ctx, buf_in, inl)
- || !EVP_DigestSignFinal(ctx, buf_out, &outl))
- {
+ || !EVP_DigestSignFinal(ctx, buf_out, &outl)) {
outl=0;
ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX,ERR_R_EVP_LIB);
goto err;
signature->flags|=ASN1_STRING_FLAG_BITS_LEFT;
err:
EVP_MD_CTX_cleanup(ctx);
- if (buf_in != NULL)
- { OPENSSL_cleanse((char *)buf_in,(unsigned int)inl); free(buf_in); }
- if (buf_out != NULL)
- { OPENSSL_cleanse((char *)buf_out,outll); free(buf_out); }
+ if (buf_in != NULL) {
+ OPENSSL_cleanse((char *)buf_in,(unsigned int)inl); free(buf_in);
+ }
+ if (buf_out != NULL) {
+ OPENSSL_cleanse((char *)buf_out,outll); free(buf_out);
+ }
return(outl);
}
if(indent < 0) indent = 0;
outlen = indent;
if(!do_indent(io_ch, arg, indent)) return -1;
- switch (flags & XN_FLAG_SEP_MASK)
- {
+ switch (flags & XN_FLAG_SEP_MASK) {
case XN_FLAG_SEP_MULTILINE:
sep_dn = "\n";
sep_dn_len = 1;
#ifndef OPENSSL_NO_FP_API
int X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent, unsigned long flags)
{
- if(flags == XN_FLAG_COMPAT)
- {
+ if(flags == XN_FLAG_COMPAT) {
BIO *btmp;
int ret;
btmp = BIO_new_fp(fp, BIO_NOCLOSE);
int i, last_nid = -1;
for (tmp = tbl_standard, i = 0;
- i < sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE); i++, tmp++)
- {
- if (tmp->nid < last_nid)
- {
- last_nid = 0;
- break;
- }
- last_nid = tmp->nid;
+ i < sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE); i++, tmp++) {
+ if (tmp->nid < last_nid) {
+ last_nid = 0;
+ break;
}
+ last_nid = tmp->nid;
+ }
- if (last_nid != 0)
- {
+ if (last_nid != 0) {
printf("Table order OK\n");
exit(0);
- }
+ }
for (tmp = tbl_standard, i = 0;
- i < sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE); i++, tmp++)
- printf("Index %d, NID %d, Name=%s\n", i, tmp->nid,
- OBJ_nid2ln(tmp->nid));
+ i < sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE); i++, tmp++) {
+ printf("Index %d, NID %d, Name=%s\n", i, tmp->nid,
+ OBJ_nid2ln(tmp->nid));
+ }
}
struct tm data;
ts=OPENSSL_gmtime(&t,&data);
- if (ts == NULL)
- {
+ if (ts == NULL) {
ASN1err(ASN1_F_ASN1_TIME_ADJ, ASN1_R_ERROR_GETTING_TIME);
return NULL;
}
- if (offset_day || offset_sec)
- {
+ if (offset_day || offset_sec) {
if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec))
return NULL;
}
if (!ASN1_TIME_check(t)) return NULL;
- if (!out || !*out)
- {
+ if (!out || !*out) {
if (!(ret = ASN1_GENERALIZEDTIME_new ()))
return NULL;
if (out) *out = ret;
else ret = *out;
/* If already GeneralizedTime just copy across */
- if (t->type == V_ASN1_GENERALIZEDTIME)
- {
+ if (t->type == V_ASN1_GENERALIZEDTIME) {
if(!ASN1_STRING_set(ret, t->data, t->length))
return NULL;
return ret;
t.type = V_ASN1_UTCTIME;
- if (!ASN1_TIME_check(&t))
- {
+ if (!ASN1_TIME_check(&t)) {
t.type = V_ASN1_GENERALIZEDTIME;
if (!ASN1_TIME_check(&t))
return 0;
void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value)
{
- if (a->value.ptr != NULL)
- {
+ if (a->value.ptr != NULL) {
ASN1_TYPE **tmp_a = &a;
ASN1_primitive_free((ASN1_VALUE **)tmp_a, NULL);
}
int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value)
{
- if (!value || (type == V_ASN1_BOOLEAN))
- {
+ if (!value || (type == V_ASN1_BOOLEAN)) {
void *p = (void *)value;
ASN1_TYPE_set(a, type, p);
- }
- else if (type == V_ASN1_OBJECT)
- {
+ } else if (type == V_ASN1_OBJECT) {
ASN1_OBJECT *odup;
odup = OBJ_dup(value);
if (!odup)
return 0;
ASN1_TYPE_set(a, type, odup);
- }
- else
- {
+ } else {
ASN1_STRING *sdup;
sdup = ASN1_STRING_dup(value);
if (!sdup)
if (!a || !b || a->type != b->type) return -1;
- switch (a->type)
- {
+ switch (a->type) {
case V_ASN1_OBJECT:
result = OBJ_cmp(a->value.object, b->value.object);
break;
ret=(ASN1_UTCTIME *)d2i_ASN1_bytes((ASN1_STRING **)a,pp,length,
V_ASN1_UTCTIME,V_ASN1_UNIVERSAL);
- if (ret == NULL)
- {
+ if (ret == NULL) {
ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ERR_R_NESTED_ASN1_ERROR);
return(NULL);
}
- if (!ASN1_UTCTIME_check(ret))
- {
+ if (!ASN1_UTCTIME_check(ret)) {
ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ASN1_R_INVALID_TIME_FORMAT);
goto err;
}
o=0;
if (l < 11) goto err;
- for (i=0; i<6; i++)
- {
+ for (i=0; i<6; i++) {
if ((i == 5) && ((a[o] == 'Z') ||
- (a[o] == '+') || (a[o] == '-')))
- { i++; break; }
+ (a[o] == '+') || (a[o] == '-'))) {
+ i++;
+ break;
+ }
if ((a[o] < '0') || (a[o] > '9')) goto err;
n= a[o]-'0';
if (++o > l) goto err;
}
if (a[o] == 'Z')
o++;
- else if ((a[o] == '+') || (a[o] == '-'))
- {
+ else if ((a[o] == '+') || (a[o] == '-')) {
o++;
if (o+4 > l) goto err;
- for (i=6; i<8; i++)
- {
+ for (i=6; i<8; i++) {
if ((a[o] < '0') || (a[o] > '9')) goto err;
n= a[o]-'0';
o++;
t.type=V_ASN1_UTCTIME;
t.length=strlen(str);
t.data=(unsigned char *)str;
- if (ASN1_UTCTIME_check(&t))
- {
- if (s != NULL)
- {
+ if (ASN1_UTCTIME_check(&t)) {
+ if (s != NULL) {
if (!ASN1_STRING_set((ASN1_STRING *)s,
(unsigned char *)str,t.length))
return 0;
s->type = V_ASN1_UTCTIME;
}
return(1);
- }
- else
+ } else
return(0);
}
if (ts == NULL)
return(NULL);
- if (offset_day || offset_sec)
- {
+ if (offset_day || offset_sec) {
if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec))
return NULL;
}
return NULL;
p=(char *)s->data;
- if ((p == NULL) || ((size_t)s->length < len))
- {
+ if ((p == NULL) || ((size_t)s->length < len)) {
p=malloc(len);
- if (p == NULL)
- {
+ if (p == NULL) {
ASN1err(ASN1_F_ASN1_UTCTIME_ADJ,ERR_R_MALLOC_FAILURE);
return(NULL);
}
if (s->data[12] == 'Z')
offset=0;
- else
- {
+ else {
offset = g2(s->data+13)*60+g2(s->data+15);
if (s->data[12] == '-')
offset = -offset;
tm.tm_sec=g2(s->data+10);
if(s->data[12] == 'Z')
offset=0;
- else
- {
+ else {
offset=g2(s->data+13)*60+g2(s->data+15);
if(s->data[12] == '-')
offset= -offset;
int mdnid, pknid;
- if (!pkey)
- {
+ if (!pkey) {
ASN1err(ASN1_F_ASN1_ITEM_VERIFY, ERR_R_PASSED_NULL_PARAMETER);
return -1;
}
EVP_MD_CTX_init(&ctx);
/* Convert signature OID into digest and public key OIDs */
- if (!OBJ_find_sigid_algs(OBJ_obj2nid(a->algorithm), &mdnid, &pknid))
- {
+ if (!OBJ_find_sigid_algs(OBJ_obj2nid(a->algorithm), &mdnid, &pknid)) {
ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM);
goto err;
}
- if (mdnid == NID_undef)
- {
- if (!pkey->ameth || !pkey->ameth->item_verify)
- {
+ if (mdnid == NID_undef) {
+ if (!pkey->ameth || !pkey->ameth->item_verify) {
ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM);
goto err;
}
if (ret != 2)
goto err;
ret = -1;
- }
- else
- {
+ } else {
const EVP_MD *type;
type=EVP_get_digestbynid(mdnid);
- if (type == NULL)
- {
+ if (type == NULL) {
ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM);
goto err;
}
/* Check public key OID matches public key type */
- if (EVP_PKEY_type(pknid) != pkey->ameth->pkey_id)
- {
+ if (EVP_PKEY_type(pknid) != pkey->ameth->pkey_id) {
ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ASN1_R_WRONG_PUBLIC_KEY_TYPE);
goto err;
}
- if (!EVP_DigestVerifyInit(&ctx, NULL, type, NULL, pkey))
- {
+ if (!EVP_DigestVerifyInit(&ctx, NULL, type, NULL, pkey)) {
ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_EVP_LIB);
ret=0;
goto err;
inl = ASN1_item_i2d(asn, &buf_in, it);
- if (buf_in == NULL)
- {
+ if (buf_in == NULL) {
ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_MALLOC_FAILURE);
goto err;
}
- if (!EVP_DigestVerifyUpdate(&ctx,buf_in,inl))
- {
+ if (!EVP_DigestVerifyUpdate(&ctx,buf_in,inl)) {
ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_EVP_LIB);
ret=0;
goto err;
free(buf_in);
if (EVP_DigestVerifyFinal(&ctx,signature->data,
- (size_t)signature->length) <= 0)
- {
+ (size_t)signature->length) <= 0) {
ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_EVP_LIB);
ret=0;
goto err;
EVP_PKEY_ASN1_METHOD tmp;
const EVP_PKEY_ASN1_METHOD *t = &tmp, **ret;
tmp.pkey_id = type;
- if (app_methods)
- {
+ if (app_methods) {
int idx;
idx = sk_EVP_PKEY_ASN1_METHOD_find(app_methods, &tmp);
if (idx >= 0)
{
const EVP_PKEY_ASN1_METHOD *t;
- for (;;)
- {
+ for (;;) {
t = pkey_asn1_find(type);
if (!t || !(t->pkey_flags & ASN1_PKEY_ALIAS))
break;
type = t->pkey_base_id;
}
- if (pe)
- {
+ if (pe) {
#ifndef OPENSSL_NO_ENGINE
ENGINE *e;
/* type will contain the final unaliased type */
e = ENGINE_get_pkey_asn1_meth_engine(type);
- if (e)
- {
+ if (e) {
*pe = e;
return ENGINE_get_pkey_asn1_meth(e, type);
}
const EVP_PKEY_ASN1_METHOD *ameth;
if (len == -1)
len = strlen(str);
- if (pe)
- {
+ if (pe) {
#ifndef OPENSSL_NO_ENGINE
ENGINE *e;
ameth = ENGINE_pkey_asn1_find_str(&e, str, len);
- if (ameth)
- {
+ if (ameth) {
/* Convert structural into
* functional reference
*/
#endif
*pe = NULL;
}
- for (i = 0; i < EVP_PKEY_asn1_get_count(); i++)
- {
+ for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) {
ameth = EVP_PKEY_asn1_get0(i);
if (ameth->pkey_flags & ASN1_PKEY_ALIAS)
continue;
int EVP_PKEY_asn1_add0(const EVP_PKEY_ASN1_METHOD *ameth)
{
- if (app_methods == NULL)
- {
+ if (app_methods == NULL) {
app_methods = sk_EVP_PKEY_ASN1_METHOD_new(ameth_cmp);
if (!app_methods)
return 0;
ameth->pkey_base_id = id;
ameth->pkey_flags = flags | ASN1_PKEY_DYNAMIC;
- if (info)
- {
+ if (info) {
ameth->info = BUF_strdup(info);
if (!ameth->info)
goto err;
else
ameth->info = NULL;
- if (pem_str)
- {
+ if (pem_str) {
ameth->pem_str = BUF_strdup(pem_str);
if (!ameth->pem_str)
goto err;
void EVP_PKEY_asn1_free(EVP_PKEY_ASN1_METHOD *ameth)
{
- if (ameth && (ameth->pkey_flags & ASN1_PKEY_DYNAMIC))
- {
+ if (ameth && (ameth->pkey_flags & ASN1_PKEY_DYNAMIC)) {
if (ameth->pem_str)
free(ameth->pem_str);
if (ameth->info)
{
#ifndef OPENSSL_NO_ERR
- if (ERR_func_error_string(ASN1_str_functs[0].error) == NULL)
- {
+ if (ERR_func_error_string(ASN1_str_functs[0].error) == NULL) {
ERR_load_strings(0,ASN1_str_functs);
ERR_load_strings(0,ASN1_str_reasons);
}
if (CONF_parse_list(str, ',', 1, asn1_cb, &asn1_tags) != 0)
return NULL;
- if ((asn1_tags.utype == V_ASN1_SEQUENCE) || (asn1_tags.utype == V_ASN1_SET))
- {
- if (!cnf)
- {
+ if ((asn1_tags.utype == V_ASN1_SEQUENCE) || (asn1_tags.utype == V_ASN1_SET)) {
+ if (!cnf) {
ASN1err(ASN1_F_ASN1_GENERATE_V3, ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG);
return NULL;
}
cpy_start = orig_der;
/* Do we need IMPLICIT tagging? */
- if (asn1_tags.imp_tag != -1)
- {
+ if (asn1_tags.imp_tag != -1) {
/* If IMPLICIT we will replace the underlying tag */
/* Skip existing tag+len */
r = ASN1_get_object(&cpy_start, &hdr_len, &hdr_tag, &hdr_class, cpy_len);
* original length and constructed flag should be
* consistent.
*/
- if (r & 0x1)
- {
+ if (r & 0x1) {
/* Indefinite length constructed */
hdr_constructed = 2;
hdr_len = 0;
/* Work out length in any EXPLICIT, starting from end */
- for(i = 0, etmp = asn1_tags.exp_list + asn1_tags.exp_count - 1; i < asn1_tags.exp_count; i++, etmp--)
- {
+ for(i = 0, etmp = asn1_tags.exp_list + asn1_tags.exp_count - 1; i < asn1_tags.exp_count; i++, etmp--) {
/* Content length: number of content octets + any padding */
len += etmp->exp_pad;
etmp->exp_len = len;
/* Output explicit tags first */
- for (i = 0, etmp = asn1_tags.exp_list; i < asn1_tags.exp_count; i++, etmp++)
- {
+ for (i = 0, etmp = asn1_tags.exp_list; i < asn1_tags.exp_count; i++, etmp++) {
ASN1_put_object(&p, etmp->exp_constructed, etmp->exp_len,
etmp->exp_tag, etmp->exp_class);
if (etmp->exp_pad)
/* If IMPLICIT, output tag */
- if (asn1_tags.imp_tag != -1)
- {
+ if (asn1_tags.imp_tag != -1) {
if (asn1_tags.imp_class == V_ASN1_UNIVERSAL
&& (asn1_tags.imp_tag == V_ASN1_SEQUENCE
|| asn1_tags.imp_tag == V_ASN1_SET) )
int tmp_tag, tmp_class;
- for(i = 0, p = elem; i < len; p++, i++)
- {
+ for(i = 0, p = elem; i < len; p++, i++) {
/* Look for the ':' in name value pairs */
- if (*p == ':')
- {
+ if (*p == ':') {
vstart = p + 1;
vlen = len - (vstart - elem);
len = p - elem;
utype = asn1_str2tag(elem, len);
- if (utype == -1)
- {
+ if (utype == -1) {
ASN1err(ASN1_F_ASN1_CB, ASN1_R_UNKNOWN_TAG);
ERR_add_error_data(2, "tag=", elem);
return -1;
}
/* If this is not a modifier mark end of string and exit */
- if (!(utype & ASN1_GEN_FLAG))
- {
+ if (!(utype & ASN1_GEN_FLAG)) {
arg->utype = utype;
arg->str = vstart;
/* If no value and not end of string, error */
- if (!vstart && elem[len])
- {
+ if (!vstart && elem[len]) {
ASN1err(ASN1_F_ASN1_CB, ASN1_R_MISSING_VALUE);
return -1;
}
return 0;
}
- switch(utype)
- {
+ switch(utype) {
- case ASN1_GEN_FLAG_IMP:
+ case ASN1_GEN_FLAG_IMP:
/* Check for illegal multiple IMPLICIT tagging */
- if (arg->imp_tag != -1)
- {
+ if (arg->imp_tag != -1) {
ASN1err(ASN1_F_ASN1_CB, ASN1_R_ILLEGAL_NESTED_TAGGING);
return -1;
}
return -1;
break;
- case ASN1_GEN_FLAG_EXP:
+ case ASN1_GEN_FLAG_EXP:
if (!parse_tagging(vstart, vlen, &tmp_tag, &tmp_class))
return -1;
return -1;
break;
- case ASN1_GEN_FLAG_SEQWRAP:
+ case ASN1_GEN_FLAG_SEQWRAP:
if (!append_exp(arg, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL, 1, 0, 1))
return -1;
break;
- case ASN1_GEN_FLAG_SETWRAP:
+ case ASN1_GEN_FLAG_SETWRAP:
if (!append_exp(arg, V_ASN1_SET, V_ASN1_UNIVERSAL, 1, 0, 1))
return -1;
break;
- case ASN1_GEN_FLAG_BITWRAP:
+ case ASN1_GEN_FLAG_BITWRAP:
if (!append_exp(arg, V_ASN1_BIT_STRING, V_ASN1_UNIVERSAL, 0, 1, 1))
return -1;
break;
- case ASN1_GEN_FLAG_OCTWRAP:
+ case ASN1_GEN_FLAG_OCTWRAP:
if (!append_exp(arg, V_ASN1_OCTET_STRING, V_ASN1_UNIVERSAL, 0, 0, 1))
return -1;
break;
- case ASN1_GEN_FLAG_FORMAT:
+ case ASN1_GEN_FLAG_FORMAT:
if (!strncmp(vstart, "ASCII", 5))
arg->format = ASN1_GEN_FORMAT_ASCII;
else if (!strncmp(vstart, "UTF8", 4))
arg->format = ASN1_GEN_FORMAT_HEX;
else if (!strncmp(vstart, "BITLIST", 7))
arg->format = ASN1_GEN_FORMAT_BITLIST;
- else
- {
+ else {
ASN1err(ASN1_F_ASN1_CB, ASN1_R_UNKOWN_FORMAT);
return -1;
}
/* Check we haven't gone past max length: should be impossible */
if (eptr && *eptr && (eptr > vstart + vlen))
return 0;
- if (tag_num < 0)
- {
+ if (tag_num < 0) {
ASN1err(ASN1_F_PARSE_TAGGING, ASN1_R_INVALID_NUMBER);
return 0;
}
vlen -= eptr - vstart;
else
vlen = 0;
- if (vlen)
- {
- switch (*eptr)
- {
+ if (vlen) {
+ switch (*eptr) {
- case 'U':
+ case 'U':
*pclass = V_ASN1_UNIVERSAL;
break;
- case 'A':
+ case 'A':
*pclass = V_ASN1_APPLICATION;
break;
- case 'P':
+ case 'P':
*pclass = V_ASN1_PRIVATE;
break;
- case 'C':
+ case 'C':
*pclass = V_ASN1_CONTEXT_SPECIFIC;
break;
sk = sk_ASN1_TYPE_new_null();
if (!sk)
goto bad;
- if (section)
- {
+ if (section) {
if (!cnf)
goto bad;
sect = X509V3_get_section(cnf, (char *)section);
if (!sect)
goto bad;
- for (i = 0; i < sk_CONF_VALUE_num(sect); i++)
- {
+ for (i = 0; i < sk_CONF_VALUE_num(sect); i++) {
ASN1_TYPE *typ = ASN1_generate_v3(sk_CONF_VALUE_value(sect, i)->value, cnf);
if (!typ)
goto bad;
{
tag_exp_type *exp_tmp;
/* Can only have IMPLICIT if permitted */
- if ((arg->imp_tag != -1) && !imp_ok)
- {
+ if ((arg->imp_tag != -1) && !imp_ok) {
ASN1err(ASN1_F_APPEND_EXP, ASN1_R_ILLEGAL_IMPLICIT_TAG);
return 0;
}
- if (arg->exp_count == ASN1_FLAG_EXP_MAX)
- {
+ if (arg->exp_count == ASN1_FLAG_EXP_MAX) {
ASN1err(ASN1_F_APPEND_EXP, ASN1_R_DEPTH_EXCEEDED);
return 0;
}
/* If IMPLICIT set tag to implicit value then
* reset implicit tag since it has been used.
*/
- if (arg->imp_tag != -1)
- {
+ if (arg->imp_tag != -1) {
exp_tmp->exp_tag = arg->imp_tag;
exp_tmp->exp_class = arg->imp_class;
arg->imp_tag = -1;
arg->imp_class = -1;
- }
- else
- {
+ } else {
exp_tmp->exp_tag = exp_tag;
exp_tmp->exp_class = exp_class;
}
len = strlen(tagstr);
tntmp = tnst;
- for (i = 0; i < sizeof(tnst) / sizeof(struct tag_name_st); i++, tntmp++)
- {
+ for (i = 0; i < sizeof(tnst) / sizeof(struct tag_name_st); i++, tntmp++) {
if ((len == tntmp->len) && !strncmp(tntmp->strnam, tagstr, len))
return tntmp->tag;
}
int no_unused = 1;
- if (!(atmp = ASN1_TYPE_new()))
- {
+ if (!(atmp = ASN1_TYPE_new())) {
ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE);
return NULL;
}
if (!str)
str = "";
- switch(utype)
- {
+ switch(utype) {
- case V_ASN1_NULL:
- if (str && *str)
- {
+ case V_ASN1_NULL:
+ if (str && *str) {
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_NULL_VALUE);
goto bad_form;
}
break;
- case V_ASN1_BOOLEAN:
- if (format != ASN1_GEN_FORMAT_ASCII)
- {
+ case V_ASN1_BOOLEAN:
+ if (format != ASN1_GEN_FORMAT_ASCII) {
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_NOT_ASCII_FORMAT);
goto bad_form;
}
vtmp.name = NULL;
vtmp.section = NULL;
vtmp.value = (char *)str;
- if (!X509V3_get_value_bool(&vtmp, &atmp->value.boolean))
- {
+ if (!X509V3_get_value_bool(&vtmp, &atmp->value.boolean)) {
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_BOOLEAN);
goto bad_str;
}
break;
- case V_ASN1_INTEGER:
- case V_ASN1_ENUMERATED:
- if (format != ASN1_GEN_FORMAT_ASCII)
- {
+ case V_ASN1_INTEGER:
+ case V_ASN1_ENUMERATED:
+ if (format != ASN1_GEN_FORMAT_ASCII) {
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_INTEGER_NOT_ASCII_FORMAT);
goto bad_form;
}
- if (!(atmp->value.integer = s2i_ASN1_INTEGER(NULL, (char *)str)))
- {
+ if (!(atmp->value.integer = s2i_ASN1_INTEGER(NULL, (char *)str))) {
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_INTEGER);
goto bad_str;
}
break;
- case V_ASN1_OBJECT:
- if (format != ASN1_GEN_FORMAT_ASCII)
- {
+ case V_ASN1_OBJECT:
+ if (format != ASN1_GEN_FORMAT_ASCII) {
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_OBJECT_NOT_ASCII_FORMAT);
goto bad_form;
}
- if (!(atmp->value.object = OBJ_txt2obj(str, 0)))
- {
+ if (!(atmp->value.object = OBJ_txt2obj(str, 0))) {
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_OBJECT);
goto bad_str;
}
break;
- case V_ASN1_UTCTIME:
- case V_ASN1_GENERALIZEDTIME:
- if (format != ASN1_GEN_FORMAT_ASCII)
- {
+ case V_ASN1_UTCTIME:
+ case V_ASN1_GENERALIZEDTIME:
+ if (format != ASN1_GEN_FORMAT_ASCII) {
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_TIME_NOT_ASCII_FORMAT);
goto bad_form;
}
- if (!(atmp->value.asn1_string = ASN1_STRING_new()))
- {
+ if (!(atmp->value.asn1_string = ASN1_STRING_new())) {
ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE);
goto bad_str;
}
- if (!ASN1_STRING_set(atmp->value.asn1_string, str, -1))
- {
+ if (!ASN1_STRING_set(atmp->value.asn1_string, str, -1)) {
ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE);
goto bad_str;
}
atmp->value.asn1_string->type = utype;
- if (!ASN1_TIME_check(atmp->value.asn1_string))
- {
+ if (!ASN1_TIME_check(atmp->value.asn1_string)) {
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_TIME_VALUE);
goto bad_str;
}
break;
- case V_ASN1_BMPSTRING:
- case V_ASN1_PRINTABLESTRING:
- case V_ASN1_IA5STRING:
- case V_ASN1_T61STRING:
- case V_ASN1_UTF8STRING:
- case V_ASN1_VISIBLESTRING:
- case V_ASN1_UNIVERSALSTRING:
- case V_ASN1_GENERALSTRING:
- case V_ASN1_NUMERICSTRING:
+ case V_ASN1_BMPSTRING:
+ case V_ASN1_PRINTABLESTRING:
+ case V_ASN1_IA5STRING:
+ case V_ASN1_T61STRING:
+ case V_ASN1_UTF8STRING:
+ case V_ASN1_VISIBLESTRING:
+ case V_ASN1_UNIVERSALSTRING:
+ case V_ASN1_GENERALSTRING:
+ case V_ASN1_NUMERICSTRING:
if (format == ASN1_GEN_FORMAT_ASCII)
format = MBSTRING_ASC;
else if (format == ASN1_GEN_FORMAT_UTF8)
format = MBSTRING_UTF8;
- else
- {
+ else {
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_FORMAT);
goto bad_form;
}
if (ASN1_mbstring_copy(&atmp->value.asn1_string, (unsigned char *)str,
- -1, format, ASN1_tag2bit(utype)) <= 0)
- {
+ -1, format, ASN1_tag2bit(utype)) <= 0) {
ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE);
goto bad_str;
}
break;
- case V_ASN1_BIT_STRING:
+ case V_ASN1_BIT_STRING:
- case V_ASN1_OCTET_STRING:
+ case V_ASN1_OCTET_STRING:
- if (!(atmp->value.asn1_string = ASN1_STRING_new()))
- {
+ if (!(atmp->value.asn1_string = ASN1_STRING_new())) {
ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE);
goto bad_form;
}
- if (format == ASN1_GEN_FORMAT_HEX)
- {
+ if (format == ASN1_GEN_FORMAT_HEX) {
- if (!(rdata = string_to_hex((char *)str, &rdlen)))
- {
+ if (!(rdata = string_to_hex((char *)str, &rdlen))) {
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_HEX);
goto bad_str;
}
}
else if (format == ASN1_GEN_FORMAT_ASCII)
ASN1_STRING_set(atmp->value.asn1_string, str, -1);
- else if ((format == ASN1_GEN_FORMAT_BITLIST) && (utype == V_ASN1_BIT_STRING))
- {
- if (!CONF_parse_list(str, ',', 1, bitstr_cb, atmp->value.bit_string))
- {
+ else if ((format == ASN1_GEN_FORMAT_BITLIST) && (utype == V_ASN1_BIT_STRING)) {
+ if (!CONF_parse_list(str, ',', 1, bitstr_cb, atmp->value.bit_string)) {
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_LIST_ERROR);
goto bad_str;
}
no_unused = 0;
- }
- else
- {
+ } else {
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_BITSTRING_FORMAT);
goto bad_form;
}
- if ((utype == V_ASN1_BIT_STRING) && no_unused)
- {
+ if ((utype == V_ASN1_BIT_STRING) && no_unused) {
atmp->value.asn1_string->flags
&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07);
atmp->value.asn1_string->flags
break;
- default:
+ default:
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_UNSUPPORTED_TYPE);
goto bad_str;
break;
return atmp;
- bad_str:
+bad_str:
ERR_add_error_data(2, "string=", str);
- bad_form:
+bad_form:
ASN1_TYPE_free(atmp);
return NULL;
bitnum = strtoul(elem, &eptr, 10);
if (eptr && *eptr && (eptr != elem + len))
return 0;
- if (bitnum < 0)
- {
+ if (bitnum < 0) {
ASN1err(ASN1_F_BITSTR_CB, ASN1_R_INVALID_NUMBER);
return 0;
}
- if (!ASN1_BIT_STRING_set_bit(bitstr, bitnum, 1))
- {
+ if (!ASN1_BIT_STRING_set_bit(bitstr, bitnum, 1)) {
ASN1err(ASN1_F_BITSTR_CB, ERR_R_MALLOC_FAILURE);
return 0;
}
* things up */
if (len <= 0)
return(1);
- else if ((len >= 2) && ((*p)[0] == 0) && ((*p)[1] == 0))
- {
+ else if ((len >= 2) && ((*p)[0] == 0) && ((*p)[1] == 0)) {
(*p)+=2;
return(1);
}
ret=(*p&V_ASN1_CONSTRUCTED);
xclass=(*p&V_ASN1_PRIVATE);
i= *p&V_ASN1_PRIMITIVE_TAG;
- if (i == V_ASN1_PRIMITIVE_TAG)
- { /* high-tag */
+ if (i == V_ASN1_PRIMITIVE_TAG) { /* high-tag */
p++;
if (--max == 0) goto err;
l=0;
- while (*p&0x80)
- {
+ while (*p&0x80) {
l<<=7L;
l|= *(p++)&0x7f;
if (--max == 0) goto err;
l|= *(p++)&0x7f;
tag=(int)l;
if (--max == 0) goto err;
- }
- else
- {
+ } else {
tag=i;
p++;
if (--max == 0) goto err;
(int)(omax+ *pp));
#endif
- if (*plength > (omax - (p - *pp)))
- {
+ if (*plength > (omax - (p - *pp))) {
ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG);
/* Set this so that even if things are not long enough
* the values are set correctly */
unsigned int i;
if (max-- < 1) return(0);
- if (*p == 0x80)
- {
+ if (*p == 0x80) {
*inf=1;
ret=0;
p++;
- }
- else
- {
+ } else {
*inf=0;
i= *p&0x7f;
- if (*(p++) & 0x80)
- {
+ if (*(p++) & 0x80) {
if (i > sizeof(long))
return 0;
if (max-- == 0) return(0);
- while (i-- > 0)
- {
+ while (i-- > 0) {
ret<<=8L;
ret|= *(p++);
if (max-- == 0) return(0);
i|=(xclass&V_ASN1_PRIVATE);
if (tag < 31)
*(p++)=i|(tag&V_ASN1_PRIMITIVE_TAG);
- else
- {
+ else {
*(p++)=i|V_ASN1_PRIMITIVE_TAG;
for(i = 0, ttag = tag; ttag > 0; i++) ttag >>=7;
ttag = i;
- while(i-- > 0)
- {
+ while(i-- > 0) {
p[i] = tag & 0x7f;
if(i != (ttag - 1)) p[i] |= 0x80;
tag >>= 7;
int i,l;
if (length <= 127)
*(p++)=(unsigned char)length;
- else
- {
+ else {
l=length;
for (i=0; l > 0; i++)
l>>=8;
*(p++)=i|0x80;
l=i;
- while (i-- > 0)
- {
+ while (i-- > 0) {
p[i]=length&0xff;
length>>=8;
}
ret=length;
ret++;
- if (tag >= 31)
- {
- while (tag > 0)
- {
+ if (tag >= 31) {
+ while (tag > 0) {
tag>>=7;
ret++;
}
if (constructed == 2)
return ret + 3;
ret++;
- if (length > 127)
- {
- while (length > 0)
- {
+ if (length > 127) {
+ while (length > 0) {
length>>=8;
ret++;
}
static int _asn1_Finish(ASN1_const_CTX *c)
{
- if ((c->inf == (1|V_ASN1_CONSTRUCTED)) && (!c->eos))
- {
- if (!ASN1_const_check_infinite_end(&c->p,c->slen))
- {
+ if ((c->inf == (1|V_ASN1_CONSTRUCTED)) && (!c->eos)) {
+ if (!ASN1_const_check_infinite_end(&c->p,c->slen)) {
c->error=ERR_R_MISSING_ASN1_EOS;
return(0);
}
}
if ( ((c->slen != 0) && !(c->inf & 1)) ||
- ((c->slen < 0) && (c->inf & 1)))
- {
+ ((c->slen < 0) && (c->inf & 1))) {
c->error=ERR_R_ASN1_LENGTH_MISMATCH;
return(0);
}
q=c->p;
c->inf=ASN1_get_object(&(c->p),&(c->slen),&(c->tag),&(c->xclass),
*length);
- if (c->inf & 0x80)
- {
+ if (c->inf & 0x80) {
c->error=ERR_R_BAD_GET_ASN1_OBJECT_CALL;
return(0);
}
- if (c->tag != V_ASN1_SEQUENCE)
- {
+ if (c->tag != V_ASN1_SEQUENCE) {
c->error=ERR_R_EXPECTING_AN_ASN1_SEQUENCE;
return(0);
}
(*length)-=(c->p-q);
- if (c->max && (*length < 0))
- {
+ if (c->max && (*length < 0)) {
c->error=ERR_R_ASN1_LENGTH_MISMATCH;
return(0);
}
ret=ASN1_STRING_new();
if (!ret)
return NULL;
- if (!ASN1_STRING_copy(ret,str))
- {
+ if (!ASN1_STRING_copy(ret,str)) {
ASN1_STRING_free(ret);
return NULL;
}
unsigned char *c;
const char *data=_data;
- if (len < 0)
- {
+ if (len < 0) {
if (data == NULL)
return(0);
else
len=strlen(data);
}
- if ((str->length < len) || (str->data == NULL))
- {
+ if ((str->length < len) || (str->data == NULL)) {
c=str->data;
if (c == NULL)
str->data=malloc(len+1);
else
str->data=realloc(c,len+1);
- if (str->data == NULL)
- {
+ if (str->data == NULL) {
ASN1err(ASN1_F_ASN1_STRING_SET,ERR_R_MALLOC_FAILURE);
str->data=c;
return(0);
}
}
str->length=len;
- if (data != NULL)
- {
+ if (data != NULL) {
memcpy(str->data,data,len);
/* an allowance for strings :-) */
str->data[len]='\0';
ASN1_STRING *ret;
ret=(ASN1_STRING *)malloc(sizeof(ASN1_STRING));
- if (ret == NULL)
- {
+ if (ret == NULL) {
ASN1err(ASN1_F_ASN1_STRING_TYPE_NEW,ERR_R_MALLOC_FAILURE);
return(NULL);
}
int i;
i=(a->length-b->length);
- if (i == 0)
- {
+ if (i == 0) {
i=memcmp(a->data,b->data,a->length);
if (i == 0)
return(a->type-b->type);
p= *pp;
tot=p+length;
op=p-1;
- while ((p < tot) && (op < p))
- {
+ while ((p < tot) && (op < p)) {
op=p;
j=ASN1_get_object(&p,&len,&tag,&xclass,length);
#ifdef LINT
j=j;
#endif
- if (j & 0x80)
- {
+ if (j & 0x80) {
if (BIO_write(bp,"Error in encoding\n",18) <= 0)
goto end;
ret=0;
if (BIO_printf(bp,"%5ld:",(long)offset+(long)(op- *pp))
<= 0) goto end;
- if (j != (V_ASN1_CONSTRUCTED | 1))
- {
+ if (j != (V_ASN1_CONSTRUCTED | 1)) {
if (BIO_printf(bp,"d=%-2d hl=%ld l=%4ld ",
depth,(long)hl,len) <= 0)
goto end;
- }
- else
- {
+ } else {
if (BIO_printf(bp,"d=%-2d hl=%ld l=inf ",
depth,(long)hl) <= 0)
goto end;
}
if (!asn1_print_info(bp,tag,xclass,j,(indent)?depth:0))
goto end;
- if (j & V_ASN1_CONSTRUCTED)
- {
+ if (j & V_ASN1_CONSTRUCTED) {
ep=p+len;
if (BIO_write(bp,"\n",1) <= 0) goto end;
- if (len > length)
- {
+ if (len > length) {
BIO_printf(bp,
"length is greater than %ld\n",length);
ret=0;
goto end;
}
- if ((j == 0x21) && (len == 0))
- {
- for (;;)
- {
+ if ((j == 0x21) && (len == 0)) {
+ for (;;) {
r=asn1_parse2(bp,&p,(long)(tot-p),
offset+(p - *pp),depth+1,
indent,dump);
}
}
else
- while (p < ep)
- {
+ while (p < ep) {
r=asn1_parse2(bp,&p,(long)len,
offset+(p - *pp),depth+1,
indent,dump);
if (r == 0) { ret=0; goto end; }
}
- }
- else if (xclass != 0)
- {
+ } else if (xclass != 0) {
p+=len;
if (BIO_write(bp,"\n",1) <= 0) goto end;
- }
- else
- {
+ } else {
nl=0;
if ( (tag == V_ASN1_PRINTABLESTRING) ||
(tag == V_ASN1_T61STRING) ||
(tag == V_ASN1_NUMERICSTRING) ||
(tag == V_ASN1_UTF8STRING) ||
(tag == V_ASN1_UTCTIME) ||
- (tag == V_ASN1_GENERALIZEDTIME))
- {
+ (tag == V_ASN1_GENERALIZEDTIME)) {
if (BIO_write(bp,":",1) <= 0) goto end;
if ((len > 0) &&
BIO_write(bp,(const char *)p,(int)len)
!= (int)len)
goto end;
- }
- else if (tag == V_ASN1_OBJECT)
- {
+ } else if (tag == V_ASN1_OBJECT) {
opp=op;
- if (d2i_ASN1_OBJECT(&o,&opp,len+hl) != NULL)
- {
+ if (d2i_ASN1_OBJECT(&o,&opp,len+hl) != NULL) {
if (BIO_write(bp,":",1) <= 0) goto end;
i2a_ASN1_OBJECT(bp,o);
- }
- else
- {
+ } else {
if (BIO_write(bp,":BAD OBJECT",11) <= 0)
goto end;
}
- }
- else if (tag == V_ASN1_BOOLEAN)
- {
+ } else if (tag == V_ASN1_BOOLEAN) {
int ii;
opp=op;
ii=d2i_ASN1_BOOLEAN(NULL,&opp,len+hl);
- if (ii < 0)
- {
+ if (ii < 0) {
if (BIO_write(bp,"Bad boolean\n",12) <= 0)
goto end;
}
BIO_printf(bp,":%d",ii);
- }
- else if (tag == V_ASN1_BMPSTRING)
- {
+ } else if (tag == V_ASN1_BMPSTRING) {
/* do the BMP thang */
- }
- else if (tag == V_ASN1_OCTET_STRING)
- {
+ } else if (tag == V_ASN1_OCTET_STRING) {
int i,printable=1;
opp=op;
os=d2i_ASN1_OCTET_STRING(NULL,&opp,len+hl);
- if (os != NULL && os->length > 0)
- {
+ if (os != NULL && os->length > 0) {
opp = os->data;
/* testing whether the octet string is
* printable */
- for (i=0; i<os->length; i++)
- {
+ for (i=0; i<os->length; i++) {
if (( (opp[i] < ' ') &&
(opp[i] != '\n') &&
(opp[i] != '\r') &&
(opp[i] != '\t')) ||
- (opp[i] > '~'))
- {
+ (opp[i] > '~')) {
printable=0;
break;
}
}
- if (printable)
+ if (printable) {
/* printable string */
- {
if (BIO_write(bp,":",1) <= 0)
goto end;
if (BIO_write(bp,(const char *)opp,
os->length) <= 0)
goto end;
- }
- else if (!dump)
+ } else if (!dump) {
/* not printable => print octet string
* as hex dump */
- {
if (BIO_write(bp,"[HEX DUMP]:",11) <= 0)
goto end;
- for (i=0; i<os->length; i++)
- {
+ for (i=0; i<os->length; i++) {
if (BIO_printf(bp,"%02X"
, opp[i]) <= 0)
goto end;
}
- }
- else
+ } else {
/* print the normal dump */
- {
- if (!nl)
- {
+ if (!nl) {
if (BIO_write(bp,"\n",1) <= 0)
goto end;
}
nl=1;
}
}
- if (os != NULL)
- {
+ if (os != NULL) {
M_ASN1_OCTET_STRING_free(os);
os=NULL;
}
- }
- else if (tag == V_ASN1_INTEGER)
- {
+ } else if (tag == V_ASN1_INTEGER) {
ASN1_INTEGER *bs;
int i;
opp=op;
bs=d2i_ASN1_INTEGER(NULL,&opp,len+hl);
- if (bs != NULL)
- {
+ if (bs != NULL) {
if (BIO_write(bp,":",1) <= 0) goto end;
if (bs->type == V_ASN1_NEG_INTEGER)
if (BIO_write(bp,"-",1) <= 0)
goto end;
- for (i=0; i<bs->length; i++)
- {
+ for (i=0; i<bs->length; i++) {
if (BIO_printf(bp,"%02X",
bs->data[i]) <= 0)
goto end;
}
- if (bs->length == 0)
- {
+ if (bs->length == 0) {
if (BIO_write(bp,"00",2) <= 0)
goto end;
}
- }
- else
- {
+ } else {
if (BIO_write(bp,"BAD INTEGER",11) <= 0)
goto end;
}
M_ASN1_INTEGER_free(bs);
- }
- else if (tag == V_ASN1_ENUMERATED)
- {
+ } else if (tag == V_ASN1_ENUMERATED) {
ASN1_ENUMERATED *bs;
int i;
opp=op;
bs=d2i_ASN1_ENUMERATED(NULL,&opp,len+hl);
- if (bs != NULL)
- {
+ if (bs != NULL) {
if (BIO_write(bp,":",1) <= 0) goto end;
if (bs->type == V_ASN1_NEG_ENUMERATED)
if (BIO_write(bp,"-",1) <= 0)
goto end;
- for (i=0; i<bs->length; i++)
- {
+ for (i=0; i<bs->length; i++) {
if (BIO_printf(bp,"%02X",
bs->data[i]) <= 0)
goto end;
}
- if (bs->length == 0)
- {
+ if (bs->length == 0) {
if (BIO_write(bp,"00",2) <= 0)
goto end;
}
- }
- else
- {
+ } else {
if (BIO_write(bp,"BAD ENUMERATED",14) <= 0)
goto end;
}
M_ASN1_ENUMERATED_free(bs);
- }
- else if (len > 0 && dump)
- {
- if (!nl)
- {
+ } else if (len > 0 && dump) {
+ if (!nl) {
if (BIO_write(bp,"\n",1) <= 0)
goto end;
}
nl=1;
}
- if (!nl)
- {
+ if (!nl) {
if (BIO_write(bp,"\n",1) <= 0) goto end;
}
p+=len;
- if ((tag == V_ASN1_EOC) && (xclass == 0))
- {
+ if ((tag == V_ASN1_EOC) && (xclass == 0)) {
ret=2; /* End of sequence */
goto end;
}
};
if((tag == V_ASN1_NEG_INTEGER) || (tag == V_ASN1_NEG_ENUMERATED))
- tag &= ~0x100;
+ tag &= ~0x100;
if(tag < 0 || tag > 30) return "(unknown)";
return tag2str[tag];
const ASN1_ITEM *it)
{
/* If streaming create stream BIO and copy all content through it */
- if (flags & SMIME_STREAM)
- {
+ if (flags & SMIME_STREAM) {
BIO *bio, *tbio;
bio = BIO_new_NDEF(out, val, it);
- if (!bio)
- {
+ if (!bio) {
ASN1err(ASN1_F_I2D_ASN1_BIO_STREAM,ERR_R_MALLOC_FAILURE);
return 0;
}
SMIME_crlf_copy(in, bio, flags);
(void)BIO_flush(bio);
/* Free up successive BIOs until we hit the old output BIO */
- do
- {
+ do {
tbio = BIO_pop(bio);
BIO_free(bio);
bio = tbio;
BIO *b64;
int r;
b64 = BIO_new(BIO_f_base64());
- if(!b64)
- {
+ if(!b64) {
ASN1err(ASN1_F_B64_WRITE_ASN1,ERR_R_MALLOC_FAILURE);
return 0;
}
int i, have_unknown = 0, write_comma, ret = 0, md_nid;
have_unknown = 0;
write_comma = 0;
- for (i = 0; i < sk_X509_ALGOR_num(mdalgs); i++)
- {
+ for (i = 0; i < sk_X509_ALGOR_num(mdalgs); i++) {
if (write_comma)
BIO_write(out, ",", 1);
write_comma = 1;
md_nid = OBJ_obj2nid(sk_X509_ALGOR_value(mdalgs, i)->algorithm);
md = EVP_get_digestbynid(md_nid);
- if (md && md->md_ctrl)
- {
+ if (md && md->md_ctrl) {
int rv;
char *micstr;
rv = md->md_ctrl(NULL, EVP_MD_CTRL_MICALG, 0, &micstr);
- if (rv > 0)
- {
+ if (rv > 0) {
BIO_puts(out, micstr);
free(micstr);
continue;
if (rv != -2)
goto err;
}
- switch(md_nid)
- {
+ switch(md_nid) {
case NID_sha1:
BIO_puts(out, "sha1");
break;
default:
if (have_unknown)
write_comma = 0;
- else
- {
+ else {
BIO_puts(out, "unknown");
have_unknown = 1;
}
if (ctype_nid == NID_pkcs7_enveloped)
msg_type = "enveloped-data";
- else if (ctype_nid == NID_pkcs7_signed)
- {
+ else if (ctype_nid == NID_pkcs7_signed) {
if (econt_nid == NID_id_smime_ct_receipt)
msg_type = "signed-receipt";
else if (sk_X509_ALGOR_num(mdalgs) >= 0)
msg_type = "signed-data";
else
msg_type = "certs-only";
- }
- else if (ctype_nid == NID_id_smime_ct_compressedData)
- {
+ } else if (ctype_nid == NID_id_smime_ct_compressedData) {
msg_type = "compressed-data";
cname = "smime.p7z";
}
/* If data is not deteched or resigning then the output BIO is
* already set up to finalise when it is written through.
*/
- if (!(flags & SMIME_DETACHED) || (flags & PKCS7_REUSE_DIGEST))
- {
+ if (!(flags & SMIME_DETACHED) || (flags & PKCS7_REUSE_DIGEST)) {
SMIME_crlf_copy(data, out, flags);
return 1;
}
- if (!aux || !aux->asn1_cb)
- {
+ if (!aux || !aux->asn1_cb) {
ASN1err(ASN1_F_ASN1_OUTPUT_DATA,
ASN1_R_STREAMING_NOT_SUPPORTED);
return 0;
/* Now remove any digests prepended to the BIO */
- while (sarg.ndef_bio != out)
- {
+ while (sarg.ndef_bio != out) {
tmpbio = BIO_pop(sarg.ndef_bio);
BIO_free(sarg.ndef_bio);
sarg.ndef_bio = tmpbio;
if (!bf)
return 0;
out = BIO_push(bf, out);
- if(flags & SMIME_BINARY)
- {
+ if(flags & SMIME_BINARY) {
while((len = BIO_read(in, linebuf, MAX_SMLEN)) > 0)
BIO_write(out, linebuf, len);
- }
- else
- {
+ } else {
if(flags & SMIME_TEXT)
BIO_printf(out, "Content-Type: text/plain\r\n\r\n");
- while ((len = BIO_gets(in, linebuf, MAX_SMLEN)) > 0)
- {
+ while ((len = BIO_gets(in, linebuf, MAX_SMLEN)) > 0) {
eol = strip_eol(linebuf, &len);
if (len)
BIO_write(out, linebuf, len);
char *p, c;
int is_eol = 0;
p = linebuf + len - 1;
- for (p = linebuf + len - 1; len > 0; len--, p--)
- {
+ for (p = linebuf + len - 1; len > 0; len--, p--) {
c = *p;
if (c == '\n')
is_eol = 1;
STACK_OF(CONF_VALUE) *sktmp;
CONF_VALUE *oval;
oid_section = CONF_imodule_get_value(md);
- if(!(sktmp = NCONF_get_section(cnf, oid_section)))
- {
+ if(!(sktmp = NCONF_get_section(cnf, oid_section))) {
ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ERROR_LOADING_SECTION);
return 0;
}
- for(i = 0; i < sk_CONF_VALUE_num(sktmp); i++)
- {
+ for(i = 0; i < sk_CONF_VALUE_num(sktmp); i++) {
oval = sk_CONF_VALUE_value(sktmp, i);
- if(!do_create(oval->value, oval->name))
- {
+ if(!do_create(oval->value, oval->name)) {
ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ADDING_OBJECT);
return 0;
}
ASN1_OBJECT *oid;
char *ln, *ostr, *p, *lntmp;
p = strrchr(value, ',');
- if (!p)
- {
+ if (!p) {
ln = name;
ostr = value;
- }
- else
- {
+ } else {
ln = NULL;
ostr = p + 1;
if (!*ostr)
if (nid == NID_undef)
return 0;
- if (p)
- {
+ if (p) {
ln = value;
while(isspace((unsigned char)*ln)) ln++;
p--;
- while(isspace((unsigned char)*p))
- {
+ while(isspace((unsigned char)*p)) {
if (p == ln)
return 0;
p--;
wrlen = 0;
ret = -1;
- for(;;)
- {
- switch (ctx->state)
- {
+ for(;;) {
+ switch (ctx->state) {
/* Setup prefix data, call it */
- case ASN1_STATE_START:
+ case ASN1_STATE_START:
if (!asn1_bio_setup_ex(b, ctx, ctx->prefix,
ASN1_STATE_PRE_COPY, ASN1_STATE_HEADER))
return 0;
break;
/* Copy any pre data first */
- case ASN1_STATE_PRE_COPY:
+ case ASN1_STATE_PRE_COPY:
ret = asn1_bio_flush_ex(b, ctx, ctx->prefix_free,
ASN1_STATE_HEADER);
break;
- case ASN1_STATE_HEADER:
+ case ASN1_STATE_HEADER:
ctx->buflen =
ASN1_object_size(0, inl, ctx->asn1_tag) - inl;
OPENSSL_assert(ctx->buflen <= ctx->bufsize);
break;
- case ASN1_STATE_HEADER_COPY:
+ case ASN1_STATE_HEADER_COPY:
ret = BIO_write(b->next_bio,
ctx->buf + ctx->bufpos, ctx->buflen);
if (ret <= 0)
ctx->buflen -= ret;
if (ctx->buflen)
ctx->bufpos += ret;
- else
- {
+ else {
ctx->bufpos = 0;
ctx->state = ASN1_STATE_DATA_COPY;
}
break;
- case ASN1_STATE_DATA_COPY:
+ case ASN1_STATE_DATA_COPY:
if (inl > ctx->copylen)
wrmax = ctx->copylen;
int ret;
if (ctx->ex_len <= 0)
return 1;
- for(;;)
- {
+ for(;;) {
ret = BIO_write(b->next_bio, ctx->ex_buf + ctx->ex_pos,
ctx->ex_len);
if (ret <= 0)
ctx->ex_len -= ret;
if (ctx->ex_len > 0)
ctx->ex_pos += ret;
- else
- {
+ else {
if(cleanup)
cleanup(b, &ctx->ex_buf, &ctx->ex_len,
&ctx->ex_arg);
asn1_bio_state_t ex_state,
asn1_bio_state_t other_state)
{
- if (setup && !setup(b, &ctx->ex_buf, &ctx->ex_len, &ctx->ex_arg))
- {
+ if (setup && !setup(b, &ctx->ex_buf, &ctx->ex_len, &ctx->ex_arg)) {
BIO_clear_retry_flags(b);
return 0;
}
ctx = (BIO_ASN1_BUF_CTX *) b->ptr;
if (ctx == NULL)
return 0;
- switch(cmd)
- {
+ switch(cmd) {
- case BIO_C_SET_PREFIX:
+ case BIO_C_SET_PREFIX:
ex_func = arg2;
ctx->prefix = ex_func->ex_func;
ctx->prefix_free = ex_func->ex_free_func;
break;
- case BIO_C_GET_PREFIX:
+ case BIO_C_GET_PREFIX:
ex_func = arg2;
ex_func->ex_func = ctx->prefix;
ex_func->ex_free_func = ctx->prefix_free;
break;
- case BIO_C_SET_SUFFIX:
+ case BIO_C_SET_SUFFIX:
ex_func = arg2;
ctx->suffix = ex_func->ex_func;
ctx->suffix_free = ex_func->ex_free_func;
break;
- case BIO_C_GET_SUFFIX:
+ case BIO_C_GET_SUFFIX:
ex_func = arg2;
ex_func->ex_func = ctx->suffix;
ex_func->ex_free_func = ctx->suffix_free;
break;
- case BIO_C_SET_EX_ARG:
+ case BIO_C_SET_EX_ARG:
ctx->ex_arg = arg2;
break;
- case BIO_C_GET_EX_ARG:
+ case BIO_C_GET_EX_ARG:
*(void **)arg2 = ctx->ex_arg;
break;
- case BIO_CTRL_FLUSH:
+ case BIO_CTRL_FLUSH:
if (!b->next_bio)
return 0;
/* Call post function if possible */
- if (ctx->state == ASN1_STATE_HEADER)
- {
+ if (ctx->state == ASN1_STATE_HEADER) {
if (!asn1_bio_setup_ex(b, ctx, ctx->suffix,
ASN1_STATE_POST_COPY, ASN1_STATE_DONE))
return 0;
}
- if (ctx->state == ASN1_STATE_POST_COPY)
- {
+ if (ctx->state == ASN1_STATE_POST_COPY) {
ret = asn1_bio_flush_ex(b, ctx, ctx->suffix_free,
ASN1_STATE_DONE);
if (ret <= 0)
if (ctx->state == ASN1_STATE_DONE)
return BIO_ctrl(b->next_bio, cmd, arg1, arg2);
- else
- {
+ else {
BIO_clear_retry_flags(b);
return 0;
}
break;
- default:
+ default:
if (!b->next_bio)
return 0;
return BIO_ctrl(b->next_bio, cmd, arg1, arg2);
BIO_ASN1_EX_FUNCS extmp;
int ret;
ret = BIO_ctrl(b, cmd, 0, &extmp);
- if (ret > 0)
- {
+ if (ret > 0) {
*ex_func = extmp.ex_func;
*ex_free_func = extmp.ex_free_func;
}
const ASN1_AUX *aux = it->funcs;
ASN1_STREAM_ARG sarg;
- if (!aux || !aux->asn1_cb)
- {
+ if (!aux || !aux->asn1_cb) {
ASN1err(ASN1_F_BIO_NEW_NDEF, ASN1_R_STREAMING_NOT_SUPPORTED);
return NULL;
}
{
EVP_PKEY *ret;
- if ((a == NULL) || (*a == NULL))
- {
- if ((ret=EVP_PKEY_new()) == NULL)
- {
+ if ((a == NULL) || (*a == NULL)) {
+ if ((ret=EVP_PKEY_new()) == NULL) {
ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_EVP_LIB);
return(NULL);
}
- }
- else
- {
+ } else {
ret= *a;
#ifndef OPENSSL_NO_ENGINE
- if (ret->engine)
- {
+ if (ret->engine) {
ENGINE_finish(ret->engine);
ret->engine = NULL;
}
#endif
}
- if (!EVP_PKEY_set_type(ret, type))
- {
+ if (!EVP_PKEY_set_type(ret, type)) {
ASN1err(ASN1_F_D2I_PRIVATEKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE);
goto err;
}
if (!ret->ameth->old_priv_decode ||
- !ret->ameth->old_priv_decode(ret, pp, length))
- {
- if (ret->ameth->priv_decode)
- {
+ !ret->ameth->old_priv_decode(ret, pp, length)) {
+ if (ret->ameth->priv_decode) {
PKCS8_PRIV_KEY_INFO *p8=NULL;
p8=d2i_PKCS8_PRIV_KEY_INFO(NULL,pp,length);
if (!p8) goto err;
ret = EVP_PKCS82PKEY(p8);
PKCS8_PRIV_KEY_INFO_free(p8);
- }
- else
- {
+ } else {
ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_ASN1_LIB);
goto err;
}
keytype = EVP_PKEY_DSA;
else if (sk_ASN1_TYPE_num(inkey) == 4)
keytype = EVP_PKEY_EC;
- else if (sk_ASN1_TYPE_num(inkey) == 3)
- { /* This seems to be PKCS8, not traditional format */
- PKCS8_PRIV_KEY_INFO *p8 = d2i_PKCS8_PRIV_KEY_INFO(NULL,pp,length);
- EVP_PKEY *ret;
+ else if (sk_ASN1_TYPE_num(inkey) == 3) {
+ /* This seems to be PKCS8, not traditional format */
+ PKCS8_PRIV_KEY_INFO *p8 = d2i_PKCS8_PRIV_KEY_INFO(NULL,pp,length);
+ EVP_PKEY *ret;
- sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free);
- if (!p8)
- {
- ASN1err(ASN1_F_D2I_AUTOPRIVATEKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
- return NULL;
- }
- ret = EVP_PKCS82PKEY(p8);
- PKCS8_PRIV_KEY_INFO_free(p8);
- if (a) {
- *a = ret;
+ sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free);
+ if (!p8) {
+ ASN1err(ASN1_F_D2I_AUTOPRIVATEKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
+ return NULL;
+ }
+ ret = EVP_PKCS82PKEY(p8);
+ PKCS8_PRIV_KEY_INFO_free(p8);
+ if (a) {
+ *a = ret;
}
- return ret;
- }
- else keytype = EVP_PKEY_RSA;
+ return ret;
+ } else
+ keytype = EVP_PKEY_RSA;
sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free);
return d2i_PrivateKey(keytype, a, pp, length);
}
{
EVP_PKEY *ret;
- if ((a == NULL) || (*a == NULL))
- {
- if ((ret=EVP_PKEY_new()) == NULL)
- {
+ if ((a == NULL) || (*a == NULL)) {
+ if ((ret=EVP_PKEY_new()) == NULL) {
ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_EVP_LIB);
return(NULL);
}
}
else ret= *a;
- if (!EVP_PKEY_set_type(ret, type))
- {
+ if (!EVP_PKEY_set_type(ret, type)) {
ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_EVP_LIB);
goto err;
}
- switch (EVP_PKEY_id(ret))
- {
+ switch (EVP_PKEY_id(ret)) {
#ifndef OPENSSL_NO_RSA
case EVP_PKEY_RSA:
if ((ret->pkey.rsa=d2i_RSAPublicKey(NULL,
int ret,num;
unsigned char *p;
- if ((a->type != V_ASN1_OCTET_STRING) || (a->value.octet_string == NULL))
- {
+ if ((a->type != V_ASN1_OCTET_STRING) || (a->value.octet_string == NULL)) {
ASN1err(ASN1_F_ASN1_TYPE_GET_OCTETSTRING,ASN1_R_DATA_IS_WRONG);
return(-1);
}
if ((osp=ASN1_STRING_new()) == NULL) return(0);
/* Grow the 'string' */
- if (!ASN1_STRING_set(osp,NULL,size))
- {
+ if (!ASN1_STRING_set(osp,NULL,size)) {
ASN1_STRING_free(osp);
return(0);
}
long length;
ASN1_const_CTX c;
- if ((a->type != V_ASN1_SEQUENCE) || (a->value.sequence == NULL))
- {
+ if ((a->type != V_ASN1_SEQUENCE) || (a->value.sequence == NULL)) {
goto err;
}
p=M_ASN1_STRING_data(a->value.sequence);
if (data != NULL)
memcpy(data,M_ASN1_STRING_data(os),n);
- if (0)
- {
+ if (0) {
err:
ASN1err(ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING,ASN1_R_DATA_IS_WRONG);
}
if (a == NULL) return(0);
- if (a->length == 0)
- {
+ if (a->length == 0) {
if (BIO_write(bp,"00",2) != 2) goto err;
n=2;
- }
- else
- {
- for (i=0; i<a->length; i++)
- {
- if ((i != 0) && (i%35 == 0))
- {
+ } else {
+ for (i=0; i<a->length; i++) {
+ if ((i != 0) && (i%35 == 0)) {
if (BIO_write(bp,"\\\n",2) != 2) goto err;
n+=2;
}
bs->type=V_ASN1_ENUMERATED;
bufsize=BIO_gets(bp,buf,size);
- for (;;)
- {
+ for (;;) {
if (bufsize < 1) goto err_sl;
i=bufsize;
if (buf[i-1] == '\n') buf[--i]='\0';
if (i == 0) goto err_sl;
again=(buf[i-1] == '\\');
- for (j=0; j<i; j++)
- {
+ for (j=0; j<i; j++) {
if (!( ((buf[j] >= '0') && (buf[j] <= '9')) ||
((buf[j] >= 'a') && (buf[j] <= 'f')) ||
- ((buf[j] >= 'A') && (buf[j] <= 'F'))))
- {
+ ((buf[j] >= 'A') && (buf[j] <= 'F')))) {
i=j;
break;
}
if (i < 2) goto err_sl;
bufp=(unsigned char *)buf;
- if (first)
- {
+ if (first) {
first=0;
- if ((bufp[0] == '0') && (buf[1] == '0'))
- {
+ if ((bufp[0] == '0') && (buf[1] == '0')) {
bufp+=2;
i-=2;
}
}
k=0;
i-=again;
- if (i%2 != 0)
- {
+ if (i%2 != 0) {
ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_ODD_NUMBER_OF_CHARS);
goto err;
}
i/=2;
- if (num+i > slen)
- {
+ if (num+i > slen) {
if (s == NULL)
sp=(unsigned char *)malloc(
(unsigned int)num+i*2);
else
sp=(unsigned char *)realloc(s,
(unsigned int)num+i*2);
- if (sp == NULL)
- {
+ if (sp == NULL) {
ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE);
if (s != NULL) free(s);
goto err;
s=sp;
slen=num+i*2;
}
- for (j=0; j<i; j++,k+=2)
- {
- for (n=0; n<2; n++)
- {
+ for (j=0; j<i; j++,k+=2) {
+ for (n=0; n<2; n++) {
m=bufp[k+n];
if ((m >= '0') && (m <= '9'))
m-='0';
m=m-'a'+10;
else if ((m >= 'A') && (m <= 'F'))
m=m-'A'+10;
- else
- {
+ else {
ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_NON_HEX_CHARACTERS);
goto err;
}
bs->data=s;
ret=1;
err:
- if (0)
- {
+ if (0) {
err_sl:
ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_SHORT_LINE);
}
if (a == NULL) return(0);
- if (a->type & V_ASN1_NEG)
- {
+ if (a->type & V_ASN1_NEG) {
if (BIO_write(bp, "-", 1) != 1) goto err;
n = 1;
}
- if (a->length == 0)
- {
+ if (a->length == 0) {
if (BIO_write(bp,"00",2) != 2) goto err;
n += 2;
- }
- else
- {
- for (i=0; i<a->length; i++)
- {
- if ((i != 0) && (i%35 == 0))
- {
+ } else {
+ for (i=0; i<a->length; i++) {
+ if ((i != 0) && (i%35 == 0)) {
if (BIO_write(bp,"\\\n",2) != 2) goto err;
n+=2;
}
bs->type=V_ASN1_INTEGER;
bufsize=BIO_gets(bp,buf,size);
- for (;;)
- {
+ for (;;) {
if (bufsize < 1) goto err_sl;
i=bufsize;
if (buf[i-1] == '\n') buf[--i]='\0';
if (i == 0) goto err_sl;
again=(buf[i-1] == '\\');
- for (j=0; j<i; j++)
- {
+ for (j=0; j<i; j++) {
if (!( ((buf[j] >= '0') && (buf[j] <= '9')) ||
((buf[j] >= 'a') && (buf[j] <= 'f')) ||
- ((buf[j] >= 'A') && (buf[j] <= 'F'))))
- {
+ ((buf[j] >= 'A') && (buf[j] <= 'F')))) {
i=j;
break;
}
if (i < 2) goto err_sl;
bufp=(unsigned char *)buf;
- if (first)
- {
+ if (first) {
first=0;
- if ((bufp[0] == '0') && (buf[1] == '0'))
- {
+ if ((bufp[0] == '0') && (buf[1] == '0')) {
bufp+=2;
i-=2;
}
}
k=0;
i-=again;
- if (i%2 != 0)
- {
+ if (i%2 != 0) {
ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_ODD_NUMBER_OF_CHARS);
goto err;
}
i/=2;
- if (num+i > slen)
- {
+ if (num+i > slen) {
if (s == NULL)
sp=(unsigned char *)malloc(
(unsigned int)num+i*2);
else
sp=OPENSSL_realloc_clean(s,slen,num+i*2);
- if (sp == NULL)
- {
+ if (sp == NULL) {
ASN1err(ASN1_F_A2I_ASN1_INTEGER,ERR_R_MALLOC_FAILURE);
if (s != NULL) free(s);
goto err;
s=sp;
slen=num+i*2;
}
- for (j=0; j<i; j++,k+=2)
- {
- for (n=0; n<2; n++)
- {
+ for (j=0; j<i; j++,k+=2) {
+ for (n=0; n<2; n++) {
m=bufp[k+n];
if ((m >= '0') && (m <= '9'))
m-='0';
m=m-'a'+10;
else if ((m >= 'A') && (m <= 'F'))
m=m-'A'+10;
- else
- {
+ else {
ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_NON_HEX_CHARACTERS);
goto err;
}
bs->data=s;
ret=1;
err:
- if (0)
- {
+ if (0) {
err_sl:
ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_SHORT_LINE);
}
if (a == NULL) return(0);
- if (a->length == 0)
- {
+ if (a->length == 0) {
if (BIO_write(bp,"0",1) != 1) goto err;
n=1;
- }
- else
- {
- for (i=0; i<a->length; i++)
- {
- if ((i != 0) && (i%35 == 0))
- {
+ } else {
+ for (i=0; i<a->length; i++) {
+ if ((i != 0) && (i%35 == 0)) {
if (BIO_write(bp,"\\\n",2) != 2) goto err;
n+=2;
}
int num=0,slen=0,first=1;
bufsize=BIO_gets(bp,buf,size);
- for (;;)
- {
- if (bufsize < 1)
- {
+ for (;;) {
+ if (bufsize < 1) {
if (first)
break;
else
if (i == 0) goto err_sl;
again=(buf[i-1] == '\\');
- for (j=i-1; j>0; j--)
- {
+ for (j=i-1; j>0; j--) {
if (!( ((buf[j] >= '0') && (buf[j] <= '9')) ||
((buf[j] >= 'a') && (buf[j] <= 'f')) ||
- ((buf[j] >= 'A') && (buf[j] <= 'F'))))
- {
+ ((buf[j] >= 'A') && (buf[j] <= 'F')))) {
i=j;
break;
}
k=0;
i-=again;
- if (i%2 != 0)
- {
+ if (i%2 != 0) {
ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_ODD_NUMBER_OF_CHARS);
goto err;
}
i/=2;
- if (num+i > slen)
- {
+ if (num+i > slen) {
if (s == NULL)
sp=(unsigned char *)malloc(
(unsigned int)num+i*2);
else
sp=(unsigned char *)realloc(s,
(unsigned int)num+i*2);
- if (sp == NULL)
- {
+ if (sp == NULL) {
ASN1err(ASN1_F_A2I_ASN1_STRING,ERR_R_MALLOC_FAILURE);
if (s != NULL) free(s);
goto err;
s=sp;
slen=num+i*2;
}
- for (j=0; j<i; j++,k+=2)
- {
- for (n=0; n<2; n++)
- {
+ for (j=0; j<i; j++,k+=2) {
+ for (n=0; n<2; n++) {
m=bufp[k+n];
if ((m >= '0') && (m <= '9'))
m-='0';
m=m-'a'+10;
else if ((m >= 'A') && (m <= 'F'))
m=m-'A'+10;
- else
- {
+ else {
ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_NON_HEX_CHARACTERS);
goto err;
}
bs->data=s;
ret=1;
err:
- if (0)
- {
+ if (0) {
err_sl:
ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_SHORT_LINE);
}
int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp)
{
- if (a->ameth && a->ameth->old_priv_encode)
- {
+ if (a->ameth && a->ameth->old_priv_encode) {
return a->ameth->old_priv_encode(a, pp);
}
if (a->ameth && a->ameth->priv_encode) {
int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp)
{
- switch (a->type)
- {
+ switch (a->type) {
#ifndef OPENSSL_NO_RSA
case EVP_PKEY_RSA:
return(i2d_RSAPublicKey(a->pkey.rsa,pp));
if ((enckey->enckey->algor->parameter=ASN1_TYPE_new()) == NULL) goto err;
enckey->enckey->algor->parameter->type=V_ASN1_NULL;
- if (pp == NULL)
- {
+ if (pp == NULL) {
olen = i2d_NETSCAPE_ENCRYPTED_PKEY(enckey, NULL);
NETSCAPE_PKEY_free(pkey);
NETSCAPE_ENCRYPTED_PKEY_free(enckey);
/* Since its RC4 encrypted length is actual length */
- if ((zz=(unsigned char *)malloc(rsalen)) == NULL)
- {
+ if ((zz=(unsigned char *)malloc(rsalen)) == NULL) {
ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE);
goto err;
}
/* Write out private key encoding */
i2d_RSAPrivateKey(a,&zz);
- if ((zz=malloc(pkeylen)) == NULL)
- {
+ if ((zz=malloc(pkeylen)) == NULL) {
ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE);
goto err;
}
- if (!ASN1_STRING_set(enckey->os, "private-key", -1))
- {
+ if (!ASN1_STRING_set(enckey->os, "private-key", -1)) {
ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE);
goto err;
}
if (cb == NULL)
cb=EVP_read_pw_string;
i=cb((char *)buf,256,"Enter Private Key password:",1);
- if (i != 0)
- {
+ if (i != 0) {
ASN1err(ASN1_F_I2D_RSA_NET,ASN1_R_BAD_PASSWORD_READ);
goto err;
}
}
if ((enckey->os->length != 11) || (strncmp("private-key",
- (char *)enckey->os->data,11) != 0))
- {
+ (char *)enckey->os->data,11) != 0)) {
ASN1err(ASN1_F_D2I_RSA_NET,ASN1_R_PRIVATE_KEY_HEADER_MISSING);
NETSCAPE_ENCRYPTED_PKEY_free(enckey);
return NULL;
}
- if (OBJ_obj2nid(enckey->enckey->algor->algorithm) != NID_rc4)
- {
+ if (OBJ_obj2nid(enckey->enckey->algor->algorithm) != NID_rc4) {
ASN1err(ASN1_F_D2I_RSA_NET,ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM);
goto err;
}
EVP_CIPHER_CTX_init(&ctx);
i=cb((char *)buf,256,"Enter Private Key password:",0);
- if (i != 0)
- {
+ if (i != 0) {
ASN1err(ASN1_F_D2I_RSA_NET_2,ASN1_R_BAD_PASSWORD_READ);
goto err;
}
zz=os->data;
- if ((pkey=d2i_NETSCAPE_PKEY(NULL,&zz,os->length)) == NULL)
- {
+ if ((pkey=d2i_NETSCAPE_PKEY(NULL,&zz,os->length)) == NULL) {
ASN1err(ASN1_F_D2I_RSA_NET_2,ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY);
goto err;
}
zz=pkey->private_key->data;
- if ((ret=d2i_RSAPrivateKey(a,&zz,pkey->private_key->length)) == NULL)
- {
+ if ((ret=d2i_RSAPrivateKey(a,&zz,pkey->private_key->length)) == NULL) {
ASN1err(ASN1_F_D2I_RSA_NET_2,ASN1_R_UNABLE_TO_DECODE_RSA_KEY);
goto err;
}
unsigned char *sstr;
pbe = PBEPARAM_new();
- if (!pbe)
- {
+ if (!pbe) {
ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR,ERR_R_MALLOC_FAILURE);
goto err;
}
if(iter <= 0)
iter = PKCS5_DEFAULT_ITER;
- if (!ASN1_INTEGER_set(pbe->iter, iter))
- {
+ if (!ASN1_INTEGER_set(pbe->iter, iter)) {
ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR,ERR_R_MALLOC_FAILURE);
goto err;
}
if (!saltlen)
saltlen = PKCS5_SALT_LEN;
- if (!ASN1_STRING_set(pbe->salt, NULL, saltlen))
- {
+ if (!ASN1_STRING_set(pbe->salt, NULL, saltlen)) {
ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR,ERR_R_MALLOC_FAILURE);
goto err;
}
else if (RAND_pseudo_bytes(sstr, saltlen) < 0)
goto err;
- if(!ASN1_item_pack(pbe, ASN1_ITEM_rptr(PBEPARAM), &pbe_str))
- {
+ if(!ASN1_item_pack(pbe, ASN1_ITEM_rptr(PBEPARAM), &pbe_str)) {
ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR,ERR_R_MALLOC_FAILURE);
goto err;
}
{
X509_ALGOR *ret;
ret = X509_ALGOR_new();
- if (!ret)
- {
+ if (!ret) {
ASN1err(ASN1_F_PKCS5_PBE_SET,ERR_R_MALLOC_FAILURE);
return NULL;
}
if(!(scheme->parameter = ASN1_TYPE_new())) goto merr;
/* Create random IV */
- if (EVP_CIPHER_iv_length(cipher))
- {
+ if (EVP_CIPHER_iv_length(cipher)) {
if (aiv)
memcpy(iv, aiv, EVP_CIPHER_iv_length(cipher));
else if (RAND_pseudo_bytes(iv, EVP_CIPHER_iv_length(cipher)) < 0)
goto err;
- }
+ }
EVP_CIPHER_CTX_init(&ctx);
* An error is OK here: just means use default PRF.
*/
if ((prf_nid == -1) &&
- EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_PBE_PRF_NID, 0, &prf_nid) <= 0)
- {
+ EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_PBE_PRF_NID, 0, &prf_nid) <= 0) {
ERR_clear_error();
prf_nid = NID_hmacWithSHA1;
- }
+ }
EVP_CIPHER_CTX_cleanup(&ctx);
/* If its RC2 then we'd better setup the key length */
return ret;
- merr:
+merr:
ASN1err(ASN1_F_PKCS5_PBE2_SET_IV,ERR_R_MALLOC_FAILURE);
err:
X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
unsigned char *salt, int saltlen)
- {
+{
return PKCS5_pbe2_set_iv(cipher, iter, salt, saltlen, NULL, -1);
- }
+}
X509_ALGOR *PKCS5_pbkdf2_set(int iter, unsigned char *salt, int saltlen,
int prf_nid, int keylen)
- {
+{
X509_ALGOR *keyfunc = NULL;
PBKDF2PARAM *kdf = NULL;
ASN1_OCTET_STRING *osalt = NULL;
/* If have a key len set it up */
- if(keylen > 0)
- {
+ if(keylen > 0) {
if(!(kdf->keylength = M_ASN1_INTEGER_new()))
goto merr;
if(!ASN1_INTEGER_set (kdf->keylength, keylen))
}
/* prf can stay NULL if we are using hmacWithSHA1 */
- if (prf_nid > 0 && prf_nid != NID_hmacWithSHA1)
- {
+ if (prf_nid > 0 && prf_nid != NID_hmacWithSHA1) {
kdf->prf = X509_ALGOR_new();
if (!kdf->prf)
goto merr;
X509_ALGOR_set0(kdf->prf, OBJ_nid2obj(prf_nid),
V_ASN1_NULL, NULL);
- }
+ }
/* Finally setup the keyfunc structure */
PBKDF2PARAM_free(kdf);
return keyfunc;
- merr:
+merr:
ASN1err(ASN1_F_PKCS5_PBKDF2_SET,ERR_R_MALLOC_FAILURE);
PBKDF2PARAM_free(kdf);
X509_ALGOR_free(keyfunc);
return NULL;
- }
+}
unsigned char *penc, int penclen)
{
unsigned char **ppenc = NULL;
- if (version >= 0)
- {
+ if (version >= 0) {
if (!ASN1_INTEGER_set(priv->version, version))
return 0;
}
- if (penc)
- {
+ if (penc) {
int pmtype;
ASN1_OCTET_STRING *oct;
oct = ASN1_OCTET_STRING_new();
pmtype = V_ASN1_OCTET_STRING;
ASN1_TYPE_set(priv->pkey, pmtype, oct);
}
- if (!X509_ALGOR_set0(priv->pkeyalg, aobj, ptype, pval))
- {
+ if (!X509_ALGOR_set0(priv->pkeyalg, aobj, ptype, pval)) {
/* If call fails do not swallow 'enc' */
if (ppenc)
*ppenc = NULL;
{
if (ppkalg)
*ppkalg = p8->pkeyalg->algorithm;
- if(p8->pkey->type == V_ASN1_OCTET_STRING)
- {
+ if(p8->pkey->type == V_ASN1_OCTET_STRING) {
p8->broken = PKCS8_OK;
- if (pk)
- {
+ if (pk) {
*pk = p8->pkey->value.octet_string->data;
*ppklen = p8->pkey->value.octet_string->length;
}
- }
- else if (p8->pkey->type == V_ASN1_SEQUENCE)
- {
+ } else if (p8->pkey->type == V_ASN1_SEQUENCE) {
p8->broken = PKCS8_NO_OCTET;
- if (pk)
- {
+ if (pk) {
*pk = p8->pkey->value.sequence->data;
*ppklen = p8->pkey->value.sequence->length;
}
BIO *b;
int ret;
- if ((b=BIO_new(BIO_s_file())) == NULL)
- {
+ if ((b=BIO_new(BIO_s_file())) == NULL) {
X509err(X509_F_X509_CRL_PRINT_FP,ERR_R_BUF_LIB);
return(0);
}
neg = (BN_is_negative(num))?"-":"";
if(!BIO_indent(bp,off,128))
return 0;
- if (BN_is_zero(num))
- {
+ if (BN_is_zero(num)) {
if (BIO_printf(bp, "%s 0\n", number) <= 0)
return 0;
return 1;
}
- if (BN_num_bytes(num) <= BN_BYTES)
- {
+ if (BN_num_bytes(num) <= BN_BYTES) {
if (BIO_printf(bp,"%s %s%lu (%s0x%lx)\n",number,neg,
(unsigned long)num->d[0],neg,(unsigned long)num->d[0])
<= 0) return(0);
- }
- else
- {
+ } else {
buf[0]=0;
if (BIO_printf(bp,"%s%s",number,
(neg[0] == '-')?" (Negative)":"") <= 0)
n++;
else buf++;
- for (i=0; i<n; i++)
- {
- if ((i%15) == 0)
- {
+ for (i=0; i<n; i++) {
+ if ((i%15) == 0) {
if(BIO_puts(bp,"\n") <= 0
|| !BIO_indent(bp,off+4,128))
return 0;
BIO *b;
int ret;
- if ((b=BIO_new(BIO_s_file())) == NULL)
- {
+ if ((b=BIO_new(BIO_s_file())) == NULL) {
X509err(X509_F_X509_REQ_PRINT_FP,ERR_R_BUF_LIB);
return(0);
}
ri=x->req_info;
- if(!(cflag & X509_FLAG_NO_HEADER))
- {
+ if(!(cflag & X509_FLAG_NO_HEADER)) {
if (BIO_write(bp,"Certificate Request:\n",21) <= 0) goto err;
if (BIO_write(bp," Data:\n",10) <= 0) goto err;
}
- if(!(cflag & X509_FLAG_NO_VERSION))
- {
+ if(!(cflag & X509_FLAG_NO_VERSION)) {
neg=(ri->version->type == V_ASN1_NEG_INTEGER)?"-":"";
l=0;
- for (i=0; i<ri->version->length; i++)
- { l<<=8; l+=ri->version->data[i]; }
+ for (i=0; i<ri->version->length; i++) {
+ l<<=8; l+=ri->version->data[i];
+ }
if(BIO_printf(bp,"%8sVersion: %s%lu (%s0x%lx)\n","",neg,l,neg,
l) <= 0)
goto err;
if (X509_NAME_print_ex(bp,ri->subject,nmindent, nmflags) < 0) goto err;
if (BIO_write(bp,"\n",1) <= 0) goto err;
}
- if(!(cflag & X509_FLAG_NO_PUBKEY))
- {
+ if(!(cflag & X509_FLAG_NO_PUBKEY)) {
if (BIO_write(bp," Subject Public Key Info:\n",33) <= 0)
goto err;
if (BIO_printf(bp,"%12sPublic Key Algorithm: ","") <= 0)
goto err;
pkey=X509_REQ_get_pubkey(x);
- if (pkey == NULL)
- {
+ if (pkey == NULL) {
BIO_printf(bp,"%12sUnable to load Public Key\n","");
ERR_print_errors(bp);
- }
- else
- {
+ } else {
EVP_PKEY_print_public(bp, pkey, 16, NULL);
EVP_PKEY_free(pkey);
}
}
- if(!(cflag & X509_FLAG_NO_ATTRIBUTES))
- {
+ if(!(cflag & X509_FLAG_NO_ATTRIBUTES)) {
/* may not be */
if(BIO_printf(bp,"%8sAttributes:\n","") <= 0)
goto err;
sk=x->req_info->attributes;
- if (sk_X509_ATTRIBUTE_num(sk) == 0)
- {
+ if (sk_X509_ATTRIBUTE_num(sk) == 0) {
if(BIO_printf(bp,"%12sa0:00\n","") <= 0)
goto err;
- }
- else
- {
- for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++)
- {
+ } else {
+ for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++) {
ASN1_TYPE *at;
X509_ATTRIBUTE *a;
ASN1_BIT_STRING *bs=NULL;
continue;
if(BIO_printf(bp,"%12s","") <= 0)
goto err;
- if ((j=i2a_ASN1_OBJECT(bp,a->object)) > 0)
- {
- if (a->single)
- {
+ if ((j=i2a_ASN1_OBJECT(bp,a->object)) > 0) {
+ if (a->single) {
t=a->value.single;
type=t->type;
bs=t->value.bit_string;
- }
- else
- {
+ } else {
ii=0;
count=sk_ASN1_TYPE_num(a->value.set);
get_next:
if (BIO_puts(bp,":") <= 0) goto err;
if ( (type == V_ASN1_PRINTABLESTRING) ||
(type == V_ASN1_T61STRING) ||
- (type == V_ASN1_IA5STRING))
- {
+ (type == V_ASN1_IA5STRING)) {
if (BIO_write(bp,(char *)bs->data,bs->length)
!= bs->length)
goto err;
BIO_puts(bp,"\n");
- }
- else
- {
+ } else {
BIO_puts(bp,"unable to print attribute\n");
}
if (++ii < count) goto get_next;
}
}
}
- if(!(cflag & X509_FLAG_NO_EXTENSIONS))
- {
+ if(!(cflag & X509_FLAG_NO_EXTENSIONS)) {
exts = X509_REQ_get_extensions(x);
- if(exts)
- {
+ if(exts) {
BIO_printf(bp,"%8sRequested Extensions:\n","");
- for (i=0; i<sk_X509_EXTENSION_num(exts); i++)
- {
+ for (i=0; i<sk_X509_EXTENSION_num(exts); i++) {
ASN1_OBJECT *obj;
X509_EXTENSION *ex;
int j;
j=X509_EXTENSION_get_critical(ex);
if (BIO_printf(bp,": %s\n",j?"critical":"") <= 0)
goto err;
- if(!X509V3_EXT_print(bp, ex, cflag, 16))
- {
+ if(!X509V3_EXT_print(bp, ex, cflag, 16)) {
BIO_printf(bp, "%16s", "");
M_ASN1_OCTET_STRING_print(bp,ex->value);
}
}
}
- if(!(cflag & X509_FLAG_NO_SIGDUMP))
- {
+ if(!(cflag & X509_FLAG_NO_SIGDUMP)) {
if(!X509_signature_print(bp, x->sig_alg, x->signature)) goto err;
}
BIO_printf(out," Public Key Algorithm: %s\n",
(i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i));
pkey = X509_PUBKEY_get(spki->spkac->pubkey);
- if(!pkey) BIO_printf(out, " Unable to load public key\n");
- else
- {
+ if(!pkey)
+ BIO_printf(out, " Unable to load public key\n");
+ else {
EVP_PKEY_print_public(out, pkey, 4, NULL);
EVP_PKEY_free(pkey);
}
n=spki->signature->length;
s=(char *)spki->signature->data;
- for (i=0; i<n; i++)
- {
- if ((i%18) == 0) BIO_write(out,"\n ",7);
+ for (i=0; i<n; i++) {
+ if ((i%18) == 0)
+ BIO_write(out,"\n ",7);
BIO_printf(out,"%02x%s",(unsigned char)s[i],
((i+1) == n)?"":":");
}
BIO *b;
int ret;
- if ((b=BIO_new(BIO_s_file())) == NULL)
- {
+ if ((b=BIO_new(BIO_s_file())) == NULL) {
X509err(X509_F_X509_PRINT_EX_FP,ERR_R_BUF_LIB);
return(0);
}
nmindent = 16;
ci=x->cert_info;
- if(!(cflag & X509_FLAG_NO_HEADER))
- {
+ if(!(cflag & X509_FLAG_NO_HEADER)) {
if (BIO_write(bp,"Certificate:\n",13) <= 0) goto err;
if (BIO_write(bp," Data:\n",10) <= 0) goto err;
}
- if(!(cflag & X509_FLAG_NO_VERSION))
- {
+ if(!(cflag & X509_FLAG_NO_VERSION)) {
l=X509_get_version(x);
if (BIO_printf(bp,"%8sVersion: %lu (0x%lx)\n","",l+1,l) <= 0) goto err;
}
- if(!(cflag & X509_FLAG_NO_SERIAL))
- {
+ if(!(cflag & X509_FLAG_NO_SERIAL)) {
if (BIO_write(bp," Serial Number:",22) <= 0) goto err;
bs=X509_get_serialNumber(x);
- if (bs->length <= (int)sizeof(long))
- {
+ if (bs->length <= (int)sizeof(long)) {
l=ASN1_INTEGER_get(bs);
- if (bs->type == V_ASN1_NEG_INTEGER)
- {
+ if (bs->type == V_ASN1_NEG_INTEGER) {
l= -l;
neg="-";
- }
- else
+ } else
neg="";
if (BIO_printf(bp," %s%lu (%s0x%lx)\n",neg,l,neg,l) <= 0)
goto err;
- }
- else
- {
+ } else {
neg=(bs->type == V_ASN1_NEG_INTEGER)?" (Negative)":"";
if (BIO_printf(bp,"\n%12s%s","",neg) <= 0) goto err;
- for (i=0; i<bs->length; i++)
- {
+ for (i=0; i<bs->length; i++) {
if (BIO_printf(bp,"%02x%c",bs->data[i],
((i+1 == bs->length)?'\n':':')) <= 0)
goto err;
}
- if(!(cflag & X509_FLAG_NO_SIGNAME))
- {
+ if(!(cflag & X509_FLAG_NO_SIGNAME)) {
if(X509_signature_print(bp, x->sig_alg, NULL) <= 0)
goto err;
#if 0
#endif
}
- if(!(cflag & X509_FLAG_NO_ISSUER))
- {
+ if(!(cflag & X509_FLAG_NO_ISSUER)) {
if (BIO_printf(bp," Issuer:%c",mlch) <= 0) goto err;
if (X509_NAME_print_ex(bp,X509_get_issuer_name(x),nmindent, nmflags) < 0) goto err;
if (BIO_write(bp,"\n",1) <= 0) goto err;
}
- if(!(cflag & X509_FLAG_NO_VALIDITY))
- {
+ if(!(cflag & X509_FLAG_NO_VALIDITY)) {
if (BIO_write(bp," Validity\n",17) <= 0) goto err;
if (BIO_write(bp," Not Before: ",24) <= 0) goto err;
if (!ASN1_TIME_print(bp,X509_get_notBefore(x))) goto err;
if (!ASN1_TIME_print(bp,X509_get_notAfter(x))) goto err;
if (BIO_write(bp,"\n",1) <= 0) goto err;
}
- if(!(cflag & X509_FLAG_NO_SUBJECT))
- {
+ if(!(cflag & X509_FLAG_NO_SUBJECT)) {
if (BIO_printf(bp," Subject:%c",mlch) <= 0) goto err;
if (X509_NAME_print_ex(bp,X509_get_subject_name(x),nmindent, nmflags) < 0) goto err;
if (BIO_write(bp,"\n",1) <= 0) goto err;
}
- if(!(cflag & X509_FLAG_NO_PUBKEY))
- {
+ if(!(cflag & X509_FLAG_NO_PUBKEY)) {
if (BIO_write(bp," Subject Public Key Info:\n",33) <= 0)
goto err;
if (BIO_printf(bp,"%12sPublic Key Algorithm: ","") <= 0)
goto err;
pkey=X509_get_pubkey(x);
- if (pkey == NULL)
- {
+ if (pkey == NULL) {
BIO_printf(bp,"%12sUnable to load Public Key\n","");
ERR_print_errors(bp);
- }
- else
- {
+ } else {
EVP_PKEY_print_public(bp, pkey, 16, NULL);
EVP_PKEY_free(pkey);
}
X509V3_extensions_print(bp, "X509v3 extensions",
ci->extensions, cflag, 8);
- if(!(cflag & X509_FLAG_NO_SIGDUMP))
- {
+ if(!(cflag & X509_FLAG_NO_SIGDUMP)) {
if(X509_signature_print(bp, x->sig_alg, x->signature) <= 0) goto err;
}
- if(!(cflag & X509_FLAG_NO_AUX))
- {
+ if(!(cflag & X509_FLAG_NO_AUX)) {
if (!X509_CERT_AUX_print(bp, x->aux, 0)) goto err;
}
ret=1;
if (!EVP_Digest(der, derlen, SHA1md, NULL, EVP_sha1(), NULL))
goto err;
- for (i=0; i < SHA_DIGEST_LENGTH; i++)
- {
+ for (i=0; i < SHA_DIGEST_LENGTH; i++) {
if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0) goto err;
}
free (der);
x->cert_info->key->public_key->length,
SHA1md, NULL, EVP_sha1(), NULL))
goto err;
- for (i=0; i < SHA_DIGEST_LENGTH; i++)
- {
+ for (i=0; i < SHA_DIGEST_LENGTH; i++) {
if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0)
goto err;
}
n=sig->length;
s=sig->data;
- for (i=0; i<n; i++)
- {
- if ((i%18) == 0)
- {
+ for (i=0; i<n; i++) {
+ if ((i%18) == 0) {
if (BIO_write(bp,"\n",1) <= 0) return 0;
if (BIO_indent(bp, indent, indent) <= 0) return 0;
}
if (i2a_ASN1_OBJECT(bp, sigalg->algorithm) <= 0) return 0;
sig_nid = OBJ_obj2nid(sigalg->algorithm);
- if (sig_nid != NID_undef)
- {
+ if (sig_nid != NID_undef) {
int pkey_nid, dig_nid;
const EVP_PKEY_ASN1_METHOD *ameth;
- if (OBJ_find_sigid_algs(sig_nid, &dig_nid, &pkey_nid))
- {
+ if (OBJ_find_sigid_algs(sig_nid, &dig_nid, &pkey_nid)) {
ameth = EVP_PKEY_asn1_find(NULL, pkey_nid);
if (ameth && ameth->sig_print)
return ameth->sig_print(bp, sigalg, sig, 9, 0);
if (v == NULL) return(0);
n=0;
p=(const char *)v->data;
- for (i=0; i<v->length; i++)
- {
+ for (i=0; i<v->length; i++) {
if ((p[i] > '~') || ((p[i] < ' ') &&
(p[i] != '\n') && (p[i] != '\r')))
buf[n]='.';
else
buf[n]=p[i];
n++;
- if (n >= 80)
- {
+ if (n >= 80) {
if (BIO_write(bp,buf,n) <= 0)
return(0);
n=0;
m= (v[10]-'0')*10+(v[11]-'0');
if (tm->length >= 14 &&
(v[12] >= '0') && (v[12] <= '9') &&
- (v[13] >= '0') && (v[13] <= '9'))
- {
+ (v[13] >= '0') && (v[13] <= '9')) {
s= (v[12]-'0')*10+(v[13]-'0');
/* Check for fractions of seconds. */
- if (tm->length >= 15 && v[14] == '.')
- {
+ if (tm->length >= 15 && v[14] == '.') {
int l = tm->length;
f = &v[14]; /* The decimal point. */
f_len = 1;
l=80-2-obase;
b=X509_NAME_oneline(name,NULL,0);
- if (!*b)
- {
+ if (!*b) {
free(b);
return 1;
}
s=b+1; /* skip the first slash */
c=s;
- for (;;)
- {
+ for (;;) {
if ( ((*s == '/') &&
((s[1] >= 'A') && (s[1] <= 'Z') && (
(s[2] == '=') ||
((s[2] >= 'A') && (s[2] <= 'Z') &&
(s[3] == '='))
))) ||
- (*s == '\0'))
- {
+ (*s == '\0')) {
i=s-c;
if (BIO_write(bp,c,i) != i) goto err;
c=s+1; /* skip following slash */
- if (*s != '\0')
- {
+ if (*s != '\0') {
if (BIO_write(bp,", ",2) != 2) goto err;
}
l--;
}
ret=1;
- if (0)
- {
+ if (0) {
err:
X509err(X509_F_X509_NAME_PRINT,ERR_R_BUF_LIB);
}
asn1_cb = aux->asn1_cb;
else asn1_cb = 0;
- switch(it->itype)
- {
- case ASN1_ITYPE_PRIMITIVE:
- if (it->templates)
- {
+ switch(it->itype) {
+ case ASN1_ITYPE_PRIMITIVE:
+ if (it->templates) {
/* tagging or OPTIONAL is currently illegal on an item
* template because the flags can't get passed down.
* In practice this isn't a problem: we include the
* relevant flags from the item template in the
* template itself.
*/
- if ((tag != -1) || opt)
- {
+ if ((tag != -1) || opt) {
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE);
goto err;
tag, aclass, opt, ctx);
break;
- case ASN1_ITYPE_MSTRING:
+ case ASN1_ITYPE_MSTRING:
p = *in;
/* Just read in tag and class */
ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, NULL,
&p, len, -1, 0, 1, ctx);
- if (!ret)
- {
+ if (!ret) {
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
ERR_R_NESTED_ASN1_ERROR);
goto err;
}
/* Must be UNIVERSAL class */
- if (oclass != V_ASN1_UNIVERSAL)
- {
+ if (oclass != V_ASN1_UNIVERSAL) {
/* If OPTIONAL, assume this is OK */
if (opt) return -1;
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
goto err;
}
/* Check tag matches bit map */
- if (!(ASN1_tag2bit(otag) & it->utype))
- {
+ if (!(ASN1_tag2bit(otag) & it->utype)) {
/* If OPTIONAL, assume this is OK */
if (opt)
return -1;
return asn1_d2i_ex_primitive(pval, in, len,
it, otag, 0, 0, ctx);
- case ASN1_ITYPE_EXTERN:
+ case ASN1_ITYPE_EXTERN:
/* Use new style d2i */
ef = it->funcs;
return ef->asn1_ex_d2i(pval, in, len,
it, tag, aclass, opt, ctx);
- case ASN1_ITYPE_COMPAT:
+ case ASN1_ITYPE_COMPAT:
/* we must resort to old style evil hackery */
cf = it->funcs;
/* If OPTIONAL see if it is there */
- if (opt)
- {
+ if (opt) {
int exptag;
p = *in;
if (tag == -1)
ret = asn1_check_tlen(NULL, NULL, NULL, NULL, NULL,
&p, len, exptag, aclass, 1, ctx);
- if (!ret)
- {
+ if (!ret) {
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
ERR_R_NESTED_ASN1_ERROR);
goto err;
* buffer.
*/
- if (tag != -1)
- {
+ if (tag != -1) {
wp = *(unsigned char **)in;
imphack = *wp;
- if (p == NULL)
- {
+ if (p == NULL) {
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
ERR_R_NESTED_ASN1_ERROR);
goto err;
goto err;
- case ASN1_ITYPE_CHOICE:
+ case ASN1_ITYPE_CHOICE:
if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL))
goto auxerr;
/* Allocate structure */
- if (!*pval && !ASN1_item_ex_new(pval, it))
- {
+ if (!*pval && !ASN1_item_ex_new(pval, it)) {
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
ERR_R_NESTED_ASN1_ERROR);
goto err;
}
/* CHOICE type, try each possibility in turn */
p = *in;
- for (i = 0, tt=it->templates; i < it->tcount; i++, tt++)
- {
+ for (i = 0, tt=it->templates; i < it->tcount; i++, tt++) {
pchptr = asn1_get_field_ptr(pval, tt);
/* We mark field as OPTIONAL so its absence
* can be recognised.
}
/* Did we fall off the end without reading anything? */
- if (i == it->tcount)
- {
+ if (i == it->tcount) {
/* If OPTIONAL, this is OK */
- if (opt)
- {
+ if (opt) {
/* Free and zero it */
ASN1_item_ex_free(pval, it);
return -1;
goto auxerr;
return 1;
- case ASN1_ITYPE_NDEF_SEQUENCE:
- case ASN1_ITYPE_SEQUENCE:
+ case ASN1_ITYPE_NDEF_SEQUENCE:
+ case ASN1_ITYPE_SEQUENCE:
p = *in;
tmplen = len;
/* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */
- if (tag == -1)
- {
+ if (tag == -1) {
tag = V_ASN1_SEQUENCE;
aclass = V_ASN1_UNIVERSAL;
}
/* Get SEQUENCE length and update len, p */
ret = asn1_check_tlen(&len, NULL, NULL, &seq_eoc, &cst,
&p, len, tag, aclass, opt, ctx);
- if (!ret)
- {
+ if (!ret) {
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
ERR_R_NESTED_ASN1_ERROR);
goto err;
}
else if (ret == -1)
return -1;
- if (aux && (aux->flags & ASN1_AFLG_BROKEN))
- {
+ if (aux && (aux->flags & ASN1_AFLG_BROKEN)) {
len = tmplen - (p - *in);
seq_nolen = 1;
}
/* If indefinite we don't do a length check */
else seq_nolen = seq_eoc;
- if (!cst)
- {
+ if (!cst) {
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
ASN1_R_SEQUENCE_NOT_CONSTRUCTED);
goto err;
}
- if (!*pval && !ASN1_item_ex_new(pval, it))
- {
+ if (!*pval && !ASN1_item_ex_new(pval, it)) {
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
ERR_R_NESTED_ASN1_ERROR);
goto err;
goto auxerr;
/* Get each field entry */
- for (i = 0, tt = it->templates; i < it->tcount; i++, tt++)
- {
+ for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
const ASN1_TEMPLATE *seqtt;
ASN1_VALUE **pseqval;
seqtt = asn1_do_adb(pval, tt, 1);
if (!len)
break;
q = p;
- if (asn1_check_eoc(&p, len))
- {
- if (!seq_eoc)
- {
+ if (asn1_check_eoc(&p, len)) {
+ if (!seq_eoc) {
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
ASN1_R_UNEXPECTED_EOC);
goto err;
ret = asn1_template_ex_d2i(pseqval, &p, len,
seqtt, isopt, ctx);
- if (!ret)
- {
+ if (!ret) {
errtt = seqtt;
goto err;
- }
- else if (ret == -1)
- {
+ } else if (ret == -1) {
/* OPTIONAL component absent.
* Free and zero the field.
*/
}
/* Check for EOC if expecting one */
- if (seq_eoc && !asn1_check_eoc(&p, len))
- {
+ if (seq_eoc && !asn1_check_eoc(&p, len)) {
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_MISSING_EOC);
goto err;
}
/* Check all data read */
- if (!seq_nolen && len)
- {
+ if (!seq_nolen && len) {
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
ASN1_R_SEQUENCE_LENGTH_MISMATCH);
goto err;
* however we may not have read all fields so check all
* remaining are OPTIONAL and clear any that are.
*/
- for (; i < it->tcount; tt++, i++)
- {
+ for (; i < it->tcount; tt++, i++) {
const ASN1_TEMPLATE *seqtt;
seqtt = asn1_do_adb(pval, tt, 1);
if (!seqtt)
goto err;
- if (seqtt->flags & ASN1_TFLG_OPTIONAL)
- {
+ if (seqtt->flags & ASN1_TFLG_OPTIONAL) {
ASN1_VALUE **pseqval;
pseqval = asn1_get_field_ptr(pval, seqtt);
ASN1_template_free(pseqval, seqtt);
- }
- else
- {
+ } else {
errtt = seqtt;
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
ASN1_R_FIELD_MISSING);
p = *in;
/* Check if EXPLICIT tag expected */
- if (flags & ASN1_TFLG_EXPTAG)
- {
+ if (flags & ASN1_TFLG_EXPTAG) {
char cst;
/* Need to work out amount of data available to the inner
* content and where it starts: so read in EXPLICIT header to
ret = asn1_check_tlen(&len, NULL, NULL, &exp_eoc, &cst,
&p, inlen, tt->tag, aclass, opt, ctx);
q = p;
- if (!ret)
- {
+ if (!ret) {
ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I,
ERR_R_NESTED_ASN1_ERROR);
return 0;
- }
- else if (ret == -1)
+ } else if (ret == -1)
return -1;
- if (!cst)
- {
+ if (!cst) {
ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I,
ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED);
return 0;
}
/* We've found the field so it can't be OPTIONAL now */
ret = asn1_template_noexp_d2i(val, &p, len, tt, 0, ctx);
- if (!ret)
- {
+ if (!ret) {
ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I,
ERR_R_NESTED_ASN1_ERROR);
return 0;
}
/* We read the field in OK so update length */
len -= p - q;
- if (exp_eoc)
- {
+ if (exp_eoc) {
/* If NDEF we must have an EOC here */
- if (!asn1_check_eoc(&p, len))
- {
+ if (!asn1_check_eoc(&p, len)) {
ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I,
ASN1_R_MISSING_EOC);
goto err;
}
- }
- else
- {
+ } else {
/* Otherwise we must hit the EXPLICIT tag end or its
* an error */
- if (len)
- {
+ if (len) {
ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I,
ASN1_R_EXPLICIT_LENGTH_MISMATCH);
goto err;
p = *in;
q = p;
- if (flags & ASN1_TFLG_SK_MASK)
- {
+ if (flags & ASN1_TFLG_SK_MASK) {
/* SET OF, SEQUENCE OF */
int sktag, skaclass;
char sk_eoc;
/* First work out expected inner tag value */
- if (flags & ASN1_TFLG_IMPTAG)
- {
+ if (flags & ASN1_TFLG_IMPTAG) {
sktag = tt->tag;
skaclass = aclass;
- }
- else
- {
+ } else {
skaclass = V_ASN1_UNIVERSAL;
if (flags & ASN1_TFLG_SET_OF)
sktag = V_ASN1_SET;
/* Get the tag */
ret = asn1_check_tlen(&len, NULL, NULL, &sk_eoc, NULL,
&p, len, sktag, skaclass, opt, ctx);
- if (!ret)
- {
+ if (!ret) {
ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
ERR_R_NESTED_ASN1_ERROR);
return 0;
return -1;
if (!*val)
*val = (ASN1_VALUE *)sk_new_null();
- else
- {
+ else {
/* We've got a valid STACK: free up any items present */
STACK_OF(ASN1_VALUE) *sktmp
= (STACK_OF(ASN1_VALUE) *)*val;
ASN1_VALUE *vtmp;
- while(sk_ASN1_VALUE_num(sktmp) > 0)
- {
+ while(sk_ASN1_VALUE_num(sktmp) > 0) {
vtmp = sk_ASN1_VALUE_pop(sktmp);
ASN1_item_ex_free(&vtmp,
ASN1_ITEM_ptr(tt->item));
}
}
- if (!*val)
- {
+ if (!*val) {
ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
ERR_R_MALLOC_FAILURE);
goto err;
}
/* Read as many items as we can */
- while(len > 0)
- {
+ while(len > 0) {
ASN1_VALUE *skfield;
q = p;
/* See if EOC found */
- if (asn1_check_eoc(&p, len))
- {
- if (!sk_eoc)
- {
+ if (asn1_check_eoc(&p, len)) {
+ if (!sk_eoc) {
ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
ASN1_R_UNEXPECTED_EOC);
goto err;
skfield = NULL;
if (!ASN1_item_ex_d2i(&skfield, &p, len,
ASN1_ITEM_ptr(tt->item),
- -1, 0, 0, ctx))
- {
+ -1, 0, 0, ctx)) {
ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
ERR_R_NESTED_ASN1_ERROR);
goto err;
}
len -= p - q;
if (!sk_ASN1_VALUE_push((STACK_OF(ASN1_VALUE) *)*val,
- skfield))
- {
+ skfield)) {
ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
ERR_R_MALLOC_FAILURE);
goto err;
}
}
- if (sk_eoc)
- {
+ if (sk_eoc) {
ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ASN1_R_MISSING_EOC);
goto err;
}
- }
- else if (flags & ASN1_TFLG_IMPTAG)
- {
+ } else if (flags & ASN1_TFLG_IMPTAG) {
/* IMPLICIT tagging */
ret = ASN1_item_ex_d2i(val, &p, len,
ASN1_ITEM_ptr(tt->item), tt->tag, aclass, opt, ctx);
- if (!ret)
- {
+ if (!ret) {
ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
ERR_R_NESTED_ASN1_ERROR);
goto err;
}
else if (ret == -1)
return -1;
- }
- else
- {
+ } else {
/* Nothing special */
ret = ASN1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item),
-1, 0, opt, ctx);
- if (!ret)
- {
+ if (!ret) {
ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
ERR_R_NESTED_ASN1_ERROR);
goto err;
BUF_MEM buf;
const unsigned char *cont = NULL;
long len;
- if (!pval)
- {
+ if (!pval) {
ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_ILLEGAL_NULL);
return 0; /* Should never happen */
}
- if (it->itype == ASN1_ITYPE_MSTRING)
- {
+ if (it->itype == ASN1_ITYPE_MSTRING) {
utype = tag;
tag = -1;
}
else
utype = it->utype;
- if (utype == V_ASN1_ANY)
- {
+ if (utype == V_ASN1_ANY) {
/* If type is ANY need to figure out type from tag */
unsigned char oclass;
- if (tag >= 0)
- {
+ if (tag >= 0) {
ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE,
ASN1_R_ILLEGAL_TAGGED_ANY);
return 0;
}
- if (opt)
- {
+ if (opt) {
ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE,
ASN1_R_ILLEGAL_OPTIONAL_ANY);
return 0;
p = *in;
ret = asn1_check_tlen(NULL, &utype, &oclass, NULL, NULL,
&p, inlen, -1, 0, 0, ctx);
- if (!ret)
- {
+ if (!ret) {
ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE,
ERR_R_NESTED_ASN1_ERROR);
return 0;
if (oclass != V_ASN1_UNIVERSAL)
utype = V_ASN1_OTHER;
}
- if (tag == -1)
- {
+ if (tag == -1) {
tag = utype;
aclass = V_ASN1_UNIVERSAL;
}
/* Check header */
ret = asn1_check_tlen(&plen, NULL, NULL, &inf, &cst,
&p, inlen, tag, aclass, opt, ctx);
- if (!ret)
- {
+ if (!ret) {
ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_NESTED_ASN1_ERROR);
return 0;
}
ret = 0;
/* SEQUENCE, SET and "OTHER" are left in encoded form */
if ((utype == V_ASN1_SEQUENCE)
- || (utype == V_ASN1_SET) || (utype == V_ASN1_OTHER))
- {
+ || (utype == V_ASN1_SET) || (utype == V_ASN1_OTHER)) {
/* Clear context cache for type OTHER because the auto clear
* when we have a exact match wont work
*/
- if (utype == V_ASN1_OTHER)
- {
+ if (utype == V_ASN1_OTHER) {
asn1_tlc_clear(ctx);
}
/* SEQUENCE and SET must be constructed */
- else if (!cst)
- {
+ else if (!cst) {
ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE,
ASN1_R_TYPE_NOT_CONSTRUCTED);
return 0;
cont = *in;
/* If indefinite length constructed find the real end */
- if (inf)
- {
+ if (inf) {
if (!asn1_find_end(&p, plen, inf))
goto err;
len = p - cont;
- }
- else
- {
+ } else {
len = p - cont + plen;
p += plen;
buf.data = NULL;
}
- }
- else if (cst)
- {
+ } else if (cst) {
buf.length = 0;
buf.max = 0;
buf.data = NULL;
* internally irrespective of the type. So instead just check
* for UNIVERSAL class and ignore the tag.
*/
- if (!asn1_collect(&buf, &p, plen, inf, -1, V_ASN1_UNIVERSAL, 0))
- {
+ if (!asn1_collect(&buf, &p, plen, inf, -1, V_ASN1_UNIVERSAL, 0)) {
free_cont = 1;
goto err;
}
len = buf.length;
/* Append a final null to string */
- if (!BUF_MEM_grow_clean(&buf, len + 1))
- {
+ if (!BUF_MEM_grow_clean(&buf, len + 1)) {
ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE,
ERR_R_MALLOC_FAILURE);
return 0;
buf.data[len] = 0;
cont = (const unsigned char *)buf.data;
free_cont = 1;
- }
- else
- {
+ } else {
cont = p;
len = plen;
p += plen;
if (pf && pf->prim_c2i)
return pf->prim_c2i(pval, cont, len, utype, free_cont, it);
/* If ANY type clear type and set pointer to internal value */
- if (it->utype == V_ASN1_ANY)
- {
- if (!*pval)
- {
+ if (it->utype == V_ASN1_ANY) {
+ if (!*pval) {
typ = ASN1_TYPE_new();
if (typ == NULL)
goto err;
opval = pval;
pval = &typ->value.asn1_value;
}
- switch(utype)
- {
- case V_ASN1_OBJECT:
+ switch(utype) {
+ case V_ASN1_OBJECT:
if (!c2i_ASN1_OBJECT((ASN1_OBJECT **)pval, &cont, len))
goto err;
break;
- case V_ASN1_NULL:
- if (len)
- {
+ case V_ASN1_NULL:
+ if (len) {
ASN1err(ASN1_F_ASN1_EX_C2I,
ASN1_R_NULL_IS_WRONG_LENGTH);
goto err;
*pval = (ASN1_VALUE *)1;
break;
- case V_ASN1_BOOLEAN:
- if (len != 1)
- {
+ case V_ASN1_BOOLEAN:
+ if (len != 1) {
ASN1err(ASN1_F_ASN1_EX_C2I,
ASN1_R_BOOLEAN_IS_WRONG_LENGTH);
goto err;
- }
- else
- {
+ } else {
ASN1_BOOLEAN *tbool;
tbool = (ASN1_BOOLEAN *)pval;
*tbool = *cont;
}
break;
- case V_ASN1_BIT_STRING:
+ case V_ASN1_BIT_STRING:
if (!c2i_ASN1_BIT_STRING((ASN1_BIT_STRING **)pval, &cont, len))
goto err;
break;
- case V_ASN1_INTEGER:
- case V_ASN1_NEG_INTEGER:
- case V_ASN1_ENUMERATED:
- case V_ASN1_NEG_ENUMERATED:
+ case V_ASN1_INTEGER:
+ case V_ASN1_NEG_INTEGER:
+ case V_ASN1_ENUMERATED:
+ case V_ASN1_NEG_ENUMERATED:
tint = (ASN1_INTEGER **)pval;
if (!c2i_ASN1_INTEGER(tint, &cont, len))
goto err;
(*tint)->type = utype | ((*tint)->type & V_ASN1_NEG);
break;
- case V_ASN1_OCTET_STRING:
- case V_ASN1_NUMERICSTRING:
- case V_ASN1_PRINTABLESTRING:
- case V_ASN1_T61STRING:
- case V_ASN1_VIDEOTEXSTRING:
- case V_ASN1_IA5STRING:
- case V_ASN1_UTCTIME:
- case V_ASN1_GENERALIZEDTIME:
- case V_ASN1_GRAPHICSTRING:
- case V_ASN1_VISIBLESTRING:
- case V_ASN1_GENERALSTRING:
- case V_ASN1_UNIVERSALSTRING:
- case V_ASN1_BMPSTRING:
- case V_ASN1_UTF8STRING:
- case V_ASN1_OTHER:
- case V_ASN1_SET:
- case V_ASN1_SEQUENCE:
- default:
- if (utype == V_ASN1_BMPSTRING && (len & 1))
- {
+ case V_ASN1_OCTET_STRING:
+ case V_ASN1_NUMERICSTRING:
+ case V_ASN1_PRINTABLESTRING:
+ case V_ASN1_T61STRING:
+ case V_ASN1_VIDEOTEXSTRING:
+ case V_ASN1_IA5STRING:
+ case V_ASN1_UTCTIME:
+ case V_ASN1_GENERALIZEDTIME:
+ case V_ASN1_GRAPHICSTRING:
+ case V_ASN1_VISIBLESTRING:
+ case V_ASN1_GENERALSTRING:
+ case V_ASN1_UNIVERSALSTRING:
+ case V_ASN1_BMPSTRING:
+ case V_ASN1_UTF8STRING:
+ case V_ASN1_OTHER:
+ case V_ASN1_SET:
+ case V_ASN1_SEQUENCE:
+ default:
+ if (utype == V_ASN1_BMPSTRING && (len & 1)) {
ASN1err(ASN1_F_ASN1_EX_C2I,
ASN1_R_BMPSTRING_IS_WRONG_LENGTH);
goto err;
}
- if (utype == V_ASN1_UNIVERSALSTRING && (len & 3))
- {
+ if (utype == V_ASN1_UNIVERSALSTRING && (len & 3)) {
ASN1err(ASN1_F_ASN1_EX_C2I,
ASN1_R_UNIVERSALSTRING_IS_WRONG_LENGTH);
goto err;
}
/* All based on ASN1_STRING and handled the same */
- if (!*pval)
- {
+ if (!*pval) {
stmp = ASN1_STRING_type_new(utype);
- if (!stmp)
- {
+ if (!stmp) {
ASN1err(ASN1_F_ASN1_EX_C2I,
ERR_R_MALLOC_FAILURE);
goto err;
}
*pval = (ASN1_VALUE *)stmp;
- }
- else
- {
+ } else {
stmp = (ASN1_STRING *)*pval;
stmp->type = utype;
}
/* If we've already allocated a buffer use it */
- if (*free_cont)
- {
+ if (*free_cont) {
if (stmp->data)
free(stmp->data);
stmp->data = (unsigned char *)cont; /* UGLY CAST! RL */
stmp->length = len;
*free_cont = 0;
- }
- else
- {
- if (!ASN1_STRING_set(stmp, cont, len))
- {
+ } else {
+ if (!ASN1_STRING_set(stmp, cont, len)) {
ASN1err(ASN1_F_ASN1_EX_C2I,
ERR_R_MALLOC_FAILURE);
ASN1_STRING_free(stmp);
ret = 1;
err:
- if (!ret)
- {
+ if (!ret) {
ASN1_TYPE_free(typ);
if (opval)
*opval = NULL;
long plen;
const unsigned char *p = *in, *q;
/* If not indefinite length constructed just add length */
- if (inf == 0)
- {
+ if (inf == 0) {
*in += len;
return 1;
}
* are encountered increment the expected eoc count otherwise just
* skip to the end of the data.
*/
- while (len > 0)
- {
- if(asn1_check_eoc(&p, len))
- {
+ while (len > 0) {
+ if(asn1_check_eoc(&p, len)) {
expected_eoc--;
if (expected_eoc == 0)
break;
q = p;
/* Just read in a header: only care about the length */
if(!asn1_check_tlen(&plen, NULL, NULL, &inf, NULL, &p, len,
- -1, 0, 0, NULL))
- {
+ -1, 0, 0, NULL)) {
ASN1err(ASN1_F_ASN1_FIND_END, ERR_R_NESTED_ASN1_ERROR);
return 0;
}
p += plen;
len -= p - q;
}
- if (expected_eoc)
- {
+ if (expected_eoc) {
ASN1err(ASN1_F_ASN1_FIND_END, ASN1_R_MISSING_EOC);
return 0;
}
inf &= 1;
/* If no buffer and not indefinite length constructed just pass over
* the encoded data */
- if (!buf && !inf)
- {
+ if (!buf && !inf) {
*in += len;
return 1;
}
- while(len > 0)
- {
+ while(len > 0) {
q = p;
/* Check for EOC */
- if (asn1_check_eoc(&p, len))
- {
+ if (asn1_check_eoc(&p, len)) {
/* EOC is illegal outside indefinite length
* constructed form */
- if (!inf)
- {
+ if (!inf) {
ASN1err(ASN1_F_ASN1_COLLECT,
ASN1_R_UNEXPECTED_EOC);
return 0;
}
if (!asn1_check_tlen(&plen, NULL, NULL, &ininf, &cst, &p,
- len, tag, aclass, 0, NULL))
- {
+ len, tag, aclass, 0, NULL)) {
ASN1err(ASN1_F_ASN1_COLLECT, ERR_R_NESTED_ASN1_ERROR);
return 0;
}
/* If indefinite length constructed update max length */
- if (cst)
- {
- if (depth >= ASN1_MAX_STRING_NEST)
- {
+ if (cst) {
+ if (depth >= ASN1_MAX_STRING_NEST) {
ASN1err(ASN1_F_ASN1_COLLECT,
ASN1_R_NESTED_ASN1_STRING);
return 0;
return 0;
len -= p - q;
}
- if (inf)
- {
+ if (inf) {
ASN1err(ASN1_F_ASN1_COLLECT, ASN1_R_MISSING_EOC);
return 0;
}
static int collect_data(BUF_MEM *buf, const unsigned char **p, long plen)
{
int len;
- if (buf)
- {
+ if (buf) {
len = buf->length;
- if (!BUF_MEM_grow_clean(buf, len + plen))
- {
+ if (!BUF_MEM_grow_clean(buf, len + plen)) {
ASN1err(ASN1_F_COLLECT_DATA, ERR_R_MALLOC_FAILURE);
return 0;
}
const unsigned char *p;
if (len < 2) return 0;
p = *in;
- if (!p[0] && !p[1])
- {
+ if (!p[0] && !p[1]) {
*in += 2;
return 1;
}
p = *in;
q = p;
- if (ctx && ctx->valid)
- {
+ if (ctx && ctx->valid) {
i = ctx->ret;
plen = ctx->plen;
pclass = ctx->pclass;
ptag = ctx->ptag;
p += ctx->hdrlen;
- }
- else
- {
+ } else {
i = ASN1_get_object(&p, &plen, &ptag, &pclass, len);
- if (ctx)
- {
+ if (ctx) {
ctx->ret = i;
ctx->plen = plen;
ctx->pclass = pclass;
/* If definite length, and no error, length +
* header can't exceed total amount of data available.
*/
- if (!(i & 0x81) && ((plen + ctx->hdrlen) > len))
- {
+ if (!(i & 0x81) && ((plen + ctx->hdrlen) > len)) {
ASN1err(ASN1_F_ASN1_CHECK_TLEN,
ASN1_R_TOO_LONG);
asn1_tlc_clear(ctx);
}
}
- if (i & 0x80)
- {
+ if (i & 0x80) {
ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_BAD_OBJECT_HEADER);
asn1_tlc_clear(ctx);
return 0;
}
- if (exptag >= 0)
- {
- if ((exptag != ptag) || (expclass != pclass))
- {
+ if (exptag >= 0) {
+ if ((exptag != ptag) || (expclass != pclass)) {
/* If type is OPTIONAL, not an error:
* indicate missing type.
*/
static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out,
const ASN1_ITEM *it, int flags)
{
- if (out && !*out)
- {
+ if (out && !*out) {
unsigned char *p, *buf;
int len;
len = ASN1_item_ex_i2d(&val, NULL, it, -1, flags);
if (aux && aux->asn1_cb)
asn1_cb = aux->asn1_cb;
- switch(it->itype)
- {
+ switch(it->itype) {
- case ASN1_ITYPE_PRIMITIVE:
+ case ASN1_ITYPE_PRIMITIVE:
if (it->templates)
return asn1_template_ex_i2d(pval, out, it->templates,
tag, aclass);
return asn1_i2d_ex_primitive(pval, out, it, tag, aclass);
break;
- case ASN1_ITYPE_MSTRING:
+ case ASN1_ITYPE_MSTRING:
return asn1_i2d_ex_primitive(pval, out, it, -1, aclass);
- case ASN1_ITYPE_CHOICE:
+ case ASN1_ITYPE_CHOICE:
if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL))
return 0;
i = asn1_get_choice_selector(pval, it);
- if ((i >= 0) && (i < it->tcount))
- {
+ if ((i >= 0) && (i < it->tcount)) {
ASN1_VALUE **pchval;
const ASN1_TEMPLATE *chtt;
chtt = it->templates + i;
return 0;
break;
- case ASN1_ITYPE_EXTERN:
+ case ASN1_ITYPE_EXTERN:
/* If new style i2d it does all the work */
ef = it->funcs;
return ef->asn1_ex_i2d(pval, out, it, tag, aclass);
- case ASN1_ITYPE_COMPAT:
+ case ASN1_ITYPE_COMPAT:
/* old style hackery... */
cf = it->funcs;
if (out)
*p = aclass | tag | (*p & V_ASN1_CONSTRUCTED);
return i;
- case ASN1_ITYPE_NDEF_SEQUENCE:
+ case ASN1_ITYPE_NDEF_SEQUENCE:
/* Use indefinite length constructed if requested */
if (aclass & ASN1_TFLG_NDEF) ndef = 2;
/* fall through */
- case ASN1_ITYPE_SEQUENCE:
+ case ASN1_ITYPE_SEQUENCE:
i = asn1_enc_restore(&seqcontlen, out, pval, it);
/* An error occurred */
if (i < 0)
/* Otherwise carry on */
seqcontlen = 0;
/* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */
- if (tag == -1)
- {
+ if (tag == -1) {
tag = V_ASN1_SEQUENCE;
/* Retain any other flags in aclass */
aclass = (aclass & ~ASN1_TFLG_TAG_CLASS)
if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL))
return 0;
/* First work out sequence content length */
- for (i = 0, tt = it->templates; i < it->tcount; tt++, i++)
- {
+ for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
const ASN1_TEMPLATE *seqtt;
ASN1_VALUE **pseqval;
seqtt = asn1_do_adb(pval, tt, 1);
return seqlen;
/* Output SEQUENCE header */
ASN1_put_object(out, ndef, seqcontlen, tag, aclass);
- for (i = 0, tt = it->templates; i < it->tcount; tt++, i++)
- {
+ for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
const ASN1_TEMPLATE *seqtt;
ASN1_VALUE **pseqval;
seqtt = asn1_do_adb(pval, tt, 1);
* the iclass argument may contain some additional flags
* which should be noted and passed down to other levels.
*/
- if (flags & ASN1_TFLG_TAG_MASK)
- {
+ if (flags & ASN1_TFLG_TAG_MASK) {
/* Error if argument and template tagging */
if (tag != -1)
/* FIXME: error code here */
/* Get tagging from template */
ttag = tt->tag;
tclass = flags & ASN1_TFLG_TAG_CLASS;
- }
- else if (tag != -1)
- {
+ } else if (tag != -1) {
/* No template tagging, get from arguments */
ttag = tag;
tclass = iclass & ASN1_TFLG_TAG_CLASS;
- }
- else
- {
+ } else {
ttag = -1;
tclass = 0;
}
ndef = 2;
else ndef = 1;
- if (flags & ASN1_TFLG_SK_MASK)
- {
+ if (flags & ASN1_TFLG_SK_MASK) {
/* SET OF, SEQUENCE OF */
STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval;
int isset, sktag, skaclass;
if (!*pval)
return 0;
- if (flags & ASN1_TFLG_SET_OF)
- {
+ if (flags & ASN1_TFLG_SET_OF) {
isset = 1;
/* 2 means we reorder */
if (flags & ASN1_TFLG_SEQUENCE_OF)
/* Work out inner tag value: if EXPLICIT
* or no tagging use underlying type.
*/
- if ((ttag != -1) && !(flags & ASN1_TFLG_EXPTAG))
- {
+ if ((ttag != -1) && !(flags & ASN1_TFLG_EXPTAG)) {
sktag = ttag;
skaclass = tclass;
- }
- else
- {
+ } else {
skaclass = V_ASN1_UNIVERSAL;
if (isset)
sktag = V_ASN1_SET;
/* Determine total length of items */
skcontlen = 0;
- for (i = 0; i < sk_ASN1_VALUE_num(sk); i++)
- {
+ for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
skitem = sk_ASN1_VALUE_value(sk, i);
skcontlen += ASN1_item_ex_i2d(&skitem, NULL,
ASN1_ITEM_ptr(tt->item),
/* And the stuff itself */
asn1_set_seq_out(sk, out, skcontlen, ASN1_ITEM_ptr(tt->item),
isset, iclass);
- if (ndef == 2)
- {
+ if (ndef == 2) {
ASN1_put_eoc(out);
if (flags & ASN1_TFLG_EXPTAG)
ASN1_put_eoc(out);
return ret;
}
- if (flags & ASN1_TFLG_EXPTAG)
- {
+ if (flags & ASN1_TFLG_EXPTAG) {
/* EXPLICIT tagging */
/* Find length of tagged item */
i = ASN1_item_ex_i2d(pval, NULL, ASN1_ITEM_ptr(tt->item),
return 0;
/* Find length of EXPLICIT tag */
ret = ASN1_object_size(ndef, i, ttag);
- if (out)
- {
+ if (out) {
/* Output tag and item */
ASN1_put_object(out, ndef, i, ttag, tclass);
ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item),
/* Don't need to sort less than 2 items */
if (sk_ASN1_VALUE_num(sk) < 2)
do_sort = 0;
- else
- {
+ else {
derlst = malloc(sk_ASN1_VALUE_num(sk)
* sizeof(*derlst));
tmpdat = malloc(skcontlen);
}
}
/* If not sorting just output each item */
- if (!do_sort)
- {
- for (i = 0; i < sk_ASN1_VALUE_num(sk); i++)
- {
+ if (!do_sort) {
+ for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
skitem = sk_ASN1_VALUE_value(sk, i);
ASN1_item_ex_i2d(&skitem, out, item, -1, iclass);
}
p = tmpdat;
/* Doing sort: build up a list of each member's DER encoding */
- for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++)
- {
+ for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) {
skitem = sk_ASN1_VALUE_value(sk, i);
tder->data = p;
tder->length = ASN1_item_ex_i2d(&skitem, &p, item, -1, iclass);
qsort(derlst, sk_ASN1_VALUE_num(sk), sizeof(*derlst), der_cmp);
/* Output sorted DER encoding */
p = *out;
- for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++)
- {
+ for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) {
memcpy(p, tder->data, tder->length);
p += tder->length;
}
*out = p;
/* If do_sort is 2 then reorder the STACK */
- if (do_sort == 2)
- {
- for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk);
- i++, tder++)
+ if (do_sort == 2) {
+ for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++)
(void)sk_ASN1_VALUE_set(sk, i, tder->field);
}
free(derlst);
return 0;
/* -2 return is special meaning use ndef */
- if (len == -2)
- {
+ if (len == -2) {
ndef = 2;
len = 0;
}
if (tag == -1) tag = utype;
/* Output tag+length followed by content octets */
- if (out)
- {
+ if (out) {
if (usetag)
ASN1_put_object(out, ndef, len, tag, aclass);
asn1_ex_i2c(pval, *out, &utype, it);
return pf->prim_i2c(pval, cout, putype, it);
/* Should type be omitted? */
- if ((it->itype != ASN1_ITYPE_PRIMITIVE)
- || (it->utype != V_ASN1_BOOLEAN))
- {
+ if ((it->itype != ASN1_ITYPE_PRIMITIVE) || (it->utype != V_ASN1_BOOLEAN)) {
if (!*pval) return -1;
}
- if (it->itype == ASN1_ITYPE_MSTRING)
- {
+ if (it->itype == ASN1_ITYPE_MSTRING) {
/* If MSTRING type set the underlying type */
strtmp = (ASN1_STRING *)*pval;
utype = strtmp->type;
*putype = utype;
- }
- else if (it->utype == V_ASN1_ANY)
- {
+ } else if (it->utype == V_ASN1_ANY) {
/* If ANY set type and pointer to value */
ASN1_TYPE *typ;
typ = (ASN1_TYPE *)*pval;
}
else utype = *putype;
- switch(utype)
- {
- case V_ASN1_OBJECT:
+ switch(utype) {
+ case V_ASN1_OBJECT:
otmp = (ASN1_OBJECT *)*pval;
cont = otmp->data;
len = otmp->length;
break;
- case V_ASN1_NULL:
+ case V_ASN1_NULL:
cont = NULL;
len = 0;
break;
- case V_ASN1_BOOLEAN:
+ case V_ASN1_BOOLEAN:
tbool = (ASN1_BOOLEAN *)pval;
if (*tbool == -1)
return -1;
- if (it->utype != V_ASN1_ANY)
- {
+ if (it->utype != V_ASN1_ANY) {
/* Default handling if value == size field then omit */
if (*tbool && (it->size > 0))
return -1;
len = 1;
break;
- case V_ASN1_BIT_STRING:
+ case V_ASN1_BIT_STRING:
return i2c_ASN1_BIT_STRING((ASN1_BIT_STRING *)*pval,
cout ? &cout : NULL);
break;
- case V_ASN1_INTEGER:
- case V_ASN1_NEG_INTEGER:
- case V_ASN1_ENUMERATED:
- case V_ASN1_NEG_ENUMERATED:
+ case V_ASN1_INTEGER:
+ case V_ASN1_NEG_INTEGER:
+ case V_ASN1_ENUMERATED:
+ case V_ASN1_NEG_ENUMERATED:
/* These are all have the same content format
* as ASN1_INTEGER
*/
cout ? &cout : NULL);
break;
- case V_ASN1_OCTET_STRING:
- case V_ASN1_NUMERICSTRING:
- case V_ASN1_PRINTABLESTRING:
- case V_ASN1_T61STRING:
- case V_ASN1_VIDEOTEXSTRING:
- case V_ASN1_IA5STRING:
- case V_ASN1_UTCTIME:
- case V_ASN1_GENERALIZEDTIME:
- case V_ASN1_GRAPHICSTRING:
- case V_ASN1_VISIBLESTRING:
- case V_ASN1_GENERALSTRING:
- case V_ASN1_UNIVERSALSTRING:
- case V_ASN1_BMPSTRING:
- case V_ASN1_UTF8STRING:
- case V_ASN1_SEQUENCE:
- case V_ASN1_SET:
- default:
+ case V_ASN1_OCTET_STRING:
+ case V_ASN1_NUMERICSTRING:
+ case V_ASN1_PRINTABLESTRING:
+ case V_ASN1_T61STRING:
+ case V_ASN1_VIDEOTEXSTRING:
+ case V_ASN1_IA5STRING:
+ case V_ASN1_UTCTIME:
+ case V_ASN1_GENERALIZEDTIME:
+ case V_ASN1_GRAPHICSTRING:
+ case V_ASN1_VISIBLESTRING:
+ case V_ASN1_GENERALSTRING:
+ case V_ASN1_UNIVERSALSTRING:
+ case V_ASN1_BMPSTRING:
+ case V_ASN1_UTF8STRING:
+ case V_ASN1_SEQUENCE:
+ case V_ASN1_SET:
+ default:
/* All based on ASN1_STRING and handled the same */
strtmp = (ASN1_STRING *)*pval;
/* Special handling for NDEF */
if ((it->size == ASN1_TFLG_NDEF)
- && (strtmp->flags & ASN1_STRING_FLAG_NDEF))
- {
- if (cout)
- {
+ && (strtmp->flags & ASN1_STRING_FLAG_NDEF)) {
+ if (cout) {
strtmp->data = cout;
strtmp->length = 0;
}
else
asn1_cb = 0;
- switch(it->itype)
- {
+ switch(it->itype) {
- case ASN1_ITYPE_PRIMITIVE:
+ case ASN1_ITYPE_PRIMITIVE:
if (it->templates)
ASN1_template_free(pval, it->templates);
else
ASN1_primitive_free(pval, it);
break;
- case ASN1_ITYPE_MSTRING:
+ case ASN1_ITYPE_MSTRING:
ASN1_primitive_free(pval, it);
break;
- case ASN1_ITYPE_CHOICE:
- if (asn1_cb)
- {
+ case ASN1_ITYPE_CHOICE:
+ if (asn1_cb) {
i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL);
if (i == 2)
return;
}
i = asn1_get_choice_selector(pval, it);
- if ((i >= 0) && (i < it->tcount))
- {
+ if ((i >= 0) && (i < it->tcount)) {
ASN1_VALUE **pchval;
tt = it->templates + i;
pchval = asn1_get_field_ptr(pval, tt);
}
if (asn1_cb)
asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL);
- if (!combine)
- {
+ if (!combine) {
free(*pval);
*pval = NULL;
}
break;
- case ASN1_ITYPE_COMPAT:
+ case ASN1_ITYPE_COMPAT:
cf = it->funcs;
if (cf && cf->asn1_free)
cf->asn1_free(*pval);
break;
- case ASN1_ITYPE_EXTERN:
+ case ASN1_ITYPE_EXTERN:
ef = it->funcs;
if (ef && ef->asn1_ex_free)
ef->asn1_ex_free(pval, it);
break;
- case ASN1_ITYPE_NDEF_SEQUENCE:
- case ASN1_ITYPE_SEQUENCE:
+ case ASN1_ITYPE_NDEF_SEQUENCE:
+ case ASN1_ITYPE_SEQUENCE:
if (asn1_do_lock(pval, -1, it) > 0)
return;
- if (asn1_cb)
- {
+ if (asn1_cb) {
i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL);
if (i == 2)
return;
* free up in reverse order.
*/
tt = it->templates + it->tcount - 1;
- for (i = 0; i < it->tcount; tt--, i++)
- {
+ for (i = 0; i < it->tcount; tt--, i++) {
ASN1_VALUE **pseqval;
seqtt = asn1_do_adb(pval, tt, 0);
if (!seqtt)
}
if (asn1_cb)
asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL);
- if (!combine)
- {
+ if (!combine) {
free(*pval);
*pval = NULL;
}
void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
{
int i;
- if (tt->flags & ASN1_TFLG_SK_MASK)
- {
+ if (tt->flags & ASN1_TFLG_SK_MASK) {
STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval;
- for (i = 0; i < sk_ASN1_VALUE_num(sk); i++)
- {
+ for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
ASN1_VALUE *vtmp;
vtmp = sk_ASN1_VALUE_value(sk, i);
asn1_item_combine_free(&vtmp, ASN1_ITEM_ptr(tt->item),
void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
{
int utype;
- if (it)
- {
+ if (it) {
const ASN1_PRIMITIVE_FUNCS *pf;
pf = it->funcs;
- if (pf && pf->prim_free)
- {
+ if (pf && pf->prim_free) {
pf->prim_free(pval, it);
return;
}
}
/* Special case: if 'it' is NULL free contents of ASN1_TYPE */
- if (!it)
- {
+ if (!it) {
ASN1_TYPE *typ = (ASN1_TYPE *)*pval;
utype = typ->type;
pval = &typ->value.asn1_value;
if (!*pval)
return;
- }
- else if (it->itype == ASN1_ITYPE_MSTRING)
- {
+ } else if (it->itype == ASN1_ITYPE_MSTRING) {
utype = -1;
if (!*pval)
return;
- }
- else
- {
+ } else {
utype = it->utype;
if ((utype != V_ASN1_BOOLEAN) && !*pval)
return;
}
- switch(utype)
- {
- case V_ASN1_OBJECT:
+ switch(utype) {
+ case V_ASN1_OBJECT:
ASN1_OBJECT_free((ASN1_OBJECT *)*pval);
break;
- case V_ASN1_BOOLEAN:
+ case V_ASN1_BOOLEAN:
if (it)
*(ASN1_BOOLEAN *)pval = it->size;
else
*(ASN1_BOOLEAN *)pval = -1;
return;
- case V_ASN1_NULL:
+ case V_ASN1_NULL:
break;
- case V_ASN1_ANY:
+ case V_ASN1_ANY:
ASN1_primitive_free(pval, NULL);
free(*pval);
break;
- default:
+ default:
ASN1_STRING_free((ASN1_STRING *)*pval);
*pval = NULL;
break;
CRYPTO_push_info(it->sname);
#endif
- switch(it->itype)
- {
+ switch(it->itype) {
- case ASN1_ITYPE_EXTERN:
+ case ASN1_ITYPE_EXTERN:
ef = it->funcs;
- if (ef && ef->asn1_ex_new)
- {
+ if (ef && ef->asn1_ex_new) {
if (!ef->asn1_ex_new(pval, it))
goto memerr;
}
break;
- case ASN1_ITYPE_COMPAT:
+ case ASN1_ITYPE_COMPAT:
cf = it->funcs;
if (cf && cf->asn1_new) {
*pval = cf->asn1_new();
if (!*pval)
goto memerr;
- }
+ }
break;
- case ASN1_ITYPE_PRIMITIVE:
- if (it->templates)
- {
+ case ASN1_ITYPE_PRIMITIVE:
+ if (it->templates) {
if (!ASN1_template_new(pval, it->templates))
goto memerr;
}
goto memerr;
break;
- case ASN1_ITYPE_MSTRING:
+ case ASN1_ITYPE_MSTRING:
if (!ASN1_primitive_new(pval, it))
goto memerr;
break;
- case ASN1_ITYPE_CHOICE:
- if (asn1_cb)
- {
+ case ASN1_ITYPE_CHOICE:
+ if (asn1_cb) {
i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL);
if (!i)
goto auxerr;
- if (i==2)
- {
+ if (i==2) {
#ifdef CRYPTO_MDEBUG
if (it->sname)
CRYPTO_pop_info();
return 1;
}
}
- if (!combine)
- {
+ if (!combine) {
*pval = malloc(it->size);
if (!*pval)
goto memerr;
goto auxerr;
break;
- case ASN1_ITYPE_NDEF_SEQUENCE:
- case ASN1_ITYPE_SEQUENCE:
- if (asn1_cb)
- {
+ case ASN1_ITYPE_NDEF_SEQUENCE:
+ case ASN1_ITYPE_SEQUENCE:
+ if (asn1_cb) {
i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL);
if (!i)
goto auxerr;
- if (i==2)
- {
+ if (i==2) {
#ifdef CRYPTO_MDEBUG
if (it->sname)
CRYPTO_pop_info();
return 1;
}
}
- if (!combine)
- {
+ if (!combine) {
*pval = malloc(it->size);
if (!*pval)
goto memerr;
asn1_do_lock(pval, 0, it);
asn1_enc_init(pval, it);
}
- for (i = 0, tt = it->templates; i < it->tcount; tt++, i++)
- {
+ for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
pseqval = asn1_get_field_ptr(pval, tt);
if (!ASN1_template_new(pseqval, tt))
goto memerr;
{
const ASN1_EXTERN_FUNCS *ef;
- switch(it->itype)
- {
+ switch(it->itype) {
- case ASN1_ITYPE_EXTERN:
+ case ASN1_ITYPE_EXTERN:
ef = it->funcs;
if (ef && ef->asn1_ex_clear)
ef->asn1_ex_clear(pval, it);
break;
- case ASN1_ITYPE_PRIMITIVE:
+ case ASN1_ITYPE_PRIMITIVE:
if (it->templates)
asn1_template_clear(pval, it->templates);
else
asn1_primitive_clear(pval, it);
break;
- case ASN1_ITYPE_MSTRING:
+ case ASN1_ITYPE_MSTRING:
asn1_primitive_clear(pval, it);
break;
- case ASN1_ITYPE_COMPAT:
- case ASN1_ITYPE_CHOICE:
- case ASN1_ITYPE_SEQUENCE:
- case ASN1_ITYPE_NDEF_SEQUENCE:
+ case ASN1_ITYPE_COMPAT:
+ case ASN1_ITYPE_CHOICE:
+ case ASN1_ITYPE_SEQUENCE:
+ case ASN1_ITYPE_NDEF_SEQUENCE:
*pval = NULL;
break;
}
{
const ASN1_ITEM *it = ASN1_ITEM_ptr(tt->item);
int ret;
- if (tt->flags & ASN1_TFLG_OPTIONAL)
- {
+ if (tt->flags & ASN1_TFLG_OPTIONAL) {
asn1_template_clear(pval, tt);
return 1;
}
/* If ANY DEFINED BY nothing to do */
- if (tt->flags & ASN1_TFLG_ADB_MASK)
- {
+ if (tt->flags & ASN1_TFLG_ADB_MASK) {
*pval = NULL;
return 1;
}
CRYPTO_push_info(tt->field_name);
#endif
/* If SET OF or SEQUENCE OF, its a STACK */
- if (tt->flags & ASN1_TFLG_SK_MASK)
- {
+ if (tt->flags & ASN1_TFLG_SK_MASK) {
STACK_OF(ASN1_VALUE) *skval;
skval = sk_ASN1_VALUE_new_null();
- if (!skval)
- {
+ if (!skval) {
ASN1err(ASN1_F_ASN1_TEMPLATE_NEW, ERR_R_MALLOC_FAILURE);
ret = 0;
goto done;
ASN1_STRING *str;
int utype;
- if (it && it->funcs)
- {
+ if (it && it->funcs) {
const ASN1_PRIMITIVE_FUNCS *pf = it->funcs;
if (pf->prim_new)
return pf->prim_new(pval, it);
utype = -1;
else
utype = it->utype;
- switch(utype)
- {
- case V_ASN1_OBJECT:
+ switch(utype) {
+ case V_ASN1_OBJECT:
*pval = (ASN1_VALUE *)OBJ_nid2obj(NID_undef);
return 1;
- case V_ASN1_BOOLEAN:
+ case V_ASN1_BOOLEAN:
*(ASN1_BOOLEAN *)pval = it->size;
return 1;
- case V_ASN1_NULL:
+ case V_ASN1_NULL:
*pval = (ASN1_VALUE *)1;
return 1;
- case V_ASN1_ANY:
+ case V_ASN1_ANY:
typ = malloc(sizeof(ASN1_TYPE));
if (!typ)
return 0;
*pval = (ASN1_VALUE *)typ;
break;
- default:
+ default:
str = ASN1_STRING_type_new(utype);
if (it->itype == ASN1_ITYPE_MSTRING && str)
str->flags |= ASN1_STRING_FLAG_MSTRING;
static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
{
int utype;
- if (it && it->funcs)
- {
+ if (it && it->funcs) {
const ASN1_PRIMITIVE_FUNCS *pf = it->funcs;
if (pf->prim_clear)
pf->prim_clear(pval, it);
{
ASN1_PCTX *ret;
ret = malloc(sizeof(ASN1_PCTX));
- if (ret == NULL)
- {
+ if (ret == NULL) {
ASN1err(ASN1_F_ASN1_PCTX_NEW, ERR_R_MALLOC_FAILURE);
return NULL;
}
ASN1_aux_cb *asn1_cb;
ASN1_PRINT_ARG parg;
int i;
- if (aux && aux->asn1_cb)
- {
+ if (aux && aux->asn1_cb) {
parg.out = out;
parg.indent = indent;
parg.pctx = pctx;
}
else asn1_cb = 0;
- if(*fld == NULL)
- {
- if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_ABSENT)
- {
+ if(*fld == NULL) {
+ if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_ABSENT) {
if (!nohdr && !asn1_print_fsname(out, indent,
fname, sname, pctx))
return 0;
return 1;
}
- switch(it->itype)
- {
- case ASN1_ITYPE_PRIMITIVE:
- if(it->templates)
- {
+ switch(it->itype) {
+ case ASN1_ITYPE_PRIMITIVE:
+ if(it->templates) {
if (!asn1_template_print_ctx(out, fld, indent,
it->templates, pctx))
return 0;
}
/* fall thru */
- case ASN1_ITYPE_MSTRING:
+ case ASN1_ITYPE_MSTRING:
if (!asn1_primitive_print(out, fld, it,
indent, fname, sname,pctx))
return 0;
break;
- case ASN1_ITYPE_EXTERN:
+ case ASN1_ITYPE_EXTERN:
if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx))
return 0;
/* Use new style print routine if possible */
ef = it->funcs;
- if (ef && ef->asn1_ex_print)
- {
+ if (ef && ef->asn1_ex_print) {
i = ef->asn1_ex_print(out, fld, indent, "", pctx);
if (!i)
return 0;
return 0;
break;
- case ASN1_ITYPE_CHOICE:
+ case ASN1_ITYPE_CHOICE:
#if 0
if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx))
return 0;
/* CHOICE type, get selector */
i = asn1_get_choice_selector(fld, it);
/* This should never happen... */
- if((i < 0) || (i >= it->tcount))
- {
+ if((i < 0) || (i >= it->tcount)) {
if (BIO_printf(out,
"ERROR: selector [%d] invalid\n", i) <= 0)
return 0;
return 0;
break;
- case ASN1_ITYPE_SEQUENCE:
- case ASN1_ITYPE_NDEF_SEQUENCE:
+ case ASN1_ITYPE_SEQUENCE:
+ case ASN1_ITYPE_NDEF_SEQUENCE:
if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx))
return 0;
- if (fname || sname)
- {
- if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE)
- {
+ if (fname || sname) {
+ if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) {
if (BIO_puts(out, " {\n") <= 0)
return 0;
- }
- else
- {
+ } else {
if (BIO_puts(out, "\n") <= 0)
return 0;
}
}
- if (asn1_cb)
- {
+ if (asn1_cb) {
i = asn1_cb(ASN1_OP_PRINT_PRE, fld, it, &parg);
if (i == 0)
return 0;
}
/* Print each field entry */
- for(i = 0, tt = it->templates; i < it->tcount; i++, tt++)
- {
+ for(i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
const ASN1_TEMPLATE *seqtt;
seqtt = asn1_do_adb(fld, tt, 1);
tmpfld = asn1_get_field_ptr(fld, seqtt);
indent + 2, seqtt, pctx))
return 0;
}
- if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE)
- {
+ if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) {
if (BIO_printf(out, "%*s}\n", indent, "") < 0)
return 0;
}
- if (asn1_cb)
- {
+ if (asn1_cb) {
i = asn1_cb(ASN1_OP_PRINT_POST, fld, it, &parg);
if (i == 0)
return 0;
fname = NULL;
else
fname = tt->field_name;
- if(flags & ASN1_TFLG_SK_MASK)
- {
+ if(flags & ASN1_TFLG_SK_MASK) {
char *tname;
ASN1_VALUE *skitem;
STACK_OF(ASN1_VALUE) *stack;
/* SET OF, SEQUENCE OF */
- if (fname)
- {
- if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_SSOF)
- {
+ if (fname) {
+ if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_SSOF) {
if(flags & ASN1_TFLG_SET_OF)
tname = "SET";
else
return 0;
}
stack = (STACK_OF(ASN1_VALUE) *)*fld;
- for(i = 0; i < sk_ASN1_VALUE_num(stack); i++)
- {
+ for(i = 0; i < sk_ASN1_VALUE_num(stack); i++) {
if ((i > 0) && (BIO_puts(out, "\n") <= 0))
return 0;
}
if (!i && BIO_printf(out, "%*s<EMPTY>\n", indent + 2, "") <= 0)
return 0;
- if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE)
- {
+ if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) {
if (BIO_printf(out, "%*s}\n", indent, "") <= 0)
return 0;
}
return 1;
#endif
- while (indent > nspaces)
- {
+ while (indent > nspaces) {
if (BIO_write(out, spaces, nspaces) != nspaces)
return 0;
indent -= nspaces;
fname = NULL;
if (!sname && !fname)
return 1;
- if (fname)
- {
+ if (fname) {
if (BIO_puts(out, fname) <= 0)
return 0;
}
- if (sname)
- {
- if (fname)
- {
+ if (sname) {
+ if (fname) {
if (BIO_printf(out, " (%s)", sname) <= 0)
return 0;
- }
- else
- {
+ } else {
if (BIO_puts(out, sname) <= 0)
return 0;
}
const ASN1_PCTX *pctx)
{
const char *str;
- switch (boolval)
- {
- case -1:
+ switch (boolval) {
+ case -1:
str = "BOOL ABSENT";
break;
- case 0:
+ case 0:
str = "FALSE";
break;
static int asn1_print_obstring_ctx(BIO *out, ASN1_STRING *str, int indent,
const ASN1_PCTX *pctx)
{
- if (str->type == V_ASN1_BIT_STRING)
- {
+ if (str->type == V_ASN1_BIT_STRING) {
if (BIO_printf(out, " (%ld unused bits)\n",
str->flags & 0x7) <= 0)
return 0;
utype = str->type & ~V_ASN1_NEG;
else
utype = it->utype;
- if (utype == V_ASN1_ANY)
- {
+ if (utype == V_ASN1_ANY) {
ASN1_TYPE *atype = (ASN1_TYPE *)*fld;
utype = atype->type;
fld = &atype->value.asn1_value;
pname = NULL;
else
pname = ASN1_tag2str(utype);
- }
- else
- {
+ } else {
if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_TYPE)
pname = ASN1_tag2str(utype);
else
pname = NULL;
}
- if (utype == V_ASN1_NULL)
- {
+ if (utype == V_ASN1_NULL) {
if (BIO_puts(out, "NULL\n") <= 0)
return 0;
return 1;
}
- if (pname)
- {
+ if (pname) {
if (BIO_puts(out, pname) <= 0)
return 0;
if (BIO_puts(out, ":") <= 0)
return 0;
}
- switch (utype)
- {
- case V_ASN1_BOOLEAN:
+ switch (utype) {
+ case V_ASN1_BOOLEAN:
{
int boolval = *(int *)fld;
if (boolval == -1)
}
break;
- case V_ASN1_INTEGER:
- case V_ASN1_ENUMERATED:
+ case V_ASN1_INTEGER:
+ case V_ASN1_ENUMERATED:
ret = asn1_print_integer_ctx(out, str, pctx);
break;
- case V_ASN1_UTCTIME:
+ case V_ASN1_UTCTIME:
ret = ASN1_UTCTIME_print(out, str);
break;
- case V_ASN1_GENERALIZEDTIME:
+ case V_ASN1_GENERALIZEDTIME:
ret = ASN1_GENERALIZEDTIME_print(out, str);
break;
- case V_ASN1_OBJECT:
+ case V_ASN1_OBJECT:
ret = asn1_print_oid_ctx(out, (const ASN1_OBJECT *)*fld, pctx);
break;
- case V_ASN1_OCTET_STRING:
- case V_ASN1_BIT_STRING:
+ case V_ASN1_OCTET_STRING:
+ case V_ASN1_BIT_STRING:
ret = asn1_print_obstring_ctx(out, str, indent, pctx);
needlf = 0;
break;
- case V_ASN1_SEQUENCE:
- case V_ASN1_SET:
- case V_ASN1_OTHER:
+ case V_ASN1_SEQUENCE:
+ case V_ASN1_SET:
+ case V_ASN1_OTHER:
if (BIO_puts(out, "\n") <= 0)
return 0;
if (ASN1_parse_dump(out, str->data, str->length,
needlf = 0;
break;
- default:
+ default:
ret = ASN1_STRING_print_ex(out, str, pctx->str_flags);
}
if (!aux || !(aux->flags & ASN1_AFLG_REFCOUNT))
return 0;
lck = offset2ptr(*pval, aux->ref_offset);
- if (op == 0)
- {
+ if (op == 0) {
*lck = 1;
return 1;
}
{
ASN1_ENCODING *enc;
enc = asn1_get_enc_ptr(pval, it);
- if (enc)
- {
+ if (enc) {
enc->enc = NULL;
enc->len = 0;
enc->modified = 1;
{
ASN1_ENCODING *enc;
enc = asn1_get_enc_ptr(pval, it);
- if (enc)
- {
+ if (enc) {
if (enc->enc)
free(enc->enc);
enc->enc = NULL;
enc = asn1_get_enc_ptr(pval, it);
if (!enc || enc->modified)
return 0;
- if (out)
- {
+ if (out) {
memcpy(*out, enc->enc, enc->len);
*out += enc->len;
}
sfld = offset2ptr(*pval, adb->offset);
/* Check if NULL */
- if (!sfld)
- {
+ if (!sfld) {
if (!adb->null_tt)
goto err;
return adb->null_tt;
{
if (!alg)
return 0;
- if (ptype != V_ASN1_UNDEF)
- {
+ if (ptype != V_ASN1_UNDEF) {
if (alg->parameter == NULL)
alg->parameter = ASN1_TYPE_new();
if (alg->parameter == NULL)
return 0;
}
- if (alg)
- {
+ if (alg) {
if (alg->algorithm)
ASN1_OBJECT_free(alg->algorithm);
alg->algorithm = aobj;
}
if (ptype == 0)
return 1;
- if (ptype == V_ASN1_UNDEF)
- {
- if (alg->parameter)
- {
+ if (ptype == V_ASN1_UNDEF) {
+ if (alg->parameter) {
ASN1_TYPE_free(alg->parameter);
alg->parameter = NULL;
}
{
if (paobj)
*paobj = algor->algorithm;
- if (pptype)
- {
- if (algor->parameter == NULL)
- {
+ if (pptype) {
+ if (algor->parameter == NULL) {
*pptype = V_ASN1_UNDEF;
return;
}
/* Just set cmp function here. We don't sort because that
* would affect the output of X509_CRL_print().
*/
- case ASN1_OP_D2I_POST:
+ case ASN1_OP_D2I_POST:
(void)sk_X509_REVOKED_set_cmp_func(a->revoked,X509_REVOKED_cmp);
break;
-}
+ }
return 1;
}
revoked = X509_CRL_get_REVOKED(crl);
gens = NULL;
- for (i = 0; i < sk_X509_REVOKED_num(revoked); i++)
- {
+ for (i = 0; i < sk_X509_REVOKED_num(revoked); i++) {
X509_REVOKED *rev = sk_X509_REVOKED_value(revoked, i);
STACK_OF(X509_EXTENSION) *exts;
ASN1_ENUMERATED *reason;
gtmp = X509_REVOKED_get_ext_d2i(rev,
NID_certificate_issuer,
&j, NULL);
- if (!gtmp && (j != -1))
- {
+ if (!gtmp && (j != -1)) {
crl->flags |= EXFLAG_INVALID;
return 1;
}
- if (gtmp)
- {
+ if (gtmp) {
gens = gtmp;
- if (!crl->issuers)
- {
+ if (!crl->issuers) {
crl->issuers = sk_GENERAL_NAMES_new_null();
if (!crl->issuers)
return 0;
reason = X509_REVOKED_get_ext_d2i(rev, NID_crl_reason,
&j, NULL);
- if (!reason && (j != -1))
- {
+ if (!reason && (j != -1)) {
crl->flags |= EXFLAG_INVALID;
return 1;
}
- if (reason)
- {
+ if (reason) {
rev->reason = ASN1_ENUMERATED_get(reason);
ASN1_ENUMERATED_free(reason);
- }
- else
+ } else
rev->reason = CRL_REASON_NONE;
/* Check for critical CRL entry extensions */
exts = rev->extensions;
- for (j = 0; j < sk_X509_EXTENSION_num(exts); j++)
- {
+ for (j = 0; j < sk_X509_EXTENSION_num(exts); j++) {
ext = sk_X509_EXTENSION_value(exts, j);
- if (ext->critical > 0)
- {
+ if (ext->critical > 0) {
if (OBJ_obj2nid(ext->object) ==
NID_certificate_issuer)
continue;
X509_EXTENSION *ext;
int idx;
- switch(operation)
- {
- case ASN1_OP_NEW_POST:
+ switch(operation) {
+ case ASN1_OP_NEW_POST:
crl->idp = NULL;
crl->akid = NULL;
crl->flags = 0;
crl->base_crl_number = NULL;
break;
- case ASN1_OP_D2I_POST:
+ case ASN1_OP_D2I_POST:
#ifndef OPENSSL_NO_SHA
X509_CRL_digest(crl, EVP_sha1(), crl->sha1_hash, NULL);
#endif
exts = crl->crl->extensions;
- for (idx = 0; idx < sk_X509_EXTENSION_num(exts); idx++)
- {
+ for (idx = 0; idx < sk_X509_EXTENSION_num(exts); idx++) {
int nid;
ext = sk_X509_EXTENSION_value(exts, idx);
nid = OBJ_obj2nid(ext->object);
if (nid == NID_freshest_crl)
crl->flags |= EXFLAG_FRESHEST;
- if (ext->critical > 0)
- {
+ if (ext->critical > 0) {
/* We handle IDP and deltas */
if ((nid == NID_issuing_distribution_point)
|| (nid == NID_delta_crl))
if (!crl_set_issuers(crl))
return 0;
- if (crl->meth->crl_init)
- {
+ if (crl->meth->crl_init) {
if (crl->meth->crl_init(crl) == 0)
return 0;
}
break;
- case ASN1_OP_FREE_POST:
- if (crl->meth->crl_free)
- {
+ case ASN1_OP_FREE_POST:
+ if (crl->meth->crl_free) {
if (!crl->meth->crl_free(crl))
return 0;
}
int idp_only = 0;
/* Set various flags according to IDP */
crl->idp_flags |= IDP_PRESENT;
- if (idp->onlyuser > 0)
- {
+ if (idp->onlyuser > 0) {
idp_only++;
crl->idp_flags |= IDP_ONLYUSER;
}
- if (idp->onlyCA > 0)
- {
+ if (idp->onlyCA > 0) {
idp_only++;
crl->idp_flags |= IDP_ONLYCA;
}
- if (idp->onlyattr > 0)
- {
+ if (idp->onlyattr > 0) {
idp_only++;
crl->idp_flags |= IDP_ONLYATTR;
}
if (idp->indirectCRL > 0)
crl->idp_flags |= IDP_INDIRECT;
- if (idp->onlysomereasons)
- {
+ if (idp->onlysomereasons) {
crl->idp_flags |= IDP_REASONS;
if (idp->onlysomereasons->length > 0)
crl->idp_reasons = idp->onlysomereasons->data[0];
{
int i;
- if (!rev->issuer)
- {
+ if (!rev->issuer) {
if (!nm)
return 1;
if (!X509_NAME_cmp(nm, X509_CRL_get_issuer(crl)))
if (!nm)
nm = X509_CRL_get_issuer(crl);
- for (i = 0; i < sk_GENERAL_NAME_num(rev->issuer); i++)
- {
+ for (i = 0; i < sk_GENERAL_NAME_num(rev->issuer); i++) {
GENERAL_NAME *gen = sk_GENERAL_NAME_value(rev->issuer, i);
if (gen->type != GEN_DIRNAME)
continue;
/* Sort revoked into serial number order if not already sorted.
* Do this under a lock to avoid race condition.
*/
- if (!sk_X509_REVOKED_is_sorted(crl->crl->revoked))
- {
+ if (!sk_X509_REVOKED_is_sorted(crl->crl->revoked)) {
CRYPTO_w_lock(CRYPTO_LOCK_X509_CRL);
sk_X509_REVOKED_sort(crl->crl->revoked);
CRYPTO_w_unlock(CRYPTO_LOCK_X509_CRL);
if(idx < 0)
return 0;
/* Need to look for matching name */
- for(;idx < sk_X509_REVOKED_num(crl->crl->revoked); idx++)
- {
+ for(;idx < sk_X509_REVOKED_num(crl->crl->revoked); idx++) {
rev = sk_X509_REVOKED_value(crl->crl->revoked, idx);
if (ASN1_INTEGER_cmp(rev->serialNumber, serial))
return 0;
- if (crl_revoked_issuer_match(crl, issuer, rev))
- {
+ if (crl_revoked_issuer_match(crl, issuer, rev)) {
if (ret)
*ret = rev;
if (rev->reason == CRL_REASON_REMOVE_FROM_CRL)
X509_INFO *ret=NULL;
ret=(X509_INFO *)malloc(sizeof(X509_INFO));
- if (ret == NULL)
- {
+ if (ret == NULL) {
ASN1err(ASN1_F_X509_INFO_NEW,ERR_R_MALLOC_FAILURE);
return(NULL);
}
memerr:
ASN1err(ASN1_F_X509_NAME_EX_NEW, ERR_R_MALLOC_FAILURE);
- if (ret)
- {
+ if (ret) {
if (ret->entries)
sk_X509_NAME_ENTRY_free(ret->entries);
free(ret);
}
static void local_sk_X509_NAME_ENTRY_free(STACK_OF(X509_NAME_ENTRY) *ne)
- {
+{
sk_X509_NAME_ENTRY_free(ne);
- }
+}
static void local_sk_X509_NAME_ENTRY_pop_free(STACK_OF(X509_NAME_ENTRY) *ne)
- {
+{
sk_X509_NAME_ENTRY_pop_free(ne, X509_NAME_ENTRY_free);
- }
+}
static int x509_name_encode(X509_NAME *a)
{
int indent,
const char *fname,
const ASN1_PCTX *pctx)
- {
+{
if (X509_NAME_print_ex(out, (X509_NAME *)*pval,
indent, pctx->nm_flags) <= 0)
return 0;
return 2;
- }
+}
/* This function generates the canonical encoding of the Name structure.
* In it all strings are converted to UTF8, leading, trailing and
*/
static int x509_name_canon(X509_NAME *a)
- {
+{
unsigned char *p;
STACK_OF(STACK_OF_X509_NAME_ENTRY) *intname = NULL;
STACK_OF(X509_NAME_ENTRY) *entries = NULL;
X509_NAME_ENTRY *entry, *tmpentry = NULL;
int i, set = -1, ret = 0;
- if (a->canon_enc)
- {
+ if (a->canon_enc) {
free(a->canon_enc);
a->canon_enc = NULL;
}
/* Special case: empty X509_NAME => null encoding */
- if (sk_X509_NAME_ENTRY_num(a->entries) == 0)
- {
+ if (sk_X509_NAME_ENTRY_num(a->entries) == 0) {
a->canon_enclen = 0;
return 1;
- }
+ }
intname = sk_STACK_OF_X509_NAME_ENTRY_new_null();
if(!intname)
goto err;
- for(i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++)
- {
+ for(i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {
entry = sk_X509_NAME_ENTRY_value(a->entries, i);
- if(entry->set != set)
- {
+ if(entry->set != set) {
entries = sk_X509_NAME_ENTRY_new_null();
if(!entries)
goto err;
if(!sk_STACK_OF_X509_NAME_ENTRY_push(intname, entries))
goto err;
set = entry->set;
- }
+ }
tmpentry = X509_NAME_ENTRY_new();
tmpentry->object = OBJ_dup(entry->object);
if (!asn1_string_canon(tmpentry->value, entry->value))
if(!sk_X509_NAME_ENTRY_push(entries, tmpentry))
goto err;
tmpentry = NULL;
- }
+ }
/* Finally generate encoding */
sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname,
local_sk_X509_NAME_ENTRY_pop_free);
return ret;
- }
+}
/* Bitmap of all the types of string that will be canonicalized. */
static int asn1_string_canon(ASN1_STRING *out, ASN1_STRING *in)
- {
+{
unsigned char *to, *from;
int len, i;
/* If type not in bitmask just copy string across */
- if (!(ASN1_tag2bit(in->type) & ASN1_MASK_CANON))
- {
+ if (!(ASN1_tag2bit(in->type) & ASN1_MASK_CANON)) {
if (!ASN1_STRING_copy(out, in))
return 0;
return 1;
- }
+ }
out->type = V_ASN1_UTF8STRING;
out->length = ASN1_STRING_to_UTF8(&out->data, in);
*/
/* Ignore leading spaces */
- while((len > 0) && !(*from & 0x80) && isspace(*from))
- {
+ while((len > 0) && !(*from & 0x80) && isspace(*from)) {
from++;
len--;
- }
+ }
to = from + len - 1;
/* Ignore trailing spaces */
- while ((len > 0) && !(*to & 0x80) && isspace(*to))
- {
+ while ((len > 0) && !(*to & 0x80) && isspace(*to)) {
to--;
len--;
- }
+ }
to = out->data;
i = 0;
- while(i < len)
- {
+ while(i < len) {
/* If MSB set just copy across */
- if (*from & 0x80)
- {
+ if (*from & 0x80) {
*to++ = *from++;
i++;
}
/* Collapse multiple spaces */
- else if (isspace(*from))
- {
+ else if (isspace(*from)) {
/* Copy one space across */
*to++ = ' ';
/* Ignore subsequent spaces. Note: don't need to
* check len here because we know the last
* character is a non-space so we can't overflow.
*/
- do
- {
+ do {
from++;
i++;
- }
- while(!(*from & 0x80) && isspace(*from));
- }
- else
- {
+ } while(!(*from & 0x80) && isspace(*from));
+ } else {
*to++ = tolower(*from);
from++;
i++;
- }
}
+ }
out->length = to - out->data;
return 1;
- }
+}
static int i2d_name_canon(STACK_OF(STACK_OF_X509_NAME_ENTRY) *_intname,
unsigned char **in)
- {
+{
int i, len, ltmp;
ASN1_VALUE *v;
STACK_OF(ASN1_VALUE) *intname = (STACK_OF(ASN1_VALUE) *)_intname;
len = 0;
- for (i = 0; i < sk_ASN1_VALUE_num(intname); i++)
- {
+ for (i = 0; i < sk_ASN1_VALUE_num(intname); i++) {
v = sk_ASN1_VALUE_value(intname, i);
ltmp = ASN1_item_ex_i2d(&v, in,
ASN1_ITEM_rptr(X509_NAME_ENTRIES), -1, -1);
if (ltmp < 0)
return ltmp;
len += ltmp;
- }
- return len;
}
+ return len;
+}
int X509_NAME_set(X509_NAME **xn, X509_NAME *name)
- {
+{
X509_NAME *in;
if (!xn || !name) return(0);
- if (*xn != name)
- {
+ if (*xn != name) {
in=X509_NAME_dup(name);
- if (in != NULL)
- {
+ if (in != NULL) {
X509_NAME_free(*xn);
*xn=in;
- }
}
- return(*xn != NULL);
}
+ return(*xn != NULL);
+}
IMPLEMENT_STACK_OF(X509_NAME_ENTRY)
IMPLEMENT_ASN1_SET_OF(X509_NAME_ENTRY)
ret->cipher.cipher=EVP_get_cipherbyname(
OBJ_nid2ln(OBJ_obj2nid(ret->enc_algor->algorithm)));
- if (ret->cipher.cipher == NULL)
- {
+ if (ret->cipher.cipher == NULL) {
c.error=ASN1_R_UNSUPPORTED_CIPHER;
c.line=__LINE__;
goto err;
}
- if (ret->enc_algor->parameter->type == V_ASN1_OCTET_STRING)
- {
+ if (ret->enc_algor->parameter->type == V_ASN1_OCTET_STRING) {
i=ret->enc_algor->parameter->value.octet_string->length;
- if (i > EVP_MAX_IV_LENGTH)
- {
+ if (i > EVP_MAX_IV_LENGTH) {
c.error=ASN1_R_IV_TOO_LARGE;
c.line=__LINE__;
goto err;
static int pubkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
void *exarg)
{
- if (operation == ASN1_OP_FREE_POST)
- {
+ if (operation == ASN1_OP_FREE_POST) {
X509_PUBKEY *pubkey = (X509_PUBKEY *)*pval;
EVP_PKEY_free(pubkey->pkey);
}
if ((pk=X509_PUBKEY_new()) == NULL) goto error;
- if (pkey->ameth)
- {
- if (pkey->ameth->pub_encode)
- {
- if (!pkey->ameth->pub_encode(pk, pkey))
- {
+ if (pkey->ameth) {
+ if (pkey->ameth->pub_encode) {
+ if (!pkey->ameth->pub_encode(pk, pkey)) {
X509err(X509_F_X509_PUBKEY_SET,
X509_R_PUBLIC_KEY_ENCODE_ERROR);
goto error;
}
- }
- else
- {
+ } else {
X509err(X509_F_X509_PUBKEY_SET,
X509_R_METHOD_NOT_SUPPORTED);
goto error;
}
- }
- else
- {
+ } else {
X509err(X509_F_X509_PUBKEY_SET,X509_R_UNSUPPORTED_ALGORITHM);
goto error;
}
if (key == NULL) goto error;
- if (key->pkey != NULL)
- {
+ if (key->pkey != NULL) {
CRYPTO_add(&key->pkey->references, 1, CRYPTO_LOCK_EVP_PKEY);
return key->pkey;
}
if (key->public_key == NULL) goto error;
- if ((ret = EVP_PKEY_new()) == NULL)
- {
+ if ((ret = EVP_PKEY_new()) == NULL) {
X509err(X509_F_X509_PUBKEY_GET, ERR_R_MALLOC_FAILURE);
goto error;
}
- if (!EVP_PKEY_set_type(ret, OBJ_obj2nid(key->algor->algorithm)))
- {
+ if (!EVP_PKEY_set_type(ret, OBJ_obj2nid(key->algor->algorithm))) {
X509err(X509_F_X509_PUBKEY_GET,X509_R_UNSUPPORTED_ALGORITHM);
goto error;
}
- if (ret->ameth->pub_decode)
- {
- if (!ret->ameth->pub_decode(ret, key))
- {
+ if (ret->ameth->pub_decode) {
+ if (!ret->ameth->pub_decode(ret, key)) {
X509err(X509_F_X509_PUBKEY_GET,
X509_R_PUBLIC_KEY_DECODE_ERROR);
goto error;
}
- }
- else
- {
+ } else {
X509err(X509_F_X509_PUBKEY_GET, X509_R_METHOD_NOT_SUPPORTED);
goto error;
}
/* Check to see if another thread set key->pkey first */
CRYPTO_w_lock(CRYPTO_LOCK_EVP_PKEY);
- if (key->pkey)
- {
+ if (key->pkey) {
CRYPTO_w_unlock(CRYPTO_LOCK_EVP_PKEY);
EVP_PKEY_free(ret);
ret = key->pkey;
- }
- else
- {
+ } else {
key->pkey = ret;
CRYPTO_w_unlock(CRYPTO_LOCK_EVP_PKEY);
}
pktmp = X509_PUBKEY_get(xpk);
X509_PUBKEY_free(xpk);
if(!pktmp) return NULL;
- if(a)
- {
+ if(a) {
EVP_PKEY_free(*a);
*a = pktmp;
}
EVP_PKEY_free(pkey);
if (!key) return NULL;
*pp = q;
- if (a)
- {
+ if (a) {
RSA_free(*a);
*a = key;
}
int ret;
if (!a) return 0;
pktmp = EVP_PKEY_new();
- if (!pktmp)
- {
+ if (!pktmp) {
ASN1err(ASN1_F_I2D_RSA_PUBKEY, ERR_R_MALLOC_FAILURE);
return 0;
}
EVP_PKEY_free(pkey);
if (!key) return NULL;
*pp = q;
- if (a)
- {
+ if (a) {
DSA_free(*a);
*a = key;
}
int ret;
if(!a) return 0;
pktmp = EVP_PKEY_new();
- if(!pktmp)
- {
+ if(!pktmp) {
ASN1err(ASN1_F_I2D_DSA_PUBKEY, ERR_R_MALLOC_FAILURE);
return 0;
}
EVP_PKEY_free(pkey);
if (!key) return(NULL);
*pp = q;
- if (a)
- {
+ if (a) {
EC_KEY_free(*a);
*a = key;
}
EVP_PKEY *pktmp;
int ret;
if (!a) return(0);
- if ((pktmp = EVP_PKEY_new()) == NULL)
- {
+ if ((pktmp = EVP_PKEY_new()) == NULL) {
ASN1err(ASN1_F_I2D_EC_PUBKEY, ERR_R_MALLOC_FAILURE);
return(0);
}
{
if (!X509_ALGOR_set0(pub->algor, aobj, ptype, pval))
return 0;
- if (penc)
- {
+ if (penc) {
if (pub->public_key->data)
free(pub->public_key->data);
pub->public_key->data = penc;
{
if (ppkalg)
*ppkalg = pub->algor->algorithm;
- if (pk)
- {
+ if (pk) {
*pk = pub->public_key->data;
*ppklen = pub->public_key->length;
}
switch(operation) {
- case ASN1_OP_NEW_POST:
+ case ASN1_OP_NEW_POST:
ret->valid=0;
ret->name = NULL;
ret->ex_flags = 0;
CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509, ret, &ret->ex_data);
break;
- case ASN1_OP_D2I_POST:
+ case ASN1_OP_D2I_POST:
if (ret->name != NULL) free(ret->name);
ret->name=X509_NAME_oneline(ret->cert_info->subject,NULL,0);
break;
- case ASN1_OP_FREE_POST:
+ case ASN1_OP_FREE_POST:
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_X509, ret, &ret->ex_data);
X509_CERT_AUX_free(ret->aux);
ASN1_OCTET_STRING_free(ret->skid);
int X509_alias_set1(X509 *x, unsigned char *name, int len)
{
X509_CERT_AUX *aux;
- if (!name)
- {
+ if (!name) {
if (!x || !x->aux || !x->aux->alias)
return 1;
ASN1_UTF8STRING_free(x->aux->alias);
int X509_keyid_set1(X509 *x, unsigned char *id, int len)
{
X509_CERT_AUX *aux;
- if (!id)
- {
+ if (!id) {
if (!x || !x->aux || !x->aux->keyid)
return 1;
ASN1_OCTET_STRING_free(x->aux->keyid);
int i;
char *ret;
- if (x == NULL) return(NULL);
+ if (x == NULL)
+ return(NULL);
i=i2d(x,NULL);
b=malloc(i+10);
- if (b == NULL)
- {
- ASN1err(ASN1_F_ASN1_DUP,ERR_R_MALLOC_FAILURE); return(NULL);
+ if (b == NULL) {
+ ASN1err(ASN1_F_ASN1_DUP,ERR_R_MALLOC_FAILURE);
+ return(NULL);
}
p= b;
i=i2d(x,&p);
long i;
void *ret;
- if (x == NULL) return(NULL);
+ if (x == NULL)
+ return(NULL);
i=ASN1_item_i2d(x,&b,it);
- if (b == NULL)
- {
- ASN1err(ASN1_F_ASN1_ITEM_DUP,ERR_R_MALLOC_FAILURE); return(NULL);
+ if (b == NULL) {
+ ASN1err(ASN1_F_ASN1_ITEM_DUP,ERR_R_MALLOC_FAILURE);
+ return(NULL);
}
p= b;
ret=ASN1_item_d2i(NULL,&p,i, it);
long d;
a->type=V_ASN1_ENUMERATED;
- if (a->length < (int)(sizeof(long)+1))
- {
+ if (a->length < (int)(sizeof(long)+1)) {
if (a->data != NULL)
free(a->data);
if ((a->data=(unsigned char *)malloc(sizeof(long)+1)) != NULL)
memset((char *)a->data,0,sizeof(long)+1);
}
- if (a->data == NULL)
- {
+ if (a->data == NULL) {
ASN1err(ASN1_F_ASN1_ENUMERATED_SET,ERR_R_MALLOC_FAILURE);
return(0);
}
d=v;
- if (d < 0)
- {
+ if (d < 0) {
d= -d;
a->type=V_ASN1_NEG_ENUMERATED;
}
- for (i=0; i<sizeof(long); i++)
- {
+ for (i=0; i<sizeof(long); i++) {
if (d == 0) break;
buf[i]=(int)d&0xff;
d>>=8;
else if (i != V_ASN1_ENUMERATED)
return -1;
- if (a->length > (int)sizeof(long))
- {
+ if (a->length > (int)sizeof(long)) {
/* hmm... a bit ugly */
return(0xffffffffL);
}
if (a->data == NULL)
return 0;
- for (i=0; i<a->length; i++)
- {
+ for (i=0; i<a->length; i++) {
r<<=8;
r|=(unsigned char)a->data[i];
}
ret=M_ASN1_ENUMERATED_new();
else
ret=ai;
- if (ret == NULL)
- {
+ if (ret == NULL) {
ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_NESTED_ASN1_ERROR);
goto err;
}
else ret->type=V_ASN1_ENUMERATED;
j=BN_num_bits(bn);
len=((j == 0)?0:((j/8)+1));
- if (ret->length < len+4)
- {
+ if (ret->length < len+4) {
unsigned char *new_data=realloc(ret->data, len+4);
if (!new_data)
{
* field so make first two fields 00 to 99
*/
if (l < 13) goto err;
- for (i=0; i<7; i++)
- {
+ for (i=0; i<7; i++) {
if ((i == 6) && ((a[o] == 'Z') ||
(a[o] == '+') || (a[o] == '-')))
{ i++; break; }
if (a[o] == 'Z')
o++;
- else if ((a[o] == '+') || (a[o] == '-'))
- {
+ else if ((a[o] == '+') || (a[o] == '-')) {
o++;
if (o+4 > l) goto err;
- for (i=7; i<9; i++)
- {
+ for (i=7; i<9; i++) {
if ((a[o] < '0') || (a[o] > '9')) goto err;
n= a[o]-'0';
o++;
if ((n < min[i]) || (n > max[i])) goto err;
o++;
}
- }
- else
- {
+ } else {
/* Missing time zone information. */
goto err;
}
t.type=V_ASN1_GENERALIZEDTIME;
t.length=strlen(str);
t.data=(unsigned char *)str;
- if (ASN1_GENERALIZEDTIME_check(&t))
- {
- if (s != NULL)
- {
+ if (ASN1_GENERALIZEDTIME_check(&t)) {
+ if (s != NULL) {
if (!ASN1_STRING_set((ASN1_STRING *)s,
(unsigned char *)str,t.length))
return 0;
if (ts == NULL)
return(NULL);
- if (offset_day || offset_sec)
- {
+ if (offset_day || offset_sec) {
if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec))
return NULL;
}
p=(char *)s->data;
- if ((p == NULL) || ((size_t)s->length < len))
- {
+ if ((p == NULL) || ((size_t)s->length < len)) {
p=malloc(len);
- if (p == NULL)
- {
+ if (p == NULL) {
ASN1err(ASN1_F_ASN1_GENERALIZEDTIME_ADJ,
ERR_R_MALLOC_FAILURE);
return(NULL);
BIO *b;
int ret;
- if ((b=BIO_new(BIO_s_file())) == NULL)
- {
+ if ((b=BIO_new(BIO_s_file())) == NULL) {
ASN1err(ASN1_F_ASN1_I2D_FP,ERR_R_BUF_LIB);
return(0);
}
n=i2d(x,NULL);
b=(char *)malloc(n);
- if (b == NULL)
- {
+ if (b == NULL) {
ASN1err(ASN1_F_ASN1_I2D_BIO,ERR_R_MALLOC_FAILURE);
return(0);
}
p=(unsigned char *)b;
i2d(x,&p);
- for (;;)
- {
+ for (;;) {
i=BIO_write(out,&(b[j]),n);
if (i == n) break;
- if (i <= 0)
- {
+ if (i <= 0) {
ret=0;
break;
}
BIO *b;
int ret;
- if ((b=BIO_new(BIO_s_file())) == NULL)
- {
+ if ((b=BIO_new(BIO_s_file())) == NULL) {
ASN1err(ASN1_F_ASN1_ITEM_I2D_FP,ERR_R_BUF_LIB);
return(0);
}
int i,j=0,n,ret=1;
n = ASN1_item_i2d(x, &b, it);
- if (b == NULL)
- {
+ if (b == NULL) {
ASN1err(ASN1_F_ASN1_ITEM_I2D_BIO,ERR_R_MALLOC_FAILURE);
return(0);
}
- for (;;)
- {
+ for (;;) {
i=BIO_write(out,&(b[j]),n);
if (i == n) break;
- if (i <= 0)
- {
+ if (i <= 0) {
ret=0;
break;
}
int neg, ret;
/* Compare signs */
neg = x->type & V_ASN1_NEG;
- if (neg != (y->type & V_ASN1_NEG))
- {
+ if (neg != (y->type & V_ASN1_NEG)) {
if (neg)
return -1;
else
neg=a->type & V_ASN1_NEG;
if (a->length == 0)
ret=1;
- else
- {
+ else {
ret=a->length;
i=a->data[0];
if (!neg && (i > 127)) {
unsigned char *to,*s;
int i;
- if ((a == NULL) || ((*a) == NULL))
- {
+ if ((a == NULL) || ((*a) == NULL)) {
if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL);
ret->type=V_ASN1_INTEGER;
}
/* We must malloc stuff, even for 0 bytes otherwise it
* signifies a missing NULL parameter. */
s=(unsigned char *)malloc((int)len+1);
- if (s == NULL)
- {
+ if (s == NULL) {
i=ERR_R_MALLOC_FAILURE;
goto err;
}
* tolerate it.
*/
ret->type=V_ASN1_INTEGER;
-} else if (*p & 0x80) /* a negative number */
- {
+ } else if (*p & 0x80) /* a negative number */ {
ret->type=V_ASN1_NEG_INTEGER;
if ((*p == 0xff) && (len != 1)) {
p++;
len--;
- }
+ }
i = len;
p += i - 1;
to += i - 1;
*(to--) = 0;
i--;
p--;
- }
+ }
/* Special case: if all zeros then the number will be of
* the form FF followed by n zero bytes: this corresponds to
* 1 followed by n zero bytes. We've already written n zeros
*s = 1;
s[len] = 0;
len++;
- } else {
+ } else {
*(to--) = (*(p--) ^ 0xff) + 1;
i--;
for(;i > 0; i--) *(to--) = *(p--) ^ 0xff;
- }
-} else {
+ }
+ } else {
ret->type=V_ASN1_INTEGER;
- if ((*p == 0) && (len != 1))
- {
+ if ((*p == 0) && (len != 1)) {
p++;
len--;
}
memcpy(s,p,(int)len);
-}
+ }
if (ret->data != NULL) free(ret->data);
ret->data=s;
int inf,tag,xclass;
int i;
- if ((a == NULL) || ((*a) == NULL))
- {
+ if ((a == NULL) || ((*a) == NULL)) {
if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL);
ret->type=V_ASN1_INTEGER;
- }
- else
+ } else
ret=(*a);
p= *pp;
inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
- if (inf & 0x80)
- {
+ if (inf & 0x80) {
i=ASN1_R_BAD_OBJECT_HEADER;
goto err;
}
- if (tag != V_ASN1_INTEGER)
- {
+ if (tag != V_ASN1_INTEGER) {
i=ASN1_R_EXPECTING_AN_INTEGER;
goto err;
}
/* We must malloc stuff, even for 0 bytes otherwise it
* signifies a missing NULL parameter. */
s=(unsigned char *)malloc((int)len+1);
- if (s == NULL)
- {
+ if (s == NULL) {
i=ERR_R_MALLOC_FAILURE;
goto err;
}
ret->type=V_ASN1_INTEGER;
if(len) {
- if ((*p == 0) && (len != 1))
- {
+ if ((*p == 0) && (len != 1)) {
p++;
len--;
}
memcpy(s,p,(int)len);
p+=len;
-}
+ }
if (ret->data != NULL) free(ret->data);
ret->data=s;
long d;
a->type=V_ASN1_INTEGER;
- if (a->length < (int)(sizeof(long)+1))
- {
+ if (a->length < (int)(sizeof(long)+1)) {
if (a->data != NULL)
free(a->data);
if ((a->data=(unsigned char *)malloc(sizeof(long)+1)) != NULL)
memset((char *)a->data,0,sizeof(long)+1);
}
- if (a->data == NULL)
- {
+ if (a->data == NULL) {
ASN1err(ASN1_F_ASN1_INTEGER_SET,ERR_R_MALLOC_FAILURE);
return(0);
}
d=v;
- if (d < 0)
- {
+ if (d < 0) {
d= -d;
a->type=V_ASN1_NEG_INTEGER;
}
- for (i=0; i<sizeof(long); i++)
- {
+ for (i=0; i<sizeof(long); i++) {
if (d == 0) break;
buf[i]=(int)d&0xff;
d>>=8;
else if (i != V_ASN1_INTEGER)
return -1;
- if (a->length > (int)sizeof(long))
- {
+ if (a->length > (int)sizeof(long)) {
/* hmm... a bit ugly, return all ones */
return -1;
}
if (a->data == NULL)
return 0;
- for (i=0; i<a->length; i++)
- {
+ for (i=0; i<a->length; i++) {
r<<=8;
r|=(unsigned char)a->data[i];
}
ret=M_ASN1_INTEGER_new();
else
ret=ai;
- if (ret == NULL)
- {
+ if (ret == NULL) {
ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_NESTED_ASN1_ERROR);
goto err;
}
else ret->type=V_ASN1_INTEGER;
j=BN_num_bits(bn);
len=((j == 0)?0:((j/8)+1));
- if (ret->length < len+4)
- {
+ if (ret->length < len+4) {
unsigned char *new_data=realloc(ret->data, len+4);
- if (!new_data)
- {
+ if (!new_data) {
ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_MALLOC_FAILURE);
goto err;
}
}
ret->length=BN_bn2bin(bn,ret->data);
/* Correct zero case */
- if(!ret->length)
- {
+ if(!ret->length) {
ret->data[0] = 0;
ret->length = 1;
}
p=buf;
c= *(p++);
num--;
- if ((c >= '0') && (c <= '2'))
- {
+ if ((c >= '0') && (c <= '2')) {
first= c-'0';
- }
- else
- {
+ } else {
ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_FIRST_NUM_TOO_LARGE);
goto err;
}
- if (num <= 0)
- {
+ if (num <= 0) {
ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_MISSING_SECOND_NUMBER);
goto err;
}
c= *(p++);
num--;
- for (;;)
- {
+ for (;;) {
if (num <= 0) break;
- if ((c != '.') && (c != ' '))
- {
+ if ((c != '.') && (c != ' ')) {
ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_SEPARATOR);
goto err;
}
l=0;
use_bn = 0;
- for (;;)
- {
+ for (;;) {
if (num <= 0) break;
num--;
c= *(p++);
if ((c == ' ') || (c == '.'))
break;
- if ((c < '0') || (c > '9'))
- {
+ if ((c < '0') || (c > '9')) {
ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_DIGIT);
goto err;
}
- if (!use_bn && l >= ((ULONG_MAX - 80) / 10L))
- {
+ if (!use_bn && l >= ((ULONG_MAX - 80) / 10L)) {
use_bn = 1;
if (!bl)
bl = BN_new();
if (!bl || !BN_set_word(bl, l))
goto err;
}
- if (use_bn)
- {
+ if (use_bn) {
if (!BN_mul_word(bl, 10L)
|| !BN_add_word(bl, c-'0'))
goto err;
else
l=l*10L+(long)(c-'0');
}
- if (len == 0)
- {
- if ((first < 2) && (l >= 40))
- {
+ if (len == 0) {
+ if ((first < 2) && (l >= 40)) {
ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_SECOND_NUMBER_TOO_LARGE);
goto err;
}
- if (use_bn)
- {
+ if (use_bn) {
if (!BN_add_word(bl, first * 40))
goto err;
}
l+=(long)first*40;
}
i=0;
- if (use_bn)
- {
+ if (use_bn) {
int blsize;
blsize = BN_num_bits(bl);
blsize = (blsize + 6)/7;
- if (blsize > tmpsize)
- {
+ if (blsize > tmpsize) {
if (tmp != ftmp)
free(tmp);
tmpsize = blsize + 32;
}
while(blsize--)
tmp[i++] = (unsigned char)BN_div_word(bl, 0x80L);
- }
- else
- {
+ } else {
- for (;;)
- {
+ for (;;) {
tmp[i++]=(unsigned char)l&0x7f;
l>>=7L;
if (l == 0L) break;
}
}
- if (out != NULL)
- {
- if (len+i > olen)
- {
+ if (out != NULL) {
+ if (len+i > olen) {
ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_BUFFER_TOO_SMALL);
goto err;
}
if ((a == NULL) || (a->data == NULL))
return(BIO_write(bp,"NULL",4));
i=i2t_ASN1_OBJECT(buf,sizeof buf,a);
- if (i > (int)(sizeof(buf) - 1))
- {
+ if (i > (int)(sizeof(buf) - 1)) {
p = malloc(i + 1);
if (!p)
return -1;
ASN1_OBJECT *ret = NULL;
p= *pp;
inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
- if (inf & 0x80)
- {
+ if (inf & 0x80) {
i=ASN1_R_BAD_OBJECT_HEADER;
goto err;
}
- if (tag != V_ASN1_OBJECT)
- {
+ if (tag != V_ASN1_OBJECT) {
i=ASN1_R_EXPECTING_AN_OBJECT;
goto err;
}
/* Sanity check OID encoding: can't have leading 0x80 in
* subidentifiers, see: X.690 8.19.2
*/
- for (i = 0, p = *pp; i < len; i++, p++)
- {
- if (*p == 0x80 && (!i || !(p[-1] & 0x80)))
- {
+ for (i = 0, p = *pp; i < len; i++, p++) {
+ if (*p == 0x80 && (!i || !(p[-1] & 0x80))) {
ASN1err(ASN1_F_C2I_ASN1_OBJECT,ASN1_R_INVALID_OBJECT_ENCODING);
return NULL;
}
/* only the ASN1_OBJECTs from the 'table' will have values
* for ->sn or ->ln */
if ((a == NULL) || ((*a) == NULL) ||
- !((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC))
- {
+ !((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC)) {
if ((ret=ASN1_OBJECT_new()) == NULL) return(NULL);
}
else ret=(*a);
data = (unsigned char *)ret->data;
ret->data = NULL;
/* once detached we can change it */
- if ((data == NULL) || (ret->length < len))
- {
+ if ((data == NULL) || (ret->length < len)) {
ret->length=0;
if (data != NULL) free(data);
data=(unsigned char *)malloc(len ? (int)len : 1);
- if (data == NULL)
- { i=ERR_R_MALLOC_FAILURE; goto err; }
+ if (data == NULL) { i=ERR_R_MALLOC_FAILURE; goto err; }
ret->flags|=ASN1_OBJECT_FLAG_DYNAMIC_DATA;
}
memcpy(data,p,(int)len);
ASN1_OBJECT *ret;
ret=(ASN1_OBJECT *)malloc(sizeof(ASN1_OBJECT));
- if (ret == NULL)
- {
+ if (ret == NULL) {
ASN1err(ASN1_F_ASN1_OBJECT_NEW,ERR_R_MALLOC_FAILURE);
return(NULL);
}
void ASN1_OBJECT_free(ASN1_OBJECT *a)
{
if (a == NULL) return;
- if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS)
- {
+ if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS) {
#ifndef CONST_STRICT /* disable purely for compile-time strict const checking. Doing this on a "real" compile will cause memory leaks */
if (a->sn != NULL) free((void *)a->sn);
if (a->ln != NULL) free((void *)a->ln);
#endif
a->sn=a->ln=NULL;
}
- if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA)
- {
+ if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA) {
if (a->data != NULL) free((void *)a->data);
a->data=NULL;
a->length=0;
if (len <= 0) len= -1;
if (s == NULL) return(V_ASN1_PRINTABLESTRING);
- while ((*s) && (len-- != 0))
- {
+ while ((*s) && (len-- != 0)) {
c= *(s++);
if (!( ((c >= 'a') && (c <= 'z')) ||
((c >= 'A') && (c <= 'Z')) ||
if (s->type != V_ASN1_UNIVERSALSTRING) return(0);
if ((s->length%4) != 0) return(0);
p=s->data;
- for (i=0; i<s->length; i+=4)
- {
+ for (i=0; i<s->length; i+=4) {
if ((p[0] != '\0') || (p[1] != '\0') || (p[2] != '\0'))
break;
else
}
if (i < s->length) return(0);
p=s->data;
- for (i=3; i<s->length; i+=4)
- {
+ for (i=3; i<s->length; i+=4) {
*(p++)=s->data[i];
}
*(p)='\0';
{
EVP_MD_CTX ctx;
EVP_MD_CTX_init(&ctx);
- if (!EVP_DigestSignInit(&ctx, NULL, type, NULL, pkey))
- {
+ if (!EVP_DigestSignInit(&ctx, NULL, type, NULL, pkey)) {
EVP_MD_CTX_cleanup(&ctx);
return 0;
}
type = EVP_MD_CTX_md(ctx);
pkey = EVP_PKEY_CTX_get0_pkey(ctx->pctx);
- if (!type || !pkey)
- {
+ if (!type || !pkey) {
ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ASN1_R_CONTEXT_NOT_INITIALISED);
return 0;
}
- if (pkey->ameth->item_sign)
- {
+ if (pkey->ameth->item_sign) {
rv = pkey->ameth->item_sign(ctx, it, asn, algor1, algor2,
signature);
if (rv == 1)
else
rv = 2;
- if (rv == 2)
- {
- if (type->flags & EVP_MD_FLAG_PKEY_METHOD_SIGNATURE)
- {
+ if (rv == 2) {
+ if (type->flags & EVP_MD_FLAG_PKEY_METHOD_SIGNATURE) {
if (!pkey->ameth ||
!OBJ_find_sigid_by_algs(&signid,
EVP_MD_nid(type),
- pkey->ameth->pkey_id))
- {
+ pkey->ameth->pkey_id)) {
ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX,
ASN1_R_DIGEST_AND_KEY_TYPE_NOT_SUPPORTED);
return 0;
inl=ASN1_item_i2d(asn,&buf_in, it);
outll=outl=EVP_PKEY_size(pkey);
buf_out=malloc((unsigned int)outl);
- if ((buf_in == NULL) || (buf_out == NULL))
- {
+ if ((buf_in == NULL) || (buf_out == NULL)) {
outl=0;
ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX,ERR_R_MALLOC_FAILURE);
goto err;
}
if (!EVP_DigestSignUpdate(ctx, buf_in, inl)
- || !EVP_DigestSignFinal(ctx, buf_out, &outl))
- {
+ || !EVP_DigestSignFinal(ctx, buf_out, &outl)) {
outl=0;
ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX,ERR_R_EVP_LIB);
goto err;
signature->flags|=ASN1_STRING_FLAG_BITS_LEFT;
err:
EVP_MD_CTX_cleanup(ctx);
- if (buf_in != NULL)
- { OPENSSL_cleanse((char *)buf_in,(unsigned int)inl); free(buf_in); }
- if (buf_out != NULL)
- { OPENSSL_cleanse((char *)buf_out,outll); free(buf_out); }
+ if (buf_in != NULL) {
+ OPENSSL_cleanse((char *)buf_in,(unsigned int)inl); free(buf_in);
+ }
+ if (buf_out != NULL) {
+ OPENSSL_cleanse((char *)buf_out,outll); free(buf_out);
+ }
return(outl);
}
if(indent < 0) indent = 0;
outlen = indent;
if(!do_indent(io_ch, arg, indent)) return -1;
- switch (flags & XN_FLAG_SEP_MASK)
- {
+ switch (flags & XN_FLAG_SEP_MASK) {
case XN_FLAG_SEP_MULTILINE:
sep_dn = "\n";
sep_dn_len = 1;
#ifndef OPENSSL_NO_FP_API
int X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent, unsigned long flags)
{
- if(flags == XN_FLAG_COMPAT)
- {
+ if(flags == XN_FLAG_COMPAT) {
BIO *btmp;
int ret;
btmp = BIO_new_fp(fp, BIO_NOCLOSE);
int i, last_nid = -1;
for (tmp = tbl_standard, i = 0;
- i < sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE); i++, tmp++)
- {
- if (tmp->nid < last_nid)
- {
- last_nid = 0;
- break;
- }
- last_nid = tmp->nid;
+ i < sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE); i++, tmp++) {
+ if (tmp->nid < last_nid) {
+ last_nid = 0;
+ break;
}
+ last_nid = tmp->nid;
+ }
- if (last_nid != 0)
- {
+ if (last_nid != 0) {
printf("Table order OK\n");
exit(0);
- }
+ }
for (tmp = tbl_standard, i = 0;
- i < sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE); i++, tmp++)
- printf("Index %d, NID %d, Name=%s\n", i, tmp->nid,
- OBJ_nid2ln(tmp->nid));
+ i < sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE); i++, tmp++) {
+ printf("Index %d, NID %d, Name=%s\n", i, tmp->nid,
+ OBJ_nid2ln(tmp->nid));
+ }
}
struct tm data;
ts=OPENSSL_gmtime(&t,&data);
- if (ts == NULL)
- {
+ if (ts == NULL) {
ASN1err(ASN1_F_ASN1_TIME_ADJ, ASN1_R_ERROR_GETTING_TIME);
return NULL;
}
- if (offset_day || offset_sec)
- {
+ if (offset_day || offset_sec) {
if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec))
return NULL;
}
if (!ASN1_TIME_check(t)) return NULL;
- if (!out || !*out)
- {
+ if (!out || !*out) {
if (!(ret = ASN1_GENERALIZEDTIME_new ()))
return NULL;
if (out) *out = ret;
else ret = *out;
/* If already GeneralizedTime just copy across */
- if (t->type == V_ASN1_GENERALIZEDTIME)
- {
+ if (t->type == V_ASN1_GENERALIZEDTIME) {
if(!ASN1_STRING_set(ret, t->data, t->length))
return NULL;
return ret;
t.type = V_ASN1_UTCTIME;
- if (!ASN1_TIME_check(&t))
- {
+ if (!ASN1_TIME_check(&t)) {
t.type = V_ASN1_GENERALIZEDTIME;
if (!ASN1_TIME_check(&t))
return 0;
void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value)
{
- if (a->value.ptr != NULL)
- {
+ if (a->value.ptr != NULL) {
ASN1_TYPE **tmp_a = &a;
ASN1_primitive_free((ASN1_VALUE **)tmp_a, NULL);
}
int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value)
{
- if (!value || (type == V_ASN1_BOOLEAN))
- {
+ if (!value || (type == V_ASN1_BOOLEAN)) {
void *p = (void *)value;
ASN1_TYPE_set(a, type, p);
- }
- else if (type == V_ASN1_OBJECT)
- {
+ } else if (type == V_ASN1_OBJECT) {
ASN1_OBJECT *odup;
odup = OBJ_dup(value);
if (!odup)
return 0;
ASN1_TYPE_set(a, type, odup);
- }
- else
- {
+ } else {
ASN1_STRING *sdup;
sdup = ASN1_STRING_dup(value);
if (!sdup)
if (!a || !b || a->type != b->type) return -1;
- switch (a->type)
- {
+ switch (a->type) {
case V_ASN1_OBJECT:
result = OBJ_cmp(a->value.object, b->value.object);
break;
ret=(ASN1_UTCTIME *)d2i_ASN1_bytes((ASN1_STRING **)a,pp,length,
V_ASN1_UTCTIME,V_ASN1_UNIVERSAL);
- if (ret == NULL)
- {
+ if (ret == NULL) {
ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ERR_R_NESTED_ASN1_ERROR);
return(NULL);
}
- if (!ASN1_UTCTIME_check(ret))
- {
+ if (!ASN1_UTCTIME_check(ret)) {
ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ASN1_R_INVALID_TIME_FORMAT);
goto err;
}
o=0;
if (l < 11) goto err;
- for (i=0; i<6; i++)
- {
+ for (i=0; i<6; i++) {
if ((i == 5) && ((a[o] == 'Z') ||
- (a[o] == '+') || (a[o] == '-')))
- { i++; break; }
+ (a[o] == '+') || (a[o] == '-'))) {
+ i++;
+ break;
+ }
if ((a[o] < '0') || (a[o] > '9')) goto err;
n= a[o]-'0';
if (++o > l) goto err;
}
if (a[o] == 'Z')
o++;
- else if ((a[o] == '+') || (a[o] == '-'))
- {
+ else if ((a[o] == '+') || (a[o] == '-')) {
o++;
if (o+4 > l) goto err;
- for (i=6; i<8; i++)
- {
+ for (i=6; i<8; i++) {
if ((a[o] < '0') || (a[o] > '9')) goto err;
n= a[o]-'0';
o++;
t.type=V_ASN1_UTCTIME;
t.length=strlen(str);
t.data=(unsigned char *)str;
- if (ASN1_UTCTIME_check(&t))
- {
- if (s != NULL)
- {
+ if (ASN1_UTCTIME_check(&t)) {
+ if (s != NULL) {
if (!ASN1_STRING_set((ASN1_STRING *)s,
(unsigned char *)str,t.length))
return 0;
s->type = V_ASN1_UTCTIME;
}
return(1);
- }
- else
+ } else
return(0);
}
if (ts == NULL)
return(NULL);
- if (offset_day || offset_sec)
- {
+ if (offset_day || offset_sec) {
if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec))
return NULL;
}
return NULL;
p=(char *)s->data;
- if ((p == NULL) || ((size_t)s->length < len))
- {
+ if ((p == NULL) || ((size_t)s->length < len)) {
p=malloc(len);
- if (p == NULL)
- {
+ if (p == NULL) {
ASN1err(ASN1_F_ASN1_UTCTIME_ADJ,ERR_R_MALLOC_FAILURE);
return(NULL);
}
if (s->data[12] == 'Z')
offset=0;
- else
- {
+ else {
offset = g2(s->data+13)*60+g2(s->data+15);
if (s->data[12] == '-')
offset = -offset;
tm.tm_sec=g2(s->data+10);
if(s->data[12] == 'Z')
offset=0;
- else
- {
+ else {
offset=g2(s->data+13)*60+g2(s->data+15);
if(s->data[12] == '-')
offset= -offset;
int mdnid, pknid;
- if (!pkey)
- {
+ if (!pkey) {
ASN1err(ASN1_F_ASN1_ITEM_VERIFY, ERR_R_PASSED_NULL_PARAMETER);
return -1;
}
EVP_MD_CTX_init(&ctx);
/* Convert signature OID into digest and public key OIDs */
- if (!OBJ_find_sigid_algs(OBJ_obj2nid(a->algorithm), &mdnid, &pknid))
- {
+ if (!OBJ_find_sigid_algs(OBJ_obj2nid(a->algorithm), &mdnid, &pknid)) {
ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM);
goto err;
}
- if (mdnid == NID_undef)
- {
- if (!pkey->ameth || !pkey->ameth->item_verify)
- {
+ if (mdnid == NID_undef) {
+ if (!pkey->ameth || !pkey->ameth->item_verify) {
ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM);
goto err;
}
if (ret != 2)
goto err;
ret = -1;
- }
- else
- {
+ } else {
const EVP_MD *type;
type=EVP_get_digestbynid(mdnid);
- if (type == NULL)
- {
+ if (type == NULL) {
ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM);
goto err;
}
/* Check public key OID matches public key type */
- if (EVP_PKEY_type(pknid) != pkey->ameth->pkey_id)
- {
+ if (EVP_PKEY_type(pknid) != pkey->ameth->pkey_id) {
ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ASN1_R_WRONG_PUBLIC_KEY_TYPE);
goto err;
}
- if (!EVP_DigestVerifyInit(&ctx, NULL, type, NULL, pkey))
- {
+ if (!EVP_DigestVerifyInit(&ctx, NULL, type, NULL, pkey)) {
ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_EVP_LIB);
ret=0;
goto err;
inl = ASN1_item_i2d(asn, &buf_in, it);
- if (buf_in == NULL)
- {
+ if (buf_in == NULL) {
ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_MALLOC_FAILURE);
goto err;
}
- if (!EVP_DigestVerifyUpdate(&ctx,buf_in,inl))
- {
+ if (!EVP_DigestVerifyUpdate(&ctx,buf_in,inl)) {
ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_EVP_LIB);
ret=0;
goto err;
free(buf_in);
if (EVP_DigestVerifyFinal(&ctx,signature->data,
- (size_t)signature->length) <= 0)
- {
+ (size_t)signature->length) <= 0) {
ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_EVP_LIB);
ret=0;
goto err;
EVP_PKEY_ASN1_METHOD tmp;
const EVP_PKEY_ASN1_METHOD *t = &tmp, **ret;
tmp.pkey_id = type;
- if (app_methods)
- {
+ if (app_methods) {
int idx;
idx = sk_EVP_PKEY_ASN1_METHOD_find(app_methods, &tmp);
if (idx >= 0)
{
const EVP_PKEY_ASN1_METHOD *t;
- for (;;)
- {
+ for (;;) {
t = pkey_asn1_find(type);
if (!t || !(t->pkey_flags & ASN1_PKEY_ALIAS))
break;
type = t->pkey_base_id;
}
- if (pe)
- {
+ if (pe) {
#ifndef OPENSSL_NO_ENGINE
ENGINE *e;
/* type will contain the final unaliased type */
e = ENGINE_get_pkey_asn1_meth_engine(type);
- if (e)
- {
+ if (e) {
*pe = e;
return ENGINE_get_pkey_asn1_meth(e, type);
}
const EVP_PKEY_ASN1_METHOD *ameth;
if (len == -1)
len = strlen(str);
- if (pe)
- {
+ if (pe) {
#ifndef OPENSSL_NO_ENGINE
ENGINE *e;
ameth = ENGINE_pkey_asn1_find_str(&e, str, len);
- if (ameth)
- {
+ if (ameth) {
/* Convert structural into
* functional reference
*/
#endif
*pe = NULL;
}
- for (i = 0; i < EVP_PKEY_asn1_get_count(); i++)
- {
+ for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) {
ameth = EVP_PKEY_asn1_get0(i);
if (ameth->pkey_flags & ASN1_PKEY_ALIAS)
continue;
int EVP_PKEY_asn1_add0(const EVP_PKEY_ASN1_METHOD *ameth)
{
- if (app_methods == NULL)
- {
+ if (app_methods == NULL) {
app_methods = sk_EVP_PKEY_ASN1_METHOD_new(ameth_cmp);
if (!app_methods)
return 0;
ameth->pkey_base_id = id;
ameth->pkey_flags = flags | ASN1_PKEY_DYNAMIC;
- if (info)
- {
+ if (info) {
ameth->info = BUF_strdup(info);
if (!ameth->info)
goto err;
else
ameth->info = NULL;
- if (pem_str)
- {
+ if (pem_str) {
ameth->pem_str = BUF_strdup(pem_str);
if (!ameth->pem_str)
goto err;
void EVP_PKEY_asn1_free(EVP_PKEY_ASN1_METHOD *ameth)
{
- if (ameth && (ameth->pkey_flags & ASN1_PKEY_DYNAMIC))
- {
+ if (ameth && (ameth->pkey_flags & ASN1_PKEY_DYNAMIC)) {
if (ameth->pem_str)
free(ameth->pem_str);
if (ameth->info)
{
#ifndef OPENSSL_NO_ERR
- if (ERR_func_error_string(ASN1_str_functs[0].error) == NULL)
- {
+ if (ERR_func_error_string(ASN1_str_functs[0].error) == NULL) {
ERR_load_strings(0,ASN1_str_functs);
ERR_load_strings(0,ASN1_str_reasons);
}
if (CONF_parse_list(str, ',', 1, asn1_cb, &asn1_tags) != 0)
return NULL;
- if ((asn1_tags.utype == V_ASN1_SEQUENCE) || (asn1_tags.utype == V_ASN1_SET))
- {
- if (!cnf)
- {
+ if ((asn1_tags.utype == V_ASN1_SEQUENCE) || (asn1_tags.utype == V_ASN1_SET)) {
+ if (!cnf) {
ASN1err(ASN1_F_ASN1_GENERATE_V3, ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG);
return NULL;
}
cpy_start = orig_der;
/* Do we need IMPLICIT tagging? */
- if (asn1_tags.imp_tag != -1)
- {
+ if (asn1_tags.imp_tag != -1) {
/* If IMPLICIT we will replace the underlying tag */
/* Skip existing tag+len */
r = ASN1_get_object(&cpy_start, &hdr_len, &hdr_tag, &hdr_class, cpy_len);
* original length and constructed flag should be
* consistent.
*/
- if (r & 0x1)
- {
+ if (r & 0x1) {
/* Indefinite length constructed */
hdr_constructed = 2;
hdr_len = 0;
/* Work out length in any EXPLICIT, starting from end */
- for(i = 0, etmp = asn1_tags.exp_list + asn1_tags.exp_count - 1; i < asn1_tags.exp_count; i++, etmp--)
- {
+ for(i = 0, etmp = asn1_tags.exp_list + asn1_tags.exp_count - 1; i < asn1_tags.exp_count; i++, etmp--) {
/* Content length: number of content octets + any padding */
len += etmp->exp_pad;
etmp->exp_len = len;
/* Output explicit tags first */
- for (i = 0, etmp = asn1_tags.exp_list; i < asn1_tags.exp_count; i++, etmp++)
- {
+ for (i = 0, etmp = asn1_tags.exp_list; i < asn1_tags.exp_count; i++, etmp++) {
ASN1_put_object(&p, etmp->exp_constructed, etmp->exp_len,
etmp->exp_tag, etmp->exp_class);
if (etmp->exp_pad)
/* If IMPLICIT, output tag */
- if (asn1_tags.imp_tag != -1)
- {
+ if (asn1_tags.imp_tag != -1) {
if (asn1_tags.imp_class == V_ASN1_UNIVERSAL
&& (asn1_tags.imp_tag == V_ASN1_SEQUENCE
|| asn1_tags.imp_tag == V_ASN1_SET) )
int tmp_tag, tmp_class;
- for(i = 0, p = elem; i < len; p++, i++)
- {
+ for(i = 0, p = elem; i < len; p++, i++) {
/* Look for the ':' in name value pairs */
- if (*p == ':')
- {
+ if (*p == ':') {
vstart = p + 1;
vlen = len - (vstart - elem);
len = p - elem;
utype = asn1_str2tag(elem, len);
- if (utype == -1)
- {
+ if (utype == -1) {
ASN1err(ASN1_F_ASN1_CB, ASN1_R_UNKNOWN_TAG);
ERR_add_error_data(2, "tag=", elem);
return -1;
}
/* If this is not a modifier mark end of string and exit */
- if (!(utype & ASN1_GEN_FLAG))
- {
+ if (!(utype & ASN1_GEN_FLAG)) {
arg->utype = utype;
arg->str = vstart;
/* If no value and not end of string, error */
- if (!vstart && elem[len])
- {
+ if (!vstart && elem[len]) {
ASN1err(ASN1_F_ASN1_CB, ASN1_R_MISSING_VALUE);
return -1;
}
return 0;
}
- switch(utype)
- {
+ switch(utype) {
- case ASN1_GEN_FLAG_IMP:
+ case ASN1_GEN_FLAG_IMP:
/* Check for illegal multiple IMPLICIT tagging */
- if (arg->imp_tag != -1)
- {
+ if (arg->imp_tag != -1) {
ASN1err(ASN1_F_ASN1_CB, ASN1_R_ILLEGAL_NESTED_TAGGING);
return -1;
}
return -1;
break;
- case ASN1_GEN_FLAG_EXP:
+ case ASN1_GEN_FLAG_EXP:
if (!parse_tagging(vstart, vlen, &tmp_tag, &tmp_class))
return -1;
return -1;
break;
- case ASN1_GEN_FLAG_SEQWRAP:
+ case ASN1_GEN_FLAG_SEQWRAP:
if (!append_exp(arg, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL, 1, 0, 1))
return -1;
break;
- case ASN1_GEN_FLAG_SETWRAP:
+ case ASN1_GEN_FLAG_SETWRAP:
if (!append_exp(arg, V_ASN1_SET, V_ASN1_UNIVERSAL, 1, 0, 1))
return -1;
break;
- case ASN1_GEN_FLAG_BITWRAP:
+ case ASN1_GEN_FLAG_BITWRAP:
if (!append_exp(arg, V_ASN1_BIT_STRING, V_ASN1_UNIVERSAL, 0, 1, 1))
return -1;
break;
- case ASN1_GEN_FLAG_OCTWRAP:
+ case ASN1_GEN_FLAG_OCTWRAP:
if (!append_exp(arg, V_ASN1_OCTET_STRING, V_ASN1_UNIVERSAL, 0, 0, 1))
return -1;
break;
- case ASN1_GEN_FLAG_FORMAT:
+ case ASN1_GEN_FLAG_FORMAT:
if (!strncmp(vstart, "ASCII", 5))
arg->format = ASN1_GEN_FORMAT_ASCII;
else if (!strncmp(vstart, "UTF8", 4))
arg->format = ASN1_GEN_FORMAT_HEX;
else if (!strncmp(vstart, "BITLIST", 7))
arg->format = ASN1_GEN_FORMAT_BITLIST;
- else
- {
+ else {
ASN1err(ASN1_F_ASN1_CB, ASN1_R_UNKOWN_FORMAT);
return -1;
}
/* Check we haven't gone past max length: should be impossible */
if (eptr && *eptr && (eptr > vstart + vlen))
return 0;
- if (tag_num < 0)
- {
+ if (tag_num < 0) {
ASN1err(ASN1_F_PARSE_TAGGING, ASN1_R_INVALID_NUMBER);
return 0;
}
vlen -= eptr - vstart;
else
vlen = 0;
- if (vlen)
- {
- switch (*eptr)
- {
+ if (vlen) {
+ switch (*eptr) {
- case 'U':
+ case 'U':
*pclass = V_ASN1_UNIVERSAL;
break;
- case 'A':
+ case 'A':
*pclass = V_ASN1_APPLICATION;
break;
- case 'P':
+ case 'P':
*pclass = V_ASN1_PRIVATE;
break;
- case 'C':
+ case 'C':
*pclass = V_ASN1_CONTEXT_SPECIFIC;
break;
sk = sk_ASN1_TYPE_new_null();
if (!sk)
goto bad;
- if (section)
- {
+ if (section) {
if (!cnf)
goto bad;
sect = X509V3_get_section(cnf, (char *)section);
if (!sect)
goto bad;
- for (i = 0; i < sk_CONF_VALUE_num(sect); i++)
- {
+ for (i = 0; i < sk_CONF_VALUE_num(sect); i++) {
ASN1_TYPE *typ = ASN1_generate_v3(sk_CONF_VALUE_value(sect, i)->value, cnf);
if (!typ)
goto bad;
{
tag_exp_type *exp_tmp;
/* Can only have IMPLICIT if permitted */
- if ((arg->imp_tag != -1) && !imp_ok)
- {
+ if ((arg->imp_tag != -1) && !imp_ok) {
ASN1err(ASN1_F_APPEND_EXP, ASN1_R_ILLEGAL_IMPLICIT_TAG);
return 0;
}
- if (arg->exp_count == ASN1_FLAG_EXP_MAX)
- {
+ if (arg->exp_count == ASN1_FLAG_EXP_MAX) {
ASN1err(ASN1_F_APPEND_EXP, ASN1_R_DEPTH_EXCEEDED);
return 0;
}
/* If IMPLICIT set tag to implicit value then
* reset implicit tag since it has been used.
*/
- if (arg->imp_tag != -1)
- {
+ if (arg->imp_tag != -1) {
exp_tmp->exp_tag = arg->imp_tag;
exp_tmp->exp_class = arg->imp_class;
arg->imp_tag = -1;
arg->imp_class = -1;
- }
- else
- {
+ } else {
exp_tmp->exp_tag = exp_tag;
exp_tmp->exp_class = exp_class;
}
len = strlen(tagstr);
tntmp = tnst;
- for (i = 0; i < sizeof(tnst) / sizeof(struct tag_name_st); i++, tntmp++)
- {
+ for (i = 0; i < sizeof(tnst) / sizeof(struct tag_name_st); i++, tntmp++) {
if ((len == tntmp->len) && !strncmp(tntmp->strnam, tagstr, len))
return tntmp->tag;
}
int no_unused = 1;
- if (!(atmp = ASN1_TYPE_new()))
- {
+ if (!(atmp = ASN1_TYPE_new())) {
ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE);
return NULL;
}
if (!str)
str = "";
- switch(utype)
- {
+ switch(utype) {
- case V_ASN1_NULL:
- if (str && *str)
- {
+ case V_ASN1_NULL:
+ if (str && *str) {
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_NULL_VALUE);
goto bad_form;
}
break;
- case V_ASN1_BOOLEAN:
- if (format != ASN1_GEN_FORMAT_ASCII)
- {
+ case V_ASN1_BOOLEAN:
+ if (format != ASN1_GEN_FORMAT_ASCII) {
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_NOT_ASCII_FORMAT);
goto bad_form;
}
vtmp.name = NULL;
vtmp.section = NULL;
vtmp.value = (char *)str;
- if (!X509V3_get_value_bool(&vtmp, &atmp->value.boolean))
- {
+ if (!X509V3_get_value_bool(&vtmp, &atmp->value.boolean)) {
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_BOOLEAN);
goto bad_str;
}
break;
- case V_ASN1_INTEGER:
- case V_ASN1_ENUMERATED:
- if (format != ASN1_GEN_FORMAT_ASCII)
- {
+ case V_ASN1_INTEGER:
+ case V_ASN1_ENUMERATED:
+ if (format != ASN1_GEN_FORMAT_ASCII) {
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_INTEGER_NOT_ASCII_FORMAT);
goto bad_form;
}
- if (!(atmp->value.integer = s2i_ASN1_INTEGER(NULL, (char *)str)))
- {
+ if (!(atmp->value.integer = s2i_ASN1_INTEGER(NULL, (char *)str))) {
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_INTEGER);
goto bad_str;
}
break;
- case V_ASN1_OBJECT:
- if (format != ASN1_GEN_FORMAT_ASCII)
- {
+ case V_ASN1_OBJECT:
+ if (format != ASN1_GEN_FORMAT_ASCII) {
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_OBJECT_NOT_ASCII_FORMAT);
goto bad_form;
}
- if (!(atmp->value.object = OBJ_txt2obj(str, 0)))
- {
+ if (!(atmp->value.object = OBJ_txt2obj(str, 0))) {
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_OBJECT);
goto bad_str;
}
break;
- case V_ASN1_UTCTIME:
- case V_ASN1_GENERALIZEDTIME:
- if (format != ASN1_GEN_FORMAT_ASCII)
- {
+ case V_ASN1_UTCTIME:
+ case V_ASN1_GENERALIZEDTIME:
+ if (format != ASN1_GEN_FORMAT_ASCII) {
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_TIME_NOT_ASCII_FORMAT);
goto bad_form;
}
- if (!(atmp->value.asn1_string = ASN1_STRING_new()))
- {
+ if (!(atmp->value.asn1_string = ASN1_STRING_new())) {
ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE);
goto bad_str;
}
- if (!ASN1_STRING_set(atmp->value.asn1_string, str, -1))
- {
+ if (!ASN1_STRING_set(atmp->value.asn1_string, str, -1)) {
ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE);
goto bad_str;
}
atmp->value.asn1_string->type = utype;
- if (!ASN1_TIME_check(atmp->value.asn1_string))
- {
+ if (!ASN1_TIME_check(atmp->value.asn1_string)) {
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_TIME_VALUE);
goto bad_str;
}
break;
- case V_ASN1_BMPSTRING:
- case V_ASN1_PRINTABLESTRING:
- case V_ASN1_IA5STRING:
- case V_ASN1_T61STRING:
- case V_ASN1_UTF8STRING:
- case V_ASN1_VISIBLESTRING:
- case V_ASN1_UNIVERSALSTRING:
- case V_ASN1_GENERALSTRING:
- case V_ASN1_NUMERICSTRING:
+ case V_ASN1_BMPSTRING:
+ case V_ASN1_PRINTABLESTRING:
+ case V_ASN1_IA5STRING:
+ case V_ASN1_T61STRING:
+ case V_ASN1_UTF8STRING:
+ case V_ASN1_VISIBLESTRING:
+ case V_ASN1_UNIVERSALSTRING:
+ case V_ASN1_GENERALSTRING:
+ case V_ASN1_NUMERICSTRING:
if (format == ASN1_GEN_FORMAT_ASCII)
format = MBSTRING_ASC;
else if (format == ASN1_GEN_FORMAT_UTF8)
format = MBSTRING_UTF8;
- else
- {
+ else {
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_FORMAT);
goto bad_form;
}
if (ASN1_mbstring_copy(&atmp->value.asn1_string, (unsigned char *)str,
- -1, format, ASN1_tag2bit(utype)) <= 0)
- {
+ -1, format, ASN1_tag2bit(utype)) <= 0) {
ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE);
goto bad_str;
}
break;
- case V_ASN1_BIT_STRING:
+ case V_ASN1_BIT_STRING:
- case V_ASN1_OCTET_STRING:
+ case V_ASN1_OCTET_STRING:
- if (!(atmp->value.asn1_string = ASN1_STRING_new()))
- {
+ if (!(atmp->value.asn1_string = ASN1_STRING_new())) {
ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE);
goto bad_form;
}
- if (format == ASN1_GEN_FORMAT_HEX)
- {
+ if (format == ASN1_GEN_FORMAT_HEX) {
- if (!(rdata = string_to_hex((char *)str, &rdlen)))
- {
+ if (!(rdata = string_to_hex((char *)str, &rdlen))) {
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_HEX);
goto bad_str;
}
}
else if (format == ASN1_GEN_FORMAT_ASCII)
ASN1_STRING_set(atmp->value.asn1_string, str, -1);
- else if ((format == ASN1_GEN_FORMAT_BITLIST) && (utype == V_ASN1_BIT_STRING))
- {
- if (!CONF_parse_list(str, ',', 1, bitstr_cb, atmp->value.bit_string))
- {
+ else if ((format == ASN1_GEN_FORMAT_BITLIST) && (utype == V_ASN1_BIT_STRING)) {
+ if (!CONF_parse_list(str, ',', 1, bitstr_cb, atmp->value.bit_string)) {
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_LIST_ERROR);
goto bad_str;
}
no_unused = 0;
- }
- else
- {
+ } else {
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_BITSTRING_FORMAT);
goto bad_form;
}
- if ((utype == V_ASN1_BIT_STRING) && no_unused)
- {
+ if ((utype == V_ASN1_BIT_STRING) && no_unused) {
atmp->value.asn1_string->flags
&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07);
atmp->value.asn1_string->flags
break;
- default:
+ default:
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_UNSUPPORTED_TYPE);
goto bad_str;
break;
return atmp;
- bad_str:
+bad_str:
ERR_add_error_data(2, "string=", str);
- bad_form:
+bad_form:
ASN1_TYPE_free(atmp);
return NULL;
bitnum = strtoul(elem, &eptr, 10);
if (eptr && *eptr && (eptr != elem + len))
return 0;
- if (bitnum < 0)
- {
+ if (bitnum < 0) {
ASN1err(ASN1_F_BITSTR_CB, ASN1_R_INVALID_NUMBER);
return 0;
}
- if (!ASN1_BIT_STRING_set_bit(bitstr, bitnum, 1))
- {
+ if (!ASN1_BIT_STRING_set_bit(bitstr, bitnum, 1)) {
ASN1err(ASN1_F_BITSTR_CB, ERR_R_MALLOC_FAILURE);
return 0;
}
* things up */
if (len <= 0)
return(1);
- else if ((len >= 2) && ((*p)[0] == 0) && ((*p)[1] == 0))
- {
+ else if ((len >= 2) && ((*p)[0] == 0) && ((*p)[1] == 0)) {
(*p)+=2;
return(1);
}
ret=(*p&V_ASN1_CONSTRUCTED);
xclass=(*p&V_ASN1_PRIVATE);
i= *p&V_ASN1_PRIMITIVE_TAG;
- if (i == V_ASN1_PRIMITIVE_TAG)
- { /* high-tag */
+ if (i == V_ASN1_PRIMITIVE_TAG) { /* high-tag */
p++;
if (--max == 0) goto err;
l=0;
- while (*p&0x80)
- {
+ while (*p&0x80) {
l<<=7L;
l|= *(p++)&0x7f;
if (--max == 0) goto err;
l|= *(p++)&0x7f;
tag=(int)l;
if (--max == 0) goto err;
- }
- else
- {
+ } else {
tag=i;
p++;
if (--max == 0) goto err;
(int)(omax+ *pp));
#endif
- if (*plength > (omax - (p - *pp)))
- {
+ if (*plength > (omax - (p - *pp))) {
ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG);
/* Set this so that even if things are not long enough
* the values are set correctly */
unsigned int i;
if (max-- < 1) return(0);
- if (*p == 0x80)
- {
+ if (*p == 0x80) {
*inf=1;
ret=0;
p++;
- }
- else
- {
+ } else {
*inf=0;
i= *p&0x7f;
- if (*(p++) & 0x80)
- {
+ if (*(p++) & 0x80) {
if (i > sizeof(long))
return 0;
if (max-- == 0) return(0);
- while (i-- > 0)
- {
+ while (i-- > 0) {
ret<<=8L;
ret|= *(p++);
if (max-- == 0) return(0);
i|=(xclass&V_ASN1_PRIVATE);
if (tag < 31)
*(p++)=i|(tag&V_ASN1_PRIMITIVE_TAG);
- else
- {
+ else {
*(p++)=i|V_ASN1_PRIMITIVE_TAG;
for(i = 0, ttag = tag; ttag > 0; i++) ttag >>=7;
ttag = i;
- while(i-- > 0)
- {
+ while(i-- > 0) {
p[i] = tag & 0x7f;
if(i != (ttag - 1)) p[i] |= 0x80;
tag >>= 7;
int i,l;
if (length <= 127)
*(p++)=(unsigned char)length;
- else
- {
+ else {
l=length;
for (i=0; l > 0; i++)
l>>=8;
*(p++)=i|0x80;
l=i;
- while (i-- > 0)
- {
+ while (i-- > 0) {
p[i]=length&0xff;
length>>=8;
}
ret=length;
ret++;
- if (tag >= 31)
- {
- while (tag > 0)
- {
+ if (tag >= 31) {
+ while (tag > 0) {
tag>>=7;
ret++;
}
if (constructed == 2)
return ret + 3;
ret++;
- if (length > 127)
- {
- while (length > 0)
- {
+ if (length > 127) {
+ while (length > 0) {
length>>=8;
ret++;
}
static int _asn1_Finish(ASN1_const_CTX *c)
{
- if ((c->inf == (1|V_ASN1_CONSTRUCTED)) && (!c->eos))
- {
- if (!ASN1_const_check_infinite_end(&c->p,c->slen))
- {
+ if ((c->inf == (1|V_ASN1_CONSTRUCTED)) && (!c->eos)) {
+ if (!ASN1_const_check_infinite_end(&c->p,c->slen)) {
c->error=ERR_R_MISSING_ASN1_EOS;
return(0);
}
}
if ( ((c->slen != 0) && !(c->inf & 1)) ||
- ((c->slen < 0) && (c->inf & 1)))
- {
+ ((c->slen < 0) && (c->inf & 1))) {
c->error=ERR_R_ASN1_LENGTH_MISMATCH;
return(0);
}
q=c->p;
c->inf=ASN1_get_object(&(c->p),&(c->slen),&(c->tag),&(c->xclass),
*length);
- if (c->inf & 0x80)
- {
+ if (c->inf & 0x80) {
c->error=ERR_R_BAD_GET_ASN1_OBJECT_CALL;
return(0);
}
- if (c->tag != V_ASN1_SEQUENCE)
- {
+ if (c->tag != V_ASN1_SEQUENCE) {
c->error=ERR_R_EXPECTING_AN_ASN1_SEQUENCE;
return(0);
}
(*length)-=(c->p-q);
- if (c->max && (*length < 0))
- {
+ if (c->max && (*length < 0)) {
c->error=ERR_R_ASN1_LENGTH_MISMATCH;
return(0);
}
ret=ASN1_STRING_new();
if (!ret)
return NULL;
- if (!ASN1_STRING_copy(ret,str))
- {
+ if (!ASN1_STRING_copy(ret,str)) {
ASN1_STRING_free(ret);
return NULL;
}
unsigned char *c;
const char *data=_data;
- if (len < 0)
- {
+ if (len < 0) {
if (data == NULL)
return(0);
else
len=strlen(data);
}
- if ((str->length < len) || (str->data == NULL))
- {
+ if ((str->length < len) || (str->data == NULL)) {
c=str->data;
if (c == NULL)
str->data=malloc(len+1);
else
str->data=realloc(c,len+1);
- if (str->data == NULL)
- {
+ if (str->data == NULL) {
ASN1err(ASN1_F_ASN1_STRING_SET,ERR_R_MALLOC_FAILURE);
str->data=c;
return(0);
}
}
str->length=len;
- if (data != NULL)
- {
+ if (data != NULL) {
memcpy(str->data,data,len);
/* an allowance for strings :-) */
str->data[len]='\0';
ASN1_STRING *ret;
ret=(ASN1_STRING *)malloc(sizeof(ASN1_STRING));
- if (ret == NULL)
- {
+ if (ret == NULL) {
ASN1err(ASN1_F_ASN1_STRING_TYPE_NEW,ERR_R_MALLOC_FAILURE);
return(NULL);
}
int i;
i=(a->length-b->length);
- if (i == 0)
- {
+ if (i == 0) {
i=memcmp(a->data,b->data,a->length);
if (i == 0)
return(a->type-b->type);
p= *pp;
tot=p+length;
op=p-1;
- while ((p < tot) && (op < p))
- {
+ while ((p < tot) && (op < p)) {
op=p;
j=ASN1_get_object(&p,&len,&tag,&xclass,length);
#ifdef LINT
j=j;
#endif
- if (j & 0x80)
- {
+ if (j & 0x80) {
if (BIO_write(bp,"Error in encoding\n",18) <= 0)
goto end;
ret=0;
if (BIO_printf(bp,"%5ld:",(long)offset+(long)(op- *pp))
<= 0) goto end;
- if (j != (V_ASN1_CONSTRUCTED | 1))
- {
+ if (j != (V_ASN1_CONSTRUCTED | 1)) {
if (BIO_printf(bp,"d=%-2d hl=%ld l=%4ld ",
depth,(long)hl,len) <= 0)
goto end;
- }
- else
- {
+ } else {
if (BIO_printf(bp,"d=%-2d hl=%ld l=inf ",
depth,(long)hl) <= 0)
goto end;
}
if (!asn1_print_info(bp,tag,xclass,j,(indent)?depth:0))
goto end;
- if (j & V_ASN1_CONSTRUCTED)
- {
+ if (j & V_ASN1_CONSTRUCTED) {
ep=p+len;
if (BIO_write(bp,"\n",1) <= 0) goto end;
- if (len > length)
- {
+ if (len > length) {
BIO_printf(bp,
"length is greater than %ld\n",length);
ret=0;
goto end;
}
- if ((j == 0x21) && (len == 0))
- {
- for (;;)
- {
+ if ((j == 0x21) && (len == 0)) {
+ for (;;) {
r=asn1_parse2(bp,&p,(long)(tot-p),
offset+(p - *pp),depth+1,
indent,dump);
}
}
else
- while (p < ep)
- {
+ while (p < ep) {
r=asn1_parse2(bp,&p,(long)len,
offset+(p - *pp),depth+1,
indent,dump);
if (r == 0) { ret=0; goto end; }
}
- }
- else if (xclass != 0)
- {
+ } else if (xclass != 0) {
p+=len;
if (BIO_write(bp,"\n",1) <= 0) goto end;
- }
- else
- {
+ } else {
nl=0;
if ( (tag == V_ASN1_PRINTABLESTRING) ||
(tag == V_ASN1_T61STRING) ||
(tag == V_ASN1_NUMERICSTRING) ||
(tag == V_ASN1_UTF8STRING) ||
(tag == V_ASN1_UTCTIME) ||
- (tag == V_ASN1_GENERALIZEDTIME))
- {
+ (tag == V_ASN1_GENERALIZEDTIME)) {
if (BIO_write(bp,":",1) <= 0) goto end;
if ((len > 0) &&
BIO_write(bp,(const char *)p,(int)len)
!= (int)len)
goto end;
- }
- else if (tag == V_ASN1_OBJECT)
- {
+ } else if (tag == V_ASN1_OBJECT) {
opp=op;
- if (d2i_ASN1_OBJECT(&o,&opp,len+hl) != NULL)
- {
+ if (d2i_ASN1_OBJECT(&o,&opp,len+hl) != NULL) {
if (BIO_write(bp,":",1) <= 0) goto end;
i2a_ASN1_OBJECT(bp,o);
- }
- else
- {
+ } else {
if (BIO_write(bp,":BAD OBJECT",11) <= 0)
goto end;
}
- }
- else if (tag == V_ASN1_BOOLEAN)
- {
+ } else if (tag == V_ASN1_BOOLEAN) {
int ii;
opp=op;
ii=d2i_ASN1_BOOLEAN(NULL,&opp,len+hl);
- if (ii < 0)
- {
+ if (ii < 0) {
if (BIO_write(bp,"Bad boolean\n",12) <= 0)
goto end;
}
BIO_printf(bp,":%d",ii);
- }
- else if (tag == V_ASN1_BMPSTRING)
- {
+ } else if (tag == V_ASN1_BMPSTRING) {
/* do the BMP thang */
- }
- else if (tag == V_ASN1_OCTET_STRING)
- {
+ } else if (tag == V_ASN1_OCTET_STRING) {
int i,printable=1;
opp=op;
os=d2i_ASN1_OCTET_STRING(NULL,&opp,len+hl);
- if (os != NULL && os->length > 0)
- {
+ if (os != NULL && os->length > 0) {
opp = os->data;
/* testing whether the octet string is
* printable */
- for (i=0; i<os->length; i++)
- {
+ for (i=0; i<os->length; i++) {
if (( (opp[i] < ' ') &&
(opp[i] != '\n') &&
(opp[i] != '\r') &&
(opp[i] != '\t')) ||
- (opp[i] > '~'))
- {
+ (opp[i] > '~')) {
printable=0;
break;
}
}
- if (printable)
+ if (printable) {
/* printable string */
- {
if (BIO_write(bp,":",1) <= 0)
goto end;
if (BIO_write(bp,(const char *)opp,
os->length) <= 0)
goto end;
- }
- else if (!dump)
+ } else if (!dump) {
/* not printable => print octet string
* as hex dump */
- {
if (BIO_write(bp,"[HEX DUMP]:",11) <= 0)
goto end;
- for (i=0; i<os->length; i++)
- {
+ for (i=0; i<os->length; i++) {
if (BIO_printf(bp,"%02X"
, opp[i]) <= 0)
goto end;
}
- }
- else
+ } else {
/* print the normal dump */
- {
- if (!nl)
- {
+ if (!nl) {
if (BIO_write(bp,"\n",1) <= 0)
goto end;
}
nl=1;
}
}
- if (os != NULL)
- {
+ if (os != NULL) {
M_ASN1_OCTET_STRING_free(os);
os=NULL;
}
- }
- else if (tag == V_ASN1_INTEGER)
- {
+ } else if (tag == V_ASN1_INTEGER) {
ASN1_INTEGER *bs;
int i;
opp=op;
bs=d2i_ASN1_INTEGER(NULL,&opp,len+hl);
- if (bs != NULL)
- {
+ if (bs != NULL) {
if (BIO_write(bp,":",1) <= 0) goto end;
if (bs->type == V_ASN1_NEG_INTEGER)
if (BIO_write(bp,"-",1) <= 0)
goto end;
- for (i=0; i<bs->length; i++)
- {
+ for (i=0; i<bs->length; i++) {
if (BIO_printf(bp,"%02X",
bs->data[i]) <= 0)
goto end;
}
- if (bs->length == 0)
- {
+ if (bs->length == 0) {
if (BIO_write(bp,"00",2) <= 0)
goto end;
}
- }
- else
- {
+ } else {
if (BIO_write(bp,"BAD INTEGER",11) <= 0)
goto end;
}
M_ASN1_INTEGER_free(bs);
- }
- else if (tag == V_ASN1_ENUMERATED)
- {
+ } else if (tag == V_ASN1_ENUMERATED) {
ASN1_ENUMERATED *bs;
int i;
opp=op;
bs=d2i_ASN1_ENUMERATED(NULL,&opp,len+hl);
- if (bs != NULL)
- {
+ if (bs != NULL) {
if (BIO_write(bp,":",1) <= 0) goto end;
if (bs->type == V_ASN1_NEG_ENUMERATED)
if (BIO_write(bp,"-",1) <= 0)
goto end;
- for (i=0; i<bs->length; i++)
- {
+ for (i=0; i<bs->length; i++) {
if (BIO_printf(bp,"%02X",
bs->data[i]) <= 0)
goto end;
}
- if (bs->length == 0)
- {
+ if (bs->length == 0) {
if (BIO_write(bp,"00",2) <= 0)
goto end;
}
- }
- else
- {
+ } else {
if (BIO_write(bp,"BAD ENUMERATED",14) <= 0)
goto end;
}
M_ASN1_ENUMERATED_free(bs);
- }
- else if (len > 0 && dump)
- {
- if (!nl)
- {
+ } else if (len > 0 && dump) {
+ if (!nl) {
if (BIO_write(bp,"\n",1) <= 0)
goto end;
}
nl=1;
}
- if (!nl)
- {
+ if (!nl) {
if (BIO_write(bp,"\n",1) <= 0) goto end;
}
p+=len;
- if ((tag == V_ASN1_EOC) && (xclass == 0))
- {
+ if ((tag == V_ASN1_EOC) && (xclass == 0)) {
ret=2; /* End of sequence */
goto end;
}
};
if((tag == V_ASN1_NEG_INTEGER) || (tag == V_ASN1_NEG_ENUMERATED))
- tag &= ~0x100;
+ tag &= ~0x100;
if(tag < 0 || tag > 30) return "(unknown)";
return tag2str[tag];
const ASN1_ITEM *it)
{
/* If streaming create stream BIO and copy all content through it */
- if (flags & SMIME_STREAM)
- {
+ if (flags & SMIME_STREAM) {
BIO *bio, *tbio;
bio = BIO_new_NDEF(out, val, it);
- if (!bio)
- {
+ if (!bio) {
ASN1err(ASN1_F_I2D_ASN1_BIO_STREAM,ERR_R_MALLOC_FAILURE);
return 0;
}
SMIME_crlf_copy(in, bio, flags);
(void)BIO_flush(bio);
/* Free up successive BIOs until we hit the old output BIO */
- do
- {
+ do {
tbio = BIO_pop(bio);
BIO_free(bio);
bio = tbio;
BIO *b64;
int r;
b64 = BIO_new(BIO_f_base64());
- if(!b64)
- {
+ if(!b64) {
ASN1err(ASN1_F_B64_WRITE_ASN1,ERR_R_MALLOC_FAILURE);
return 0;
}
int i, have_unknown = 0, write_comma, ret = 0, md_nid;
have_unknown = 0;
write_comma = 0;
- for (i = 0; i < sk_X509_ALGOR_num(mdalgs); i++)
- {
+ for (i = 0; i < sk_X509_ALGOR_num(mdalgs); i++) {
if (write_comma)
BIO_write(out, ",", 1);
write_comma = 1;
md_nid = OBJ_obj2nid(sk_X509_ALGOR_value(mdalgs, i)->algorithm);
md = EVP_get_digestbynid(md_nid);
- if (md && md->md_ctrl)
- {
+ if (md && md->md_ctrl) {
int rv;
char *micstr;
rv = md->md_ctrl(NULL, EVP_MD_CTRL_MICALG, 0, &micstr);
- if (rv > 0)
- {
+ if (rv > 0) {
BIO_puts(out, micstr);
free(micstr);
continue;
if (rv != -2)
goto err;
}
- switch(md_nid)
- {
+ switch(md_nid) {
case NID_sha1:
BIO_puts(out, "sha1");
break;
default:
if (have_unknown)
write_comma = 0;
- else
- {
+ else {
BIO_puts(out, "unknown");
have_unknown = 1;
}
if (ctype_nid == NID_pkcs7_enveloped)
msg_type = "enveloped-data";
- else if (ctype_nid == NID_pkcs7_signed)
- {
+ else if (ctype_nid == NID_pkcs7_signed) {
if (econt_nid == NID_id_smime_ct_receipt)
msg_type = "signed-receipt";
else if (sk_X509_ALGOR_num(mdalgs) >= 0)
msg_type = "signed-data";
else
msg_type = "certs-only";
- }
- else if (ctype_nid == NID_id_smime_ct_compressedData)
- {
+ } else if (ctype_nid == NID_id_smime_ct_compressedData) {
msg_type = "compressed-data";
cname = "smime.p7z";
}
/* If data is not deteched or resigning then the output BIO is
* already set up to finalise when it is written through.
*/
- if (!(flags & SMIME_DETACHED) || (flags & PKCS7_REUSE_DIGEST))
- {
+ if (!(flags & SMIME_DETACHED) || (flags & PKCS7_REUSE_DIGEST)) {
SMIME_crlf_copy(data, out, flags);
return 1;
}
- if (!aux || !aux->asn1_cb)
- {
+ if (!aux || !aux->asn1_cb) {
ASN1err(ASN1_F_ASN1_OUTPUT_DATA,
ASN1_R_STREAMING_NOT_SUPPORTED);
return 0;
/* Now remove any digests prepended to the BIO */
- while (sarg.ndef_bio != out)
- {
+ while (sarg.ndef_bio != out) {
tmpbio = BIO_pop(sarg.ndef_bio);
BIO_free(sarg.ndef_bio);
sarg.ndef_bio = tmpbio;
if (!bf)
return 0;
out = BIO_push(bf, out);
- if(flags & SMIME_BINARY)
- {
+ if(flags & SMIME_BINARY) {
while((len = BIO_read(in, linebuf, MAX_SMLEN)) > 0)
BIO_write(out, linebuf, len);
- }
- else
- {
+ } else {
if(flags & SMIME_TEXT)
BIO_printf(out, "Content-Type: text/plain\r\n\r\n");
- while ((len = BIO_gets(in, linebuf, MAX_SMLEN)) > 0)
- {
+ while ((len = BIO_gets(in, linebuf, MAX_SMLEN)) > 0) {
eol = strip_eol(linebuf, &len);
if (len)
BIO_write(out, linebuf, len);
char *p, c;
int is_eol = 0;
p = linebuf + len - 1;
- for (p = linebuf + len - 1; len > 0; len--, p--)
- {
+ for (p = linebuf + len - 1; len > 0; len--, p--) {
c = *p;
if (c == '\n')
is_eol = 1;
STACK_OF(CONF_VALUE) *sktmp;
CONF_VALUE *oval;
oid_section = CONF_imodule_get_value(md);
- if(!(sktmp = NCONF_get_section(cnf, oid_section)))
- {
+ if(!(sktmp = NCONF_get_section(cnf, oid_section))) {
ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ERROR_LOADING_SECTION);
return 0;
}
- for(i = 0; i < sk_CONF_VALUE_num(sktmp); i++)
- {
+ for(i = 0; i < sk_CONF_VALUE_num(sktmp); i++) {
oval = sk_CONF_VALUE_value(sktmp, i);
- if(!do_create(oval->value, oval->name))
- {
+ if(!do_create(oval->value, oval->name)) {
ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ADDING_OBJECT);
return 0;
}
ASN1_OBJECT *oid;
char *ln, *ostr, *p, *lntmp;
p = strrchr(value, ',');
- if (!p)
- {
+ if (!p) {
ln = name;
ostr = value;
- }
- else
- {
+ } else {
ln = NULL;
ostr = p + 1;
if (!*ostr)
if (nid == NID_undef)
return 0;
- if (p)
- {
+ if (p) {
ln = value;
while(isspace((unsigned char)*ln)) ln++;
p--;
- while(isspace((unsigned char)*p))
- {
+ while(isspace((unsigned char)*p)) {
if (p == ln)
return 0;
p--;
wrlen = 0;
ret = -1;
- for(;;)
- {
- switch (ctx->state)
- {
+ for(;;) {
+ switch (ctx->state) {
/* Setup prefix data, call it */
- case ASN1_STATE_START:
+ case ASN1_STATE_START:
if (!asn1_bio_setup_ex(b, ctx, ctx->prefix,
ASN1_STATE_PRE_COPY, ASN1_STATE_HEADER))
return 0;
break;
/* Copy any pre data first */
- case ASN1_STATE_PRE_COPY:
+ case ASN1_STATE_PRE_COPY:
ret = asn1_bio_flush_ex(b, ctx, ctx->prefix_free,
ASN1_STATE_HEADER);
break;
- case ASN1_STATE_HEADER:
+ case ASN1_STATE_HEADER:
ctx->buflen =
ASN1_object_size(0, inl, ctx->asn1_tag) - inl;
OPENSSL_assert(ctx->buflen <= ctx->bufsize);
break;
- case ASN1_STATE_HEADER_COPY:
+ case ASN1_STATE_HEADER_COPY:
ret = BIO_write(b->next_bio,
ctx->buf + ctx->bufpos, ctx->buflen);
if (ret <= 0)
ctx->buflen -= ret;
if (ctx->buflen)
ctx->bufpos += ret;
- else
- {
+ else {
ctx->bufpos = 0;
ctx->state = ASN1_STATE_DATA_COPY;
}
break;
- case ASN1_STATE_DATA_COPY:
+ case ASN1_STATE_DATA_COPY:
if (inl > ctx->copylen)
wrmax = ctx->copylen;
int ret;
if (ctx->ex_len <= 0)
return 1;
- for(;;)
- {
+ for(;;) {
ret = BIO_write(b->next_bio, ctx->ex_buf + ctx->ex_pos,
ctx->ex_len);
if (ret <= 0)
ctx->ex_len -= ret;
if (ctx->ex_len > 0)
ctx->ex_pos += ret;
- else
- {
+ else {
if(cleanup)
cleanup(b, &ctx->ex_buf, &ctx->ex_len,
&ctx->ex_arg);
asn1_bio_state_t ex_state,
asn1_bio_state_t other_state)
{
- if (setup && !setup(b, &ctx->ex_buf, &ctx->ex_len, &ctx->ex_arg))
- {
+ if (setup && !setup(b, &ctx->ex_buf, &ctx->ex_len, &ctx->ex_arg)) {
BIO_clear_retry_flags(b);
return 0;
}
ctx = (BIO_ASN1_BUF_CTX *) b->ptr;
if (ctx == NULL)
return 0;
- switch(cmd)
- {
+ switch(cmd) {
- case BIO_C_SET_PREFIX:
+ case BIO_C_SET_PREFIX:
ex_func = arg2;
ctx->prefix = ex_func->ex_func;
ctx->prefix_free = ex_func->ex_free_func;
break;
- case BIO_C_GET_PREFIX:
+ case BIO_C_GET_PREFIX:
ex_func = arg2;
ex_func->ex_func = ctx->prefix;
ex_func->ex_free_func = ctx->prefix_free;
break;
- case BIO_C_SET_SUFFIX:
+ case BIO_C_SET_SUFFIX:
ex_func = arg2;
ctx->suffix = ex_func->ex_func;
ctx->suffix_free = ex_func->ex_free_func;
break;
- case BIO_C_GET_SUFFIX:
+ case BIO_C_GET_SUFFIX:
ex_func = arg2;
ex_func->ex_func = ctx->suffix;
ex_func->ex_free_func = ctx->suffix_free;
break;
- case BIO_C_SET_EX_ARG:
+ case BIO_C_SET_EX_ARG:
ctx->ex_arg = arg2;
break;
- case BIO_C_GET_EX_ARG:
+ case BIO_C_GET_EX_ARG:
*(void **)arg2 = ctx->ex_arg;
break;
- case BIO_CTRL_FLUSH:
+ case BIO_CTRL_FLUSH:
if (!b->next_bio)
return 0;
/* Call post function if possible */
- if (ctx->state == ASN1_STATE_HEADER)
- {
+ if (ctx->state == ASN1_STATE_HEADER) {
if (!asn1_bio_setup_ex(b, ctx, ctx->suffix,
ASN1_STATE_POST_COPY, ASN1_STATE_DONE))
return 0;
}
- if (ctx->state == ASN1_STATE_POST_COPY)
- {
+ if (ctx->state == ASN1_STATE_POST_COPY) {
ret = asn1_bio_flush_ex(b, ctx, ctx->suffix_free,
ASN1_STATE_DONE);
if (ret <= 0)
if (ctx->state == ASN1_STATE_DONE)
return BIO_ctrl(b->next_bio, cmd, arg1, arg2);
- else
- {
+ else {
BIO_clear_retry_flags(b);
return 0;
}
break;
- default:
+ default:
if (!b->next_bio)
return 0;
return BIO_ctrl(b->next_bio, cmd, arg1, arg2);
BIO_ASN1_EX_FUNCS extmp;
int ret;
ret = BIO_ctrl(b, cmd, 0, &extmp);
- if (ret > 0)
- {
+ if (ret > 0) {
*ex_func = extmp.ex_func;
*ex_free_func = extmp.ex_free_func;
}
const ASN1_AUX *aux = it->funcs;
ASN1_STREAM_ARG sarg;
- if (!aux || !aux->asn1_cb)
- {
+ if (!aux || !aux->asn1_cb) {
ASN1err(ASN1_F_BIO_NEW_NDEF, ASN1_R_STREAMING_NOT_SUPPORTED);
return NULL;
}
{
EVP_PKEY *ret;
- if ((a == NULL) || (*a == NULL))
- {
- if ((ret=EVP_PKEY_new()) == NULL)
- {
+ if ((a == NULL) || (*a == NULL)) {
+ if ((ret=EVP_PKEY_new()) == NULL) {
ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_EVP_LIB);
return(NULL);
}
- }
- else
- {
+ } else {
ret= *a;
#ifndef OPENSSL_NO_ENGINE
- if (ret->engine)
- {
+ if (ret->engine) {
ENGINE_finish(ret->engine);
ret->engine = NULL;
}
#endif
}
- if (!EVP_PKEY_set_type(ret, type))
- {
+ if (!EVP_PKEY_set_type(ret, type)) {
ASN1err(ASN1_F_D2I_PRIVATEKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE);
goto err;
}
if (!ret->ameth->old_priv_decode ||
- !ret->ameth->old_priv_decode(ret, pp, length))
- {
- if (ret->ameth->priv_decode)
- {
+ !ret->ameth->old_priv_decode(ret, pp, length)) {
+ if (ret->ameth->priv_decode) {
PKCS8_PRIV_KEY_INFO *p8=NULL;
p8=d2i_PKCS8_PRIV_KEY_INFO(NULL,pp,length);
if (!p8) goto err;
ret = EVP_PKCS82PKEY(p8);
PKCS8_PRIV_KEY_INFO_free(p8);
- }
- else
- {
+ } else {
ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_ASN1_LIB);
goto err;
}
keytype = EVP_PKEY_DSA;
else if (sk_ASN1_TYPE_num(inkey) == 4)
keytype = EVP_PKEY_EC;
- else if (sk_ASN1_TYPE_num(inkey) == 3)
- { /* This seems to be PKCS8, not traditional format */
- PKCS8_PRIV_KEY_INFO *p8 = d2i_PKCS8_PRIV_KEY_INFO(NULL,pp,length);
- EVP_PKEY *ret;
+ else if (sk_ASN1_TYPE_num(inkey) == 3) {
+ /* This seems to be PKCS8, not traditional format */
+ PKCS8_PRIV_KEY_INFO *p8 = d2i_PKCS8_PRIV_KEY_INFO(NULL,pp,length);
+ EVP_PKEY *ret;
- sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free);
- if (!p8)
- {
- ASN1err(ASN1_F_D2I_AUTOPRIVATEKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
- return NULL;
- }
- ret = EVP_PKCS82PKEY(p8);
- PKCS8_PRIV_KEY_INFO_free(p8);
- if (a) {
- *a = ret;
+ sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free);
+ if (!p8) {
+ ASN1err(ASN1_F_D2I_AUTOPRIVATEKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
+ return NULL;
+ }
+ ret = EVP_PKCS82PKEY(p8);
+ PKCS8_PRIV_KEY_INFO_free(p8);
+ if (a) {
+ *a = ret;
}
- return ret;
- }
- else keytype = EVP_PKEY_RSA;
+ return ret;
+ } else
+ keytype = EVP_PKEY_RSA;
sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free);
return d2i_PrivateKey(keytype, a, pp, length);
}
{
EVP_PKEY *ret;
- if ((a == NULL) || (*a == NULL))
- {
- if ((ret=EVP_PKEY_new()) == NULL)
- {
+ if ((a == NULL) || (*a == NULL)) {
+ if ((ret=EVP_PKEY_new()) == NULL) {
ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_EVP_LIB);
return(NULL);
}
}
else ret= *a;
- if (!EVP_PKEY_set_type(ret, type))
- {
+ if (!EVP_PKEY_set_type(ret, type)) {
ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_EVP_LIB);
goto err;
}
- switch (EVP_PKEY_id(ret))
- {
+ switch (EVP_PKEY_id(ret)) {
#ifndef OPENSSL_NO_RSA
case EVP_PKEY_RSA:
if ((ret->pkey.rsa=d2i_RSAPublicKey(NULL,
int ret,num;
unsigned char *p;
- if ((a->type != V_ASN1_OCTET_STRING) || (a->value.octet_string == NULL))
- {
+ if ((a->type != V_ASN1_OCTET_STRING) || (a->value.octet_string == NULL)) {
ASN1err(ASN1_F_ASN1_TYPE_GET_OCTETSTRING,ASN1_R_DATA_IS_WRONG);
return(-1);
}
if ((osp=ASN1_STRING_new()) == NULL) return(0);
/* Grow the 'string' */
- if (!ASN1_STRING_set(osp,NULL,size))
- {
+ if (!ASN1_STRING_set(osp,NULL,size)) {
ASN1_STRING_free(osp);
return(0);
}
long length;
ASN1_const_CTX c;
- if ((a->type != V_ASN1_SEQUENCE) || (a->value.sequence == NULL))
- {
+ if ((a->type != V_ASN1_SEQUENCE) || (a->value.sequence == NULL)) {
goto err;
}
p=M_ASN1_STRING_data(a->value.sequence);
if (data != NULL)
memcpy(data,M_ASN1_STRING_data(os),n);
- if (0)
- {
+ if (0) {
err:
ASN1err(ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING,ASN1_R_DATA_IS_WRONG);
}
if (a == NULL) return(0);
- if (a->length == 0)
- {
+ if (a->length == 0) {
if (BIO_write(bp,"00",2) != 2) goto err;
n=2;
- }
- else
- {
- for (i=0; i<a->length; i++)
- {
- if ((i != 0) && (i%35 == 0))
- {
+ } else {
+ for (i=0; i<a->length; i++) {
+ if ((i != 0) && (i%35 == 0)) {
if (BIO_write(bp,"\\\n",2) != 2) goto err;
n+=2;
}
bs->type=V_ASN1_ENUMERATED;
bufsize=BIO_gets(bp,buf,size);
- for (;;)
- {
+ for (;;) {
if (bufsize < 1) goto err_sl;
i=bufsize;
if (buf[i-1] == '\n') buf[--i]='\0';
if (i == 0) goto err_sl;
again=(buf[i-1] == '\\');
- for (j=0; j<i; j++)
- {
+ for (j=0; j<i; j++) {
if (!( ((buf[j] >= '0') && (buf[j] <= '9')) ||
((buf[j] >= 'a') && (buf[j] <= 'f')) ||
- ((buf[j] >= 'A') && (buf[j] <= 'F'))))
- {
+ ((buf[j] >= 'A') && (buf[j] <= 'F')))) {
i=j;
break;
}
if (i < 2) goto err_sl;
bufp=(unsigned char *)buf;
- if (first)
- {
+ if (first) {
first=0;
- if ((bufp[0] == '0') && (buf[1] == '0'))
- {
+ if ((bufp[0] == '0') && (buf[1] == '0')) {
bufp+=2;
i-=2;
}
}
k=0;
i-=again;
- if (i%2 != 0)
- {
+ if (i%2 != 0) {
ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_ODD_NUMBER_OF_CHARS);
goto err;
}
i/=2;
- if (num+i > slen)
- {
+ if (num+i > slen) {
if (s == NULL)
sp=(unsigned char *)malloc(
(unsigned int)num+i*2);
else
sp=(unsigned char *)realloc(s,
(unsigned int)num+i*2);
- if (sp == NULL)
- {
+ if (sp == NULL) {
ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE);
if (s != NULL) free(s);
goto err;
s=sp;
slen=num+i*2;
}
- for (j=0; j<i; j++,k+=2)
- {
- for (n=0; n<2; n++)
- {
+ for (j=0; j<i; j++,k+=2) {
+ for (n=0; n<2; n++) {
m=bufp[k+n];
if ((m >= '0') && (m <= '9'))
m-='0';
m=m-'a'+10;
else if ((m >= 'A') && (m <= 'F'))
m=m-'A'+10;
- else
- {
+ else {
ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_NON_HEX_CHARACTERS);
goto err;
}
bs->data=s;
ret=1;
err:
- if (0)
- {
+ if (0) {
err_sl:
ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_SHORT_LINE);
}
if (a == NULL) return(0);
- if (a->type & V_ASN1_NEG)
- {
+ if (a->type & V_ASN1_NEG) {
if (BIO_write(bp, "-", 1) != 1) goto err;
n = 1;
}
- if (a->length == 0)
- {
+ if (a->length == 0) {
if (BIO_write(bp,"00",2) != 2) goto err;
n += 2;
- }
- else
- {
- for (i=0; i<a->length; i++)
- {
- if ((i != 0) && (i%35 == 0))
- {
+ } else {
+ for (i=0; i<a->length; i++) {
+ if ((i != 0) && (i%35 == 0)) {
if (BIO_write(bp,"\\\n",2) != 2) goto err;
n+=2;
}
bs->type=V_ASN1_INTEGER;
bufsize=BIO_gets(bp,buf,size);
- for (;;)
- {
+ for (;;) {
if (bufsize < 1) goto err_sl;
i=bufsize;
if (buf[i-1] == '\n') buf[--i]='\0';
if (i == 0) goto err_sl;
again=(buf[i-1] == '\\');
- for (j=0; j<i; j++)
- {
+ for (j=0; j<i; j++) {
if (!( ((buf[j] >= '0') && (buf[j] <= '9')) ||
((buf[j] >= 'a') && (buf[j] <= 'f')) ||
- ((buf[j] >= 'A') && (buf[j] <= 'F'))))
- {
+ ((buf[j] >= 'A') && (buf[j] <= 'F')))) {
i=j;
break;
}
if (i < 2) goto err_sl;
bufp=(unsigned char *)buf;
- if (first)
- {
+ if (first) {
first=0;
- if ((bufp[0] == '0') && (buf[1] == '0'))
- {
+ if ((bufp[0] == '0') && (buf[1] == '0')) {
bufp+=2;
i-=2;
}
}
k=0;
i-=again;
- if (i%2 != 0)
- {
+ if (i%2 != 0) {
ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_ODD_NUMBER_OF_CHARS);
goto err;
}
i/=2;
- if (num+i > slen)
- {
+ if (num+i > slen) {
if (s == NULL)
sp=(unsigned char *)malloc(
(unsigned int)num+i*2);
else
sp=OPENSSL_realloc_clean(s,slen,num+i*2);
- if (sp == NULL)
- {
+ if (sp == NULL) {
ASN1err(ASN1_F_A2I_ASN1_INTEGER,ERR_R_MALLOC_FAILURE);
if (s != NULL) free(s);
goto err;
s=sp;
slen=num+i*2;
}
- for (j=0; j<i; j++,k+=2)
- {
- for (n=0; n<2; n++)
- {
+ for (j=0; j<i; j++,k+=2) {
+ for (n=0; n<2; n++) {
m=bufp[k+n];
if ((m >= '0') && (m <= '9'))
m-='0';
m=m-'a'+10;
else if ((m >= 'A') && (m <= 'F'))
m=m-'A'+10;
- else
- {
+ else {
ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_NON_HEX_CHARACTERS);
goto err;
}
bs->data=s;
ret=1;
err:
- if (0)
- {
+ if (0) {
err_sl:
ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_SHORT_LINE);
}
if (a == NULL) return(0);
- if (a->length == 0)
- {
+ if (a->length == 0) {
if (BIO_write(bp,"0",1) != 1) goto err;
n=1;
- }
- else
- {
- for (i=0; i<a->length; i++)
- {
- if ((i != 0) && (i%35 == 0))
- {
+ } else {
+ for (i=0; i<a->length; i++) {
+ if ((i != 0) && (i%35 == 0)) {
if (BIO_write(bp,"\\\n",2) != 2) goto err;
n+=2;
}
int num=0,slen=0,first=1;
bufsize=BIO_gets(bp,buf,size);
- for (;;)
- {
- if (bufsize < 1)
- {
+ for (;;) {
+ if (bufsize < 1) {
if (first)
break;
else
if (i == 0) goto err_sl;
again=(buf[i-1] == '\\');
- for (j=i-1; j>0; j--)
- {
+ for (j=i-1; j>0; j--) {
if (!( ((buf[j] >= '0') && (buf[j] <= '9')) ||
((buf[j] >= 'a') && (buf[j] <= 'f')) ||
- ((buf[j] >= 'A') && (buf[j] <= 'F'))))
- {
+ ((buf[j] >= 'A') && (buf[j] <= 'F')))) {
i=j;
break;
}
k=0;
i-=again;
- if (i%2 != 0)
- {
+ if (i%2 != 0) {
ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_ODD_NUMBER_OF_CHARS);
goto err;
}
i/=2;
- if (num+i > slen)
- {
+ if (num+i > slen) {
if (s == NULL)
sp=(unsigned char *)malloc(
(unsigned int)num+i*2);
else
sp=(unsigned char *)realloc(s,
(unsigned int)num+i*2);
- if (sp == NULL)
- {
+ if (sp == NULL) {
ASN1err(ASN1_F_A2I_ASN1_STRING,ERR_R_MALLOC_FAILURE);
if (s != NULL) free(s);
goto err;
s=sp;
slen=num+i*2;
}
- for (j=0; j<i; j++,k+=2)
- {
- for (n=0; n<2; n++)
- {
+ for (j=0; j<i; j++,k+=2) {
+ for (n=0; n<2; n++) {
m=bufp[k+n];
if ((m >= '0') && (m <= '9'))
m-='0';
m=m-'a'+10;
else if ((m >= 'A') && (m <= 'F'))
m=m-'A'+10;
- else
- {
+ else {
ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_NON_HEX_CHARACTERS);
goto err;
}
bs->data=s;
ret=1;
err:
- if (0)
- {
+ if (0) {
err_sl:
ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_SHORT_LINE);
}
int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp)
{
- if (a->ameth && a->ameth->old_priv_encode)
- {
+ if (a->ameth && a->ameth->old_priv_encode) {
return a->ameth->old_priv_encode(a, pp);
}
if (a->ameth && a->ameth->priv_encode) {
int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp)
{
- switch (a->type)
- {
+ switch (a->type) {
#ifndef OPENSSL_NO_RSA
case EVP_PKEY_RSA:
return(i2d_RSAPublicKey(a->pkey.rsa,pp));
if ((enckey->enckey->algor->parameter=ASN1_TYPE_new()) == NULL) goto err;
enckey->enckey->algor->parameter->type=V_ASN1_NULL;
- if (pp == NULL)
- {
+ if (pp == NULL) {
olen = i2d_NETSCAPE_ENCRYPTED_PKEY(enckey, NULL);
NETSCAPE_PKEY_free(pkey);
NETSCAPE_ENCRYPTED_PKEY_free(enckey);
/* Since its RC4 encrypted length is actual length */
- if ((zz=(unsigned char *)malloc(rsalen)) == NULL)
- {
+ if ((zz=(unsigned char *)malloc(rsalen)) == NULL) {
ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE);
goto err;
}
/* Write out private key encoding */
i2d_RSAPrivateKey(a,&zz);
- if ((zz=malloc(pkeylen)) == NULL)
- {
+ if ((zz=malloc(pkeylen)) == NULL) {
ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE);
goto err;
}
- if (!ASN1_STRING_set(enckey->os, "private-key", -1))
- {
+ if (!ASN1_STRING_set(enckey->os, "private-key", -1)) {
ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE);
goto err;
}
if (cb == NULL)
cb=EVP_read_pw_string;
i=cb((char *)buf,256,"Enter Private Key password:",1);
- if (i != 0)
- {
+ if (i != 0) {
ASN1err(ASN1_F_I2D_RSA_NET,ASN1_R_BAD_PASSWORD_READ);
goto err;
}
}
if ((enckey->os->length != 11) || (strncmp("private-key",
- (char *)enckey->os->data,11) != 0))
- {
+ (char *)enckey->os->data,11) != 0)) {
ASN1err(ASN1_F_D2I_RSA_NET,ASN1_R_PRIVATE_KEY_HEADER_MISSING);
NETSCAPE_ENCRYPTED_PKEY_free(enckey);
return NULL;
}
- if (OBJ_obj2nid(enckey->enckey->algor->algorithm) != NID_rc4)
- {
+ if (OBJ_obj2nid(enckey->enckey->algor->algorithm) != NID_rc4) {
ASN1err(ASN1_F_D2I_RSA_NET,ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM);
goto err;
}
EVP_CIPHER_CTX_init(&ctx);
i=cb((char *)buf,256,"Enter Private Key password:",0);
- if (i != 0)
- {
+ if (i != 0) {
ASN1err(ASN1_F_D2I_RSA_NET_2,ASN1_R_BAD_PASSWORD_READ);
goto err;
}
zz=os->data;
- if ((pkey=d2i_NETSCAPE_PKEY(NULL,&zz,os->length)) == NULL)
- {
+ if ((pkey=d2i_NETSCAPE_PKEY(NULL,&zz,os->length)) == NULL) {
ASN1err(ASN1_F_D2I_RSA_NET_2,ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY);
goto err;
}
zz=pkey->private_key->data;
- if ((ret=d2i_RSAPrivateKey(a,&zz,pkey->private_key->length)) == NULL)
- {
+ if ((ret=d2i_RSAPrivateKey(a,&zz,pkey->private_key->length)) == NULL) {
ASN1err(ASN1_F_D2I_RSA_NET_2,ASN1_R_UNABLE_TO_DECODE_RSA_KEY);
goto err;
}
unsigned char *sstr;
pbe = PBEPARAM_new();
- if (!pbe)
- {
+ if (!pbe) {
ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR,ERR_R_MALLOC_FAILURE);
goto err;
}
if(iter <= 0)
iter = PKCS5_DEFAULT_ITER;
- if (!ASN1_INTEGER_set(pbe->iter, iter))
- {
+ if (!ASN1_INTEGER_set(pbe->iter, iter)) {
ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR,ERR_R_MALLOC_FAILURE);
goto err;
}
if (!saltlen)
saltlen = PKCS5_SALT_LEN;
- if (!ASN1_STRING_set(pbe->salt, NULL, saltlen))
- {
+ if (!ASN1_STRING_set(pbe->salt, NULL, saltlen)) {
ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR,ERR_R_MALLOC_FAILURE);
goto err;
}
else if (RAND_pseudo_bytes(sstr, saltlen) < 0)
goto err;
- if(!ASN1_item_pack(pbe, ASN1_ITEM_rptr(PBEPARAM), &pbe_str))
- {
+ if(!ASN1_item_pack(pbe, ASN1_ITEM_rptr(PBEPARAM), &pbe_str)) {
ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR,ERR_R_MALLOC_FAILURE);
goto err;
}
{
X509_ALGOR *ret;
ret = X509_ALGOR_new();
- if (!ret)
- {
+ if (!ret) {
ASN1err(ASN1_F_PKCS5_PBE_SET,ERR_R_MALLOC_FAILURE);
return NULL;
}
if(!(scheme->parameter = ASN1_TYPE_new())) goto merr;
/* Create random IV */
- if (EVP_CIPHER_iv_length(cipher))
- {
+ if (EVP_CIPHER_iv_length(cipher)) {
if (aiv)
memcpy(iv, aiv, EVP_CIPHER_iv_length(cipher));
else if (RAND_pseudo_bytes(iv, EVP_CIPHER_iv_length(cipher)) < 0)
goto err;
- }
+ }
EVP_CIPHER_CTX_init(&ctx);
* An error is OK here: just means use default PRF.
*/
if ((prf_nid == -1) &&
- EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_PBE_PRF_NID, 0, &prf_nid) <= 0)
- {
+ EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_PBE_PRF_NID, 0, &prf_nid) <= 0) {
ERR_clear_error();
prf_nid = NID_hmacWithSHA1;
- }
+ }
EVP_CIPHER_CTX_cleanup(&ctx);
/* If its RC2 then we'd better setup the key length */
return ret;
- merr:
+merr:
ASN1err(ASN1_F_PKCS5_PBE2_SET_IV,ERR_R_MALLOC_FAILURE);
err:
X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
unsigned char *salt, int saltlen)
- {
+{
return PKCS5_pbe2_set_iv(cipher, iter, salt, saltlen, NULL, -1);
- }
+}
X509_ALGOR *PKCS5_pbkdf2_set(int iter, unsigned char *salt, int saltlen,
int prf_nid, int keylen)
- {
+{
X509_ALGOR *keyfunc = NULL;
PBKDF2PARAM *kdf = NULL;
ASN1_OCTET_STRING *osalt = NULL;
/* If have a key len set it up */
- if(keylen > 0)
- {
+ if(keylen > 0) {
if(!(kdf->keylength = M_ASN1_INTEGER_new()))
goto merr;
if(!ASN1_INTEGER_set (kdf->keylength, keylen))
}
/* prf can stay NULL if we are using hmacWithSHA1 */
- if (prf_nid > 0 && prf_nid != NID_hmacWithSHA1)
- {
+ if (prf_nid > 0 && prf_nid != NID_hmacWithSHA1) {
kdf->prf = X509_ALGOR_new();
if (!kdf->prf)
goto merr;
X509_ALGOR_set0(kdf->prf, OBJ_nid2obj(prf_nid),
V_ASN1_NULL, NULL);
- }
+ }
/* Finally setup the keyfunc structure */
PBKDF2PARAM_free(kdf);
return keyfunc;
- merr:
+merr:
ASN1err(ASN1_F_PKCS5_PBKDF2_SET,ERR_R_MALLOC_FAILURE);
PBKDF2PARAM_free(kdf);
X509_ALGOR_free(keyfunc);
return NULL;
- }
+}
unsigned char *penc, int penclen)
{
unsigned char **ppenc = NULL;
- if (version >= 0)
- {
+ if (version >= 0) {
if (!ASN1_INTEGER_set(priv->version, version))
return 0;
}
- if (penc)
- {
+ if (penc) {
int pmtype;
ASN1_OCTET_STRING *oct;
oct = ASN1_OCTET_STRING_new();
pmtype = V_ASN1_OCTET_STRING;
ASN1_TYPE_set(priv->pkey, pmtype, oct);
}
- if (!X509_ALGOR_set0(priv->pkeyalg, aobj, ptype, pval))
- {
+ if (!X509_ALGOR_set0(priv->pkeyalg, aobj, ptype, pval)) {
/* If call fails do not swallow 'enc' */
if (ppenc)
*ppenc = NULL;
{
if (ppkalg)
*ppkalg = p8->pkeyalg->algorithm;
- if(p8->pkey->type == V_ASN1_OCTET_STRING)
- {
+ if(p8->pkey->type == V_ASN1_OCTET_STRING) {
p8->broken = PKCS8_OK;
- if (pk)
- {
+ if (pk) {
*pk = p8->pkey->value.octet_string->data;
*ppklen = p8->pkey->value.octet_string->length;
}
- }
- else if (p8->pkey->type == V_ASN1_SEQUENCE)
- {
+ } else if (p8->pkey->type == V_ASN1_SEQUENCE) {
p8->broken = PKCS8_NO_OCTET;
- if (pk)
- {
+ if (pk) {
*pk = p8->pkey->value.sequence->data;
*ppklen = p8->pkey->value.sequence->length;
}
BIO *b;
int ret;
- if ((b=BIO_new(BIO_s_file())) == NULL)
- {
+ if ((b=BIO_new(BIO_s_file())) == NULL) {
X509err(X509_F_X509_CRL_PRINT_FP,ERR_R_BUF_LIB);
return(0);
}
neg = (BN_is_negative(num))?"-":"";
if(!BIO_indent(bp,off,128))
return 0;
- if (BN_is_zero(num))
- {
+ if (BN_is_zero(num)) {
if (BIO_printf(bp, "%s 0\n", number) <= 0)
return 0;
return 1;
}
- if (BN_num_bytes(num) <= BN_BYTES)
- {
+ if (BN_num_bytes(num) <= BN_BYTES) {
if (BIO_printf(bp,"%s %s%lu (%s0x%lx)\n",number,neg,
(unsigned long)num->d[0],neg,(unsigned long)num->d[0])
<= 0) return(0);
- }
- else
- {
+ } else {
buf[0]=0;
if (BIO_printf(bp,"%s%s",number,
(neg[0] == '-')?" (Negative)":"") <= 0)
n++;
else buf++;
- for (i=0; i<n; i++)
- {
- if ((i%15) == 0)
- {
+ for (i=0; i<n; i++) {
+ if ((i%15) == 0) {
if(BIO_puts(bp,"\n") <= 0
|| !BIO_indent(bp,off+4,128))
return 0;
BIO *b;
int ret;
- if ((b=BIO_new(BIO_s_file())) == NULL)
- {
+ if ((b=BIO_new(BIO_s_file())) == NULL) {
X509err(X509_F_X509_REQ_PRINT_FP,ERR_R_BUF_LIB);
return(0);
}
ri=x->req_info;
- if(!(cflag & X509_FLAG_NO_HEADER))
- {
+ if(!(cflag & X509_FLAG_NO_HEADER)) {
if (BIO_write(bp,"Certificate Request:\n",21) <= 0) goto err;
if (BIO_write(bp," Data:\n",10) <= 0) goto err;
}
- if(!(cflag & X509_FLAG_NO_VERSION))
- {
+ if(!(cflag & X509_FLAG_NO_VERSION)) {
neg=(ri->version->type == V_ASN1_NEG_INTEGER)?"-":"";
l=0;
- for (i=0; i<ri->version->length; i++)
- { l<<=8; l+=ri->version->data[i]; }
+ for (i=0; i<ri->version->length; i++) {
+ l<<=8; l+=ri->version->data[i];
+ }
if(BIO_printf(bp,"%8sVersion: %s%lu (%s0x%lx)\n","",neg,l,neg,
l) <= 0)
goto err;
if (X509_NAME_print_ex(bp,ri->subject,nmindent, nmflags) < 0) goto err;
if (BIO_write(bp,"\n",1) <= 0) goto err;
}
- if(!(cflag & X509_FLAG_NO_PUBKEY))
- {
+ if(!(cflag & X509_FLAG_NO_PUBKEY)) {
if (BIO_write(bp," Subject Public Key Info:\n",33) <= 0)
goto err;
if (BIO_printf(bp,"%12sPublic Key Algorithm: ","") <= 0)
goto err;
pkey=X509_REQ_get_pubkey(x);
- if (pkey == NULL)
- {
+ if (pkey == NULL) {
BIO_printf(bp,"%12sUnable to load Public Key\n","");
ERR_print_errors(bp);
- }
- else
- {
+ } else {
EVP_PKEY_print_public(bp, pkey, 16, NULL);
EVP_PKEY_free(pkey);
}
}
- if(!(cflag & X509_FLAG_NO_ATTRIBUTES))
- {
+ if(!(cflag & X509_FLAG_NO_ATTRIBUTES)) {
/* may not be */
if(BIO_printf(bp,"%8sAttributes:\n","") <= 0)
goto err;
sk=x->req_info->attributes;
- if (sk_X509_ATTRIBUTE_num(sk) == 0)
- {
+ if (sk_X509_ATTRIBUTE_num(sk) == 0) {
if(BIO_printf(bp,"%12sa0:00\n","") <= 0)
goto err;
- }
- else
- {
- for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++)
- {
+ } else {
+ for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++) {
ASN1_TYPE *at;
X509_ATTRIBUTE *a;
ASN1_BIT_STRING *bs=NULL;
continue;
if(BIO_printf(bp,"%12s","") <= 0)
goto err;
- if ((j=i2a_ASN1_OBJECT(bp,a->object)) > 0)
- {
- if (a->single)
- {
+ if ((j=i2a_ASN1_OBJECT(bp,a->object)) > 0) {
+ if (a->single) {
t=a->value.single;
type=t->type;
bs=t->value.bit_string;
- }
- else
- {
+ } else {
ii=0;
count=sk_ASN1_TYPE_num(a->value.set);
get_next:
if (BIO_puts(bp,":") <= 0) goto err;
if ( (type == V_ASN1_PRINTABLESTRING) ||
(type == V_ASN1_T61STRING) ||
- (type == V_ASN1_IA5STRING))
- {
+ (type == V_ASN1_IA5STRING)) {
if (BIO_write(bp,(char *)bs->data,bs->length)
!= bs->length)
goto err;
BIO_puts(bp,"\n");
- }
- else
- {
+ } else {
BIO_puts(bp,"unable to print attribute\n");
}
if (++ii < count) goto get_next;
}
}
}
- if(!(cflag & X509_FLAG_NO_EXTENSIONS))
- {
+ if(!(cflag & X509_FLAG_NO_EXTENSIONS)) {
exts = X509_REQ_get_extensions(x);
- if(exts)
- {
+ if(exts) {
BIO_printf(bp,"%8sRequested Extensions:\n","");
- for (i=0; i<sk_X509_EXTENSION_num(exts); i++)
- {
+ for (i=0; i<sk_X509_EXTENSION_num(exts); i++) {
ASN1_OBJECT *obj;
X509_EXTENSION *ex;
int j;
j=X509_EXTENSION_get_critical(ex);
if (BIO_printf(bp,": %s\n",j?"critical":"") <= 0)
goto err;
- if(!X509V3_EXT_print(bp, ex, cflag, 16))
- {
+ if(!X509V3_EXT_print(bp, ex, cflag, 16)) {
BIO_printf(bp, "%16s", "");
M_ASN1_OCTET_STRING_print(bp,ex->value);
}
}
}
- if(!(cflag & X509_FLAG_NO_SIGDUMP))
- {
+ if(!(cflag & X509_FLAG_NO_SIGDUMP)) {
if(!X509_signature_print(bp, x->sig_alg, x->signature)) goto err;
}
BIO_printf(out," Public Key Algorithm: %s\n",
(i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i));
pkey = X509_PUBKEY_get(spki->spkac->pubkey);
- if(!pkey) BIO_printf(out, " Unable to load public key\n");
- else
- {
+ if(!pkey)
+ BIO_printf(out, " Unable to load public key\n");
+ else {
EVP_PKEY_print_public(out, pkey, 4, NULL);
EVP_PKEY_free(pkey);
}
n=spki->signature->length;
s=(char *)spki->signature->data;
- for (i=0; i<n; i++)
- {
- if ((i%18) == 0) BIO_write(out,"\n ",7);
+ for (i=0; i<n; i++) {
+ if ((i%18) == 0)
+ BIO_write(out,"\n ",7);
BIO_printf(out,"%02x%s",(unsigned char)s[i],
((i+1) == n)?"":":");
}
BIO *b;
int ret;
- if ((b=BIO_new(BIO_s_file())) == NULL)
- {
+ if ((b=BIO_new(BIO_s_file())) == NULL) {
X509err(X509_F_X509_PRINT_EX_FP,ERR_R_BUF_LIB);
return(0);
}
nmindent = 16;
ci=x->cert_info;
- if(!(cflag & X509_FLAG_NO_HEADER))
- {
+ if(!(cflag & X509_FLAG_NO_HEADER)) {
if (BIO_write(bp,"Certificate:\n",13) <= 0) goto err;
if (BIO_write(bp," Data:\n",10) <= 0) goto err;
}
- if(!(cflag & X509_FLAG_NO_VERSION))
- {
+ if(!(cflag & X509_FLAG_NO_VERSION)) {
l=X509_get_version(x);
if (BIO_printf(bp,"%8sVersion: %lu (0x%lx)\n","",l+1,l) <= 0) goto err;
}
- if(!(cflag & X509_FLAG_NO_SERIAL))
- {
+ if(!(cflag & X509_FLAG_NO_SERIAL)) {
if (BIO_write(bp," Serial Number:",22) <= 0) goto err;
bs=X509_get_serialNumber(x);
- if (bs->length <= (int)sizeof(long))
- {
+ if (bs->length <= (int)sizeof(long)) {
l=ASN1_INTEGER_get(bs);
- if (bs->type == V_ASN1_NEG_INTEGER)
- {
+ if (bs->type == V_ASN1_NEG_INTEGER) {
l= -l;
neg="-";
- }
- else
+ } else
neg="";
if (BIO_printf(bp," %s%lu (%s0x%lx)\n",neg,l,neg,l) <= 0)
goto err;
- }
- else
- {
+ } else {
neg=(bs->type == V_ASN1_NEG_INTEGER)?" (Negative)":"";
if (BIO_printf(bp,"\n%12s%s","",neg) <= 0) goto err;
- for (i=0; i<bs->length; i++)
- {
+ for (i=0; i<bs->length; i++) {
if (BIO_printf(bp,"%02x%c",bs->data[i],
((i+1 == bs->length)?'\n':':')) <= 0)
goto err;
}
- if(!(cflag & X509_FLAG_NO_SIGNAME))
- {
+ if(!(cflag & X509_FLAG_NO_SIGNAME)) {
if(X509_signature_print(bp, x->sig_alg, NULL) <= 0)
goto err;
#if 0
#endif
}
- if(!(cflag & X509_FLAG_NO_ISSUER))
- {
+ if(!(cflag & X509_FLAG_NO_ISSUER)) {
if (BIO_printf(bp," Issuer:%c",mlch) <= 0) goto err;
if (X509_NAME_print_ex(bp,X509_get_issuer_name(x),nmindent, nmflags) < 0) goto err;
if (BIO_write(bp,"\n",1) <= 0) goto err;
}
- if(!(cflag & X509_FLAG_NO_VALIDITY))
- {
+ if(!(cflag & X509_FLAG_NO_VALIDITY)) {
if (BIO_write(bp," Validity\n",17) <= 0) goto err;
if (BIO_write(bp," Not Before: ",24) <= 0) goto err;
if (!ASN1_TIME_print(bp,X509_get_notBefore(x))) goto err;
if (!ASN1_TIME_print(bp,X509_get_notAfter(x))) goto err;
if (BIO_write(bp,"\n",1) <= 0) goto err;
}
- if(!(cflag & X509_FLAG_NO_SUBJECT))
- {
+ if(!(cflag & X509_FLAG_NO_SUBJECT)) {
if (BIO_printf(bp," Subject:%c",mlch) <= 0) goto err;
if (X509_NAME_print_ex(bp,X509_get_subject_name(x),nmindent, nmflags) < 0) goto err;
if (BIO_write(bp,"\n",1) <= 0) goto err;
}
- if(!(cflag & X509_FLAG_NO_PUBKEY))
- {
+ if(!(cflag & X509_FLAG_NO_PUBKEY)) {
if (BIO_write(bp," Subject Public Key Info:\n",33) <= 0)
goto err;
if (BIO_printf(bp,"%12sPublic Key Algorithm: ","") <= 0)
goto err;
pkey=X509_get_pubkey(x);
- if (pkey == NULL)
- {
+ if (pkey == NULL) {
BIO_printf(bp,"%12sUnable to load Public Key\n","");
ERR_print_errors(bp);
- }
- else
- {
+ } else {
EVP_PKEY_print_public(bp, pkey, 16, NULL);
EVP_PKEY_free(pkey);
}
X509V3_extensions_print(bp, "X509v3 extensions",
ci->extensions, cflag, 8);
- if(!(cflag & X509_FLAG_NO_SIGDUMP))
- {
+ if(!(cflag & X509_FLAG_NO_SIGDUMP)) {
if(X509_signature_print(bp, x->sig_alg, x->signature) <= 0) goto err;
}
- if(!(cflag & X509_FLAG_NO_AUX))
- {
+ if(!(cflag & X509_FLAG_NO_AUX)) {
if (!X509_CERT_AUX_print(bp, x->aux, 0)) goto err;
}
ret=1;
if (!EVP_Digest(der, derlen, SHA1md, NULL, EVP_sha1(), NULL))
goto err;
- for (i=0; i < SHA_DIGEST_LENGTH; i++)
- {
+ for (i=0; i < SHA_DIGEST_LENGTH; i++) {
if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0) goto err;
}
free (der);
x->cert_info->key->public_key->length,
SHA1md, NULL, EVP_sha1(), NULL))
goto err;
- for (i=0; i < SHA_DIGEST_LENGTH; i++)
- {
+ for (i=0; i < SHA_DIGEST_LENGTH; i++) {
if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0)
goto err;
}
n=sig->length;
s=sig->data;
- for (i=0; i<n; i++)
- {
- if ((i%18) == 0)
- {
+ for (i=0; i<n; i++) {
+ if ((i%18) == 0) {
if (BIO_write(bp,"\n",1) <= 0) return 0;
if (BIO_indent(bp, indent, indent) <= 0) return 0;
}
if (i2a_ASN1_OBJECT(bp, sigalg->algorithm) <= 0) return 0;
sig_nid = OBJ_obj2nid(sigalg->algorithm);
- if (sig_nid != NID_undef)
- {
+ if (sig_nid != NID_undef) {
int pkey_nid, dig_nid;
const EVP_PKEY_ASN1_METHOD *ameth;
- if (OBJ_find_sigid_algs(sig_nid, &dig_nid, &pkey_nid))
- {
+ if (OBJ_find_sigid_algs(sig_nid, &dig_nid, &pkey_nid)) {
ameth = EVP_PKEY_asn1_find(NULL, pkey_nid);
if (ameth && ameth->sig_print)
return ameth->sig_print(bp, sigalg, sig, 9, 0);
if (v == NULL) return(0);
n=0;
p=(const char *)v->data;
- for (i=0; i<v->length; i++)
- {
+ for (i=0; i<v->length; i++) {
if ((p[i] > '~') || ((p[i] < ' ') &&
(p[i] != '\n') && (p[i] != '\r')))
buf[n]='.';
else
buf[n]=p[i];
n++;
- if (n >= 80)
- {
+ if (n >= 80) {
if (BIO_write(bp,buf,n) <= 0)
return(0);
n=0;
m= (v[10]-'0')*10+(v[11]-'0');
if (tm->length >= 14 &&
(v[12] >= '0') && (v[12] <= '9') &&
- (v[13] >= '0') && (v[13] <= '9'))
- {
+ (v[13] >= '0') && (v[13] <= '9')) {
s= (v[12]-'0')*10+(v[13]-'0');
/* Check for fractions of seconds. */
- if (tm->length >= 15 && v[14] == '.')
- {
+ if (tm->length >= 15 && v[14] == '.') {
int l = tm->length;
f = &v[14]; /* The decimal point. */
f_len = 1;
l=80-2-obase;
b=X509_NAME_oneline(name,NULL,0);
- if (!*b)
- {
+ if (!*b) {
free(b);
return 1;
}
s=b+1; /* skip the first slash */
c=s;
- for (;;)
- {
+ for (;;) {
if ( ((*s == '/') &&
((s[1] >= 'A') && (s[1] <= 'Z') && (
(s[2] == '=') ||
((s[2] >= 'A') && (s[2] <= 'Z') &&
(s[3] == '='))
))) ||
- (*s == '\0'))
- {
+ (*s == '\0')) {
i=s-c;
if (BIO_write(bp,c,i) != i) goto err;
c=s+1; /* skip following slash */
- if (*s != '\0')
- {
+ if (*s != '\0') {
if (BIO_write(bp,", ",2) != 2) goto err;
}
l--;
}
ret=1;
- if (0)
- {
+ if (0) {
err:
X509err(X509_F_X509_NAME_PRINT,ERR_R_BUF_LIB);
}
asn1_cb = aux->asn1_cb;
else asn1_cb = 0;
- switch(it->itype)
- {
- case ASN1_ITYPE_PRIMITIVE:
- if (it->templates)
- {
+ switch(it->itype) {
+ case ASN1_ITYPE_PRIMITIVE:
+ if (it->templates) {
/* tagging or OPTIONAL is currently illegal on an item
* template because the flags can't get passed down.
* In practice this isn't a problem: we include the
* relevant flags from the item template in the
* template itself.
*/
- if ((tag != -1) || opt)
- {
+ if ((tag != -1) || opt) {
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE);
goto err;
tag, aclass, opt, ctx);
break;
- case ASN1_ITYPE_MSTRING:
+ case ASN1_ITYPE_MSTRING:
p = *in;
/* Just read in tag and class */
ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, NULL,
&p, len, -1, 0, 1, ctx);
- if (!ret)
- {
+ if (!ret) {
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
ERR_R_NESTED_ASN1_ERROR);
goto err;
}
/* Must be UNIVERSAL class */
- if (oclass != V_ASN1_UNIVERSAL)
- {
+ if (oclass != V_ASN1_UNIVERSAL) {
/* If OPTIONAL, assume this is OK */
if (opt) return -1;
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
goto err;
}
/* Check tag matches bit map */
- if (!(ASN1_tag2bit(otag) & it->utype))
- {
+ if (!(ASN1_tag2bit(otag) & it->utype)) {
/* If OPTIONAL, assume this is OK */
if (opt)
return -1;
return asn1_d2i_ex_primitive(pval, in, len,
it, otag, 0, 0, ctx);
- case ASN1_ITYPE_EXTERN:
+ case ASN1_ITYPE_EXTERN:
/* Use new style d2i */
ef = it->funcs;
return ef->asn1_ex_d2i(pval, in, len,
it, tag, aclass, opt, ctx);
- case ASN1_ITYPE_COMPAT:
+ case ASN1_ITYPE_COMPAT:
/* we must resort to old style evil hackery */
cf = it->funcs;
/* If OPTIONAL see if it is there */
- if (opt)
- {
+ if (opt) {
int exptag;
p = *in;
if (tag == -1)
ret = asn1_check_tlen(NULL, NULL, NULL, NULL, NULL,
&p, len, exptag, aclass, 1, ctx);
- if (!ret)
- {
+ if (!ret) {
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
ERR_R_NESTED_ASN1_ERROR);
goto err;
* buffer.
*/
- if (tag != -1)
- {
+ if (tag != -1) {
wp = *(unsigned char **)in;
imphack = *wp;
- if (p == NULL)
- {
+ if (p == NULL) {
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
ERR_R_NESTED_ASN1_ERROR);
goto err;
goto err;
- case ASN1_ITYPE_CHOICE:
+ case ASN1_ITYPE_CHOICE:
if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL))
goto auxerr;
/* Allocate structure */
- if (!*pval && !ASN1_item_ex_new(pval, it))
- {
+ if (!*pval && !ASN1_item_ex_new(pval, it)) {
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
ERR_R_NESTED_ASN1_ERROR);
goto err;
}
/* CHOICE type, try each possibility in turn */
p = *in;
- for (i = 0, tt=it->templates; i < it->tcount; i++, tt++)
- {
+ for (i = 0, tt=it->templates; i < it->tcount; i++, tt++) {
pchptr = asn1_get_field_ptr(pval, tt);
/* We mark field as OPTIONAL so its absence
* can be recognised.
}
/* Did we fall off the end without reading anything? */
- if (i == it->tcount)
- {
+ if (i == it->tcount) {
/* If OPTIONAL, this is OK */
- if (opt)
- {
+ if (opt) {
/* Free and zero it */
ASN1_item_ex_free(pval, it);
return -1;
goto auxerr;
return 1;
- case ASN1_ITYPE_NDEF_SEQUENCE:
- case ASN1_ITYPE_SEQUENCE:
+ case ASN1_ITYPE_NDEF_SEQUENCE:
+ case ASN1_ITYPE_SEQUENCE:
p = *in;
tmplen = len;
/* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */
- if (tag == -1)
- {
+ if (tag == -1) {
tag = V_ASN1_SEQUENCE;
aclass = V_ASN1_UNIVERSAL;
}
/* Get SEQUENCE length and update len, p */
ret = asn1_check_tlen(&len, NULL, NULL, &seq_eoc, &cst,
&p, len, tag, aclass, opt, ctx);
- if (!ret)
- {
+ if (!ret) {
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
ERR_R_NESTED_ASN1_ERROR);
goto err;
}
else if (ret == -1)
return -1;
- if (aux && (aux->flags & ASN1_AFLG_BROKEN))
- {
+ if (aux && (aux->flags & ASN1_AFLG_BROKEN)) {
len = tmplen - (p - *in);
seq_nolen = 1;
}
/* If indefinite we don't do a length check */
else seq_nolen = seq_eoc;
- if (!cst)
- {
+ if (!cst) {
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
ASN1_R_SEQUENCE_NOT_CONSTRUCTED);
goto err;
}
- if (!*pval && !ASN1_item_ex_new(pval, it))
- {
+ if (!*pval && !ASN1_item_ex_new(pval, it)) {
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
ERR_R_NESTED_ASN1_ERROR);
goto err;
goto auxerr;
/* Get each field entry */
- for (i = 0, tt = it->templates; i < it->tcount; i++, tt++)
- {
+ for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
const ASN1_TEMPLATE *seqtt;
ASN1_VALUE **pseqval;
seqtt = asn1_do_adb(pval, tt, 1);
if (!len)
break;
q = p;
- if (asn1_check_eoc(&p, len))
- {
- if (!seq_eoc)
- {
+ if (asn1_check_eoc(&p, len)) {
+ if (!seq_eoc) {
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
ASN1_R_UNEXPECTED_EOC);
goto err;
ret = asn1_template_ex_d2i(pseqval, &p, len,
seqtt, isopt, ctx);
- if (!ret)
- {
+ if (!ret) {
errtt = seqtt;
goto err;
- }
- else if (ret == -1)
- {
+ } else if (ret == -1) {
/* OPTIONAL component absent.
* Free and zero the field.
*/
}
/* Check for EOC if expecting one */
- if (seq_eoc && !asn1_check_eoc(&p, len))
- {
+ if (seq_eoc && !asn1_check_eoc(&p, len)) {
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_MISSING_EOC);
goto err;
}
/* Check all data read */
- if (!seq_nolen && len)
- {
+ if (!seq_nolen && len) {
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
ASN1_R_SEQUENCE_LENGTH_MISMATCH);
goto err;
* however we may not have read all fields so check all
* remaining are OPTIONAL and clear any that are.
*/
- for (; i < it->tcount; tt++, i++)
- {
+ for (; i < it->tcount; tt++, i++) {
const ASN1_TEMPLATE *seqtt;
seqtt = asn1_do_adb(pval, tt, 1);
if (!seqtt)
goto err;
- if (seqtt->flags & ASN1_TFLG_OPTIONAL)
- {
+ if (seqtt->flags & ASN1_TFLG_OPTIONAL) {
ASN1_VALUE **pseqval;
pseqval = asn1_get_field_ptr(pval, seqtt);
ASN1_template_free(pseqval, seqtt);
- }
- else
- {
+ } else {
errtt = seqtt;
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
ASN1_R_FIELD_MISSING);
p = *in;
/* Check if EXPLICIT tag expected */
- if (flags & ASN1_TFLG_EXPTAG)
- {
+ if (flags & ASN1_TFLG_EXPTAG) {
char cst;
/* Need to work out amount of data available to the inner
* content and where it starts: so read in EXPLICIT header to
ret = asn1_check_tlen(&len, NULL, NULL, &exp_eoc, &cst,
&p, inlen, tt->tag, aclass, opt, ctx);
q = p;
- if (!ret)
- {
+ if (!ret) {
ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I,
ERR_R_NESTED_ASN1_ERROR);
return 0;
- }
- else if (ret == -1)
+ } else if (ret == -1)
return -1;
- if (!cst)
- {
+ if (!cst) {
ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I,
ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED);
return 0;
}
/* We've found the field so it can't be OPTIONAL now */
ret = asn1_template_noexp_d2i(val, &p, len, tt, 0, ctx);
- if (!ret)
- {
+ if (!ret) {
ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I,
ERR_R_NESTED_ASN1_ERROR);
return 0;
}
/* We read the field in OK so update length */
len -= p - q;
- if (exp_eoc)
- {
+ if (exp_eoc) {
/* If NDEF we must have an EOC here */
- if (!asn1_check_eoc(&p, len))
- {
+ if (!asn1_check_eoc(&p, len)) {
ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I,
ASN1_R_MISSING_EOC);
goto err;
}
- }
- else
- {
+ } else {
/* Otherwise we must hit the EXPLICIT tag end or its
* an error */
- if (len)
- {
+ if (len) {
ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I,
ASN1_R_EXPLICIT_LENGTH_MISMATCH);
goto err;
p = *in;
q = p;
- if (flags & ASN1_TFLG_SK_MASK)
- {
+ if (flags & ASN1_TFLG_SK_MASK) {
/* SET OF, SEQUENCE OF */
int sktag, skaclass;
char sk_eoc;
/* First work out expected inner tag value */
- if (flags & ASN1_TFLG_IMPTAG)
- {
+ if (flags & ASN1_TFLG_IMPTAG) {
sktag = tt->tag;
skaclass = aclass;
- }
- else
- {
+ } else {
skaclass = V_ASN1_UNIVERSAL;
if (flags & ASN1_TFLG_SET_OF)
sktag = V_ASN1_SET;
/* Get the tag */
ret = asn1_check_tlen(&len, NULL, NULL, &sk_eoc, NULL,
&p, len, sktag, skaclass, opt, ctx);
- if (!ret)
- {
+ if (!ret) {
ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
ERR_R_NESTED_ASN1_ERROR);
return 0;
return -1;
if (!*val)
*val = (ASN1_VALUE *)sk_new_null();
- else
- {
+ else {
/* We've got a valid STACK: free up any items present */
STACK_OF(ASN1_VALUE) *sktmp
= (STACK_OF(ASN1_VALUE) *)*val;
ASN1_VALUE *vtmp;
- while(sk_ASN1_VALUE_num(sktmp) > 0)
- {
+ while(sk_ASN1_VALUE_num(sktmp) > 0) {
vtmp = sk_ASN1_VALUE_pop(sktmp);
ASN1_item_ex_free(&vtmp,
ASN1_ITEM_ptr(tt->item));
}
}
- if (!*val)
- {
+ if (!*val) {
ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
ERR_R_MALLOC_FAILURE);
goto err;
}
/* Read as many items as we can */
- while(len > 0)
- {
+ while(len > 0) {
ASN1_VALUE *skfield;
q = p;
/* See if EOC found */
- if (asn1_check_eoc(&p, len))
- {
- if (!sk_eoc)
- {
+ if (asn1_check_eoc(&p, len)) {
+ if (!sk_eoc) {
ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
ASN1_R_UNEXPECTED_EOC);
goto err;
skfield = NULL;
if (!ASN1_item_ex_d2i(&skfield, &p, len,
ASN1_ITEM_ptr(tt->item),
- -1, 0, 0, ctx))
- {
+ -1, 0, 0, ctx)) {
ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
ERR_R_NESTED_ASN1_ERROR);
goto err;
}
len -= p - q;
if (!sk_ASN1_VALUE_push((STACK_OF(ASN1_VALUE) *)*val,
- skfield))
- {
+ skfield)) {
ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
ERR_R_MALLOC_FAILURE);
goto err;
}
}
- if (sk_eoc)
- {
+ if (sk_eoc) {
ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ASN1_R_MISSING_EOC);
goto err;
}
- }
- else if (flags & ASN1_TFLG_IMPTAG)
- {
+ } else if (flags & ASN1_TFLG_IMPTAG) {
/* IMPLICIT tagging */
ret = ASN1_item_ex_d2i(val, &p, len,
ASN1_ITEM_ptr(tt->item), tt->tag, aclass, opt, ctx);
- if (!ret)
- {
+ if (!ret) {
ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
ERR_R_NESTED_ASN1_ERROR);
goto err;
}
else if (ret == -1)
return -1;
- }
- else
- {
+ } else {
/* Nothing special */
ret = ASN1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item),
-1, 0, opt, ctx);
- if (!ret)
- {
+ if (!ret) {
ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
ERR_R_NESTED_ASN1_ERROR);
goto err;
BUF_MEM buf;
const unsigned char *cont = NULL;
long len;
- if (!pval)
- {
+ if (!pval) {
ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_ILLEGAL_NULL);
return 0; /* Should never happen */
}
- if (it->itype == ASN1_ITYPE_MSTRING)
- {
+ if (it->itype == ASN1_ITYPE_MSTRING) {
utype = tag;
tag = -1;
}
else
utype = it->utype;
- if (utype == V_ASN1_ANY)
- {
+ if (utype == V_ASN1_ANY) {
/* If type is ANY need to figure out type from tag */
unsigned char oclass;
- if (tag >= 0)
- {
+ if (tag >= 0) {
ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE,
ASN1_R_ILLEGAL_TAGGED_ANY);
return 0;
}
- if (opt)
- {
+ if (opt) {
ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE,
ASN1_R_ILLEGAL_OPTIONAL_ANY);
return 0;
p = *in;
ret = asn1_check_tlen(NULL, &utype, &oclass, NULL, NULL,
&p, inlen, -1, 0, 0, ctx);
- if (!ret)
- {
+ if (!ret) {
ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE,
ERR_R_NESTED_ASN1_ERROR);
return 0;
if (oclass != V_ASN1_UNIVERSAL)
utype = V_ASN1_OTHER;
}
- if (tag == -1)
- {
+ if (tag == -1) {
tag = utype;
aclass = V_ASN1_UNIVERSAL;
}
/* Check header */
ret = asn1_check_tlen(&plen, NULL, NULL, &inf, &cst,
&p, inlen, tag, aclass, opt, ctx);
- if (!ret)
- {
+ if (!ret) {
ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_NESTED_ASN1_ERROR);
return 0;
}
ret = 0;
/* SEQUENCE, SET and "OTHER" are left in encoded form */
if ((utype == V_ASN1_SEQUENCE)
- || (utype == V_ASN1_SET) || (utype == V_ASN1_OTHER))
- {
+ || (utype == V_ASN1_SET) || (utype == V_ASN1_OTHER)) {
/* Clear context cache for type OTHER because the auto clear
* when we have a exact match wont work
*/
- if (utype == V_ASN1_OTHER)
- {
+ if (utype == V_ASN1_OTHER) {
asn1_tlc_clear(ctx);
}
/* SEQUENCE and SET must be constructed */
- else if (!cst)
- {
+ else if (!cst) {
ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE,
ASN1_R_TYPE_NOT_CONSTRUCTED);
return 0;
cont = *in;
/* If indefinite length constructed find the real end */
- if (inf)
- {
+ if (inf) {
if (!asn1_find_end(&p, plen, inf))
goto err;
len = p - cont;
- }
- else
- {
+ } else {
len = p - cont + plen;
p += plen;
buf.data = NULL;
}
- }
- else if (cst)
- {
+ } else if (cst) {
buf.length = 0;
buf.max = 0;
buf.data = NULL;
* internally irrespective of the type. So instead just check
* for UNIVERSAL class and ignore the tag.
*/
- if (!asn1_collect(&buf, &p, plen, inf, -1, V_ASN1_UNIVERSAL, 0))
- {
+ if (!asn1_collect(&buf, &p, plen, inf, -1, V_ASN1_UNIVERSAL, 0)) {
free_cont = 1;
goto err;
}
len = buf.length;
/* Append a final null to string */
- if (!BUF_MEM_grow_clean(&buf, len + 1))
- {
+ if (!BUF_MEM_grow_clean(&buf, len + 1)) {
ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE,
ERR_R_MALLOC_FAILURE);
return 0;
buf.data[len] = 0;
cont = (const unsigned char *)buf.data;
free_cont = 1;
- }
- else
- {
+ } else {
cont = p;
len = plen;
p += plen;
if (pf && pf->prim_c2i)
return pf->prim_c2i(pval, cont, len, utype, free_cont, it);
/* If ANY type clear type and set pointer to internal value */
- if (it->utype == V_ASN1_ANY)
- {
- if (!*pval)
- {
+ if (it->utype == V_ASN1_ANY) {
+ if (!*pval) {
typ = ASN1_TYPE_new();
if (typ == NULL)
goto err;
opval = pval;
pval = &typ->value.asn1_value;
}
- switch(utype)
- {
- case V_ASN1_OBJECT:
+ switch(utype) {
+ case V_ASN1_OBJECT:
if (!c2i_ASN1_OBJECT((ASN1_OBJECT **)pval, &cont, len))
goto err;
break;
- case V_ASN1_NULL:
- if (len)
- {
+ case V_ASN1_NULL:
+ if (len) {
ASN1err(ASN1_F_ASN1_EX_C2I,
ASN1_R_NULL_IS_WRONG_LENGTH);
goto err;
*pval = (ASN1_VALUE *)1;
break;
- case V_ASN1_BOOLEAN:
- if (len != 1)
- {
+ case V_ASN1_BOOLEAN:
+ if (len != 1) {
ASN1err(ASN1_F_ASN1_EX_C2I,
ASN1_R_BOOLEAN_IS_WRONG_LENGTH);
goto err;
- }
- else
- {
+ } else {
ASN1_BOOLEAN *tbool;
tbool = (ASN1_BOOLEAN *)pval;
*tbool = *cont;
}
break;
- case V_ASN1_BIT_STRING:
+ case V_ASN1_BIT_STRING:
if (!c2i_ASN1_BIT_STRING((ASN1_BIT_STRING **)pval, &cont, len))
goto err;
break;
- case V_ASN1_INTEGER:
- case V_ASN1_NEG_INTEGER:
- case V_ASN1_ENUMERATED:
- case V_ASN1_NEG_ENUMERATED:
+ case V_ASN1_INTEGER:
+ case V_ASN1_NEG_INTEGER:
+ case V_ASN1_ENUMERATED:
+ case V_ASN1_NEG_ENUMERATED:
tint = (ASN1_INTEGER **)pval;
if (!c2i_ASN1_INTEGER(tint, &cont, len))
goto err;
(*tint)->type = utype | ((*tint)->type & V_ASN1_NEG);
break;
- case V_ASN1_OCTET_STRING:
- case V_ASN1_NUMERICSTRING:
- case V_ASN1_PRINTABLESTRING:
- case V_ASN1_T61STRING:
- case V_ASN1_VIDEOTEXSTRING:
- case V_ASN1_IA5STRING:
- case V_ASN1_UTCTIME:
- case V_ASN1_GENERALIZEDTIME:
- case V_ASN1_GRAPHICSTRING:
- case V_ASN1_VISIBLESTRING:
- case V_ASN1_GENERALSTRING:
- case V_ASN1_UNIVERSALSTRING:
- case V_ASN1_BMPSTRING:
- case V_ASN1_UTF8STRING:
- case V_ASN1_OTHER:
- case V_ASN1_SET:
- case V_ASN1_SEQUENCE:
- default:
- if (utype == V_ASN1_BMPSTRING && (len & 1))
- {
+ case V_ASN1_OCTET_STRING:
+ case V_ASN1_NUMERICSTRING:
+ case V_ASN1_PRINTABLESTRING:
+ case V_ASN1_T61STRING:
+ case V_ASN1_VIDEOTEXSTRING:
+ case V_ASN1_IA5STRING:
+ case V_ASN1_UTCTIME:
+ case V_ASN1_GENERALIZEDTIME:
+ case V_ASN1_GRAPHICSTRING:
+ case V_ASN1_VISIBLESTRING:
+ case V_ASN1_GENERALSTRING:
+ case V_ASN1_UNIVERSALSTRING:
+ case V_ASN1_BMPSTRING:
+ case V_ASN1_UTF8STRING:
+ case V_ASN1_OTHER:
+ case V_ASN1_SET:
+ case V_ASN1_SEQUENCE:
+ default:
+ if (utype == V_ASN1_BMPSTRING && (len & 1)) {
ASN1err(ASN1_F_ASN1_EX_C2I,
ASN1_R_BMPSTRING_IS_WRONG_LENGTH);
goto err;
}
- if (utype == V_ASN1_UNIVERSALSTRING && (len & 3))
- {
+ if (utype == V_ASN1_UNIVERSALSTRING && (len & 3)) {
ASN1err(ASN1_F_ASN1_EX_C2I,
ASN1_R_UNIVERSALSTRING_IS_WRONG_LENGTH);
goto err;
}
/* All based on ASN1_STRING and handled the same */
- if (!*pval)
- {
+ if (!*pval) {
stmp = ASN1_STRING_type_new(utype);
- if (!stmp)
- {
+ if (!stmp) {
ASN1err(ASN1_F_ASN1_EX_C2I,
ERR_R_MALLOC_FAILURE);
goto err;
}
*pval = (ASN1_VALUE *)stmp;
- }
- else
- {
+ } else {
stmp = (ASN1_STRING *)*pval;
stmp->type = utype;
}
/* If we've already allocated a buffer use it */
- if (*free_cont)
- {
+ if (*free_cont) {
if (stmp->data)
free(stmp->data);
stmp->data = (unsigned char *)cont; /* UGLY CAST! RL */
stmp->length = len;
*free_cont = 0;
- }
- else
- {
- if (!ASN1_STRING_set(stmp, cont, len))
- {
+ } else {
+ if (!ASN1_STRING_set(stmp, cont, len)) {
ASN1err(ASN1_F_ASN1_EX_C2I,
ERR_R_MALLOC_FAILURE);
ASN1_STRING_free(stmp);
ret = 1;
err:
- if (!ret)
- {
+ if (!ret) {
ASN1_TYPE_free(typ);
if (opval)
*opval = NULL;
long plen;
const unsigned char *p = *in, *q;
/* If not indefinite length constructed just add length */
- if (inf == 0)
- {
+ if (inf == 0) {
*in += len;
return 1;
}
* are encountered increment the expected eoc count otherwise just
* skip to the end of the data.
*/
- while (len > 0)
- {
- if(asn1_check_eoc(&p, len))
- {
+ while (len > 0) {
+ if(asn1_check_eoc(&p, len)) {
expected_eoc--;
if (expected_eoc == 0)
break;
q = p;
/* Just read in a header: only care about the length */
if(!asn1_check_tlen(&plen, NULL, NULL, &inf, NULL, &p, len,
- -1, 0, 0, NULL))
- {
+ -1, 0, 0, NULL)) {
ASN1err(ASN1_F_ASN1_FIND_END, ERR_R_NESTED_ASN1_ERROR);
return 0;
}
p += plen;
len -= p - q;
}
- if (expected_eoc)
- {
+ if (expected_eoc) {
ASN1err(ASN1_F_ASN1_FIND_END, ASN1_R_MISSING_EOC);
return 0;
}
inf &= 1;
/* If no buffer and not indefinite length constructed just pass over
* the encoded data */
- if (!buf && !inf)
- {
+ if (!buf && !inf) {
*in += len;
return 1;
}
- while(len > 0)
- {
+ while(len > 0) {
q = p;
/* Check for EOC */
- if (asn1_check_eoc(&p, len))
- {
+ if (asn1_check_eoc(&p, len)) {
/* EOC is illegal outside indefinite length
* constructed form */
- if (!inf)
- {
+ if (!inf) {
ASN1err(ASN1_F_ASN1_COLLECT,
ASN1_R_UNEXPECTED_EOC);
return 0;
}
if (!asn1_check_tlen(&plen, NULL, NULL, &ininf, &cst, &p,
- len, tag, aclass, 0, NULL))
- {
+ len, tag, aclass, 0, NULL)) {
ASN1err(ASN1_F_ASN1_COLLECT, ERR_R_NESTED_ASN1_ERROR);
return 0;
}
/* If indefinite length constructed update max length */
- if (cst)
- {
- if (depth >= ASN1_MAX_STRING_NEST)
- {
+ if (cst) {
+ if (depth >= ASN1_MAX_STRING_NEST) {
ASN1err(ASN1_F_ASN1_COLLECT,
ASN1_R_NESTED_ASN1_STRING);
return 0;
return 0;
len -= p - q;
}
- if (inf)
- {
+ if (inf) {
ASN1err(ASN1_F_ASN1_COLLECT, ASN1_R_MISSING_EOC);
return 0;
}
static int collect_data(BUF_MEM *buf, const unsigned char **p, long plen)
{
int len;
- if (buf)
- {
+ if (buf) {
len = buf->length;
- if (!BUF_MEM_grow_clean(buf, len + plen))
- {
+ if (!BUF_MEM_grow_clean(buf, len + plen)) {
ASN1err(ASN1_F_COLLECT_DATA, ERR_R_MALLOC_FAILURE);
return 0;
}
const unsigned char *p;
if (len < 2) return 0;
p = *in;
- if (!p[0] && !p[1])
- {
+ if (!p[0] && !p[1]) {
*in += 2;
return 1;
}
p = *in;
q = p;
- if (ctx && ctx->valid)
- {
+ if (ctx && ctx->valid) {
i = ctx->ret;
plen = ctx->plen;
pclass = ctx->pclass;
ptag = ctx->ptag;
p += ctx->hdrlen;
- }
- else
- {
+ } else {
i = ASN1_get_object(&p, &plen, &ptag, &pclass, len);
- if (ctx)
- {
+ if (ctx) {
ctx->ret = i;
ctx->plen = plen;
ctx->pclass = pclass;
/* If definite length, and no error, length +
* header can't exceed total amount of data available.
*/
- if (!(i & 0x81) && ((plen + ctx->hdrlen) > len))
- {
+ if (!(i & 0x81) && ((plen + ctx->hdrlen) > len)) {
ASN1err(ASN1_F_ASN1_CHECK_TLEN,
ASN1_R_TOO_LONG);
asn1_tlc_clear(ctx);
}
}
- if (i & 0x80)
- {
+ if (i & 0x80) {
ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_BAD_OBJECT_HEADER);
asn1_tlc_clear(ctx);
return 0;
}
- if (exptag >= 0)
- {
- if ((exptag != ptag) || (expclass != pclass))
- {
+ if (exptag >= 0) {
+ if ((exptag != ptag) || (expclass != pclass)) {
/* If type is OPTIONAL, not an error:
* indicate missing type.
*/
static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out,
const ASN1_ITEM *it, int flags)
{
- if (out && !*out)
- {
+ if (out && !*out) {
unsigned char *p, *buf;
int len;
len = ASN1_item_ex_i2d(&val, NULL, it, -1, flags);
if (aux && aux->asn1_cb)
asn1_cb = aux->asn1_cb;
- switch(it->itype)
- {
+ switch(it->itype) {
- case ASN1_ITYPE_PRIMITIVE:
+ case ASN1_ITYPE_PRIMITIVE:
if (it->templates)
return asn1_template_ex_i2d(pval, out, it->templates,
tag, aclass);
return asn1_i2d_ex_primitive(pval, out, it, tag, aclass);
break;
- case ASN1_ITYPE_MSTRING:
+ case ASN1_ITYPE_MSTRING:
return asn1_i2d_ex_primitive(pval, out, it, -1, aclass);
- case ASN1_ITYPE_CHOICE:
+ case ASN1_ITYPE_CHOICE:
if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL))
return 0;
i = asn1_get_choice_selector(pval, it);
- if ((i >= 0) && (i < it->tcount))
- {
+ if ((i >= 0) && (i < it->tcount)) {
ASN1_VALUE **pchval;
const ASN1_TEMPLATE *chtt;
chtt = it->templates + i;
return 0;
break;
- case ASN1_ITYPE_EXTERN:
+ case ASN1_ITYPE_EXTERN:
/* If new style i2d it does all the work */
ef = it->funcs;
return ef->asn1_ex_i2d(pval, out, it, tag, aclass);
- case ASN1_ITYPE_COMPAT:
+ case ASN1_ITYPE_COMPAT:
/* old style hackery... */
cf = it->funcs;
if (out)
*p = aclass | tag | (*p & V_ASN1_CONSTRUCTED);
return i;
- case ASN1_ITYPE_NDEF_SEQUENCE:
+ case ASN1_ITYPE_NDEF_SEQUENCE:
/* Use indefinite length constructed if requested */
if (aclass & ASN1_TFLG_NDEF) ndef = 2;
/* fall through */
- case ASN1_ITYPE_SEQUENCE:
+ case ASN1_ITYPE_SEQUENCE:
i = asn1_enc_restore(&seqcontlen, out, pval, it);
/* An error occurred */
if (i < 0)
/* Otherwise carry on */
seqcontlen = 0;
/* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */
- if (tag == -1)
- {
+ if (tag == -1) {
tag = V_ASN1_SEQUENCE;
/* Retain any other flags in aclass */
aclass = (aclass & ~ASN1_TFLG_TAG_CLASS)
if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL))
return 0;
/* First work out sequence content length */
- for (i = 0, tt = it->templates; i < it->tcount; tt++, i++)
- {
+ for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
const ASN1_TEMPLATE *seqtt;
ASN1_VALUE **pseqval;
seqtt = asn1_do_adb(pval, tt, 1);
return seqlen;
/* Output SEQUENCE header */
ASN1_put_object(out, ndef, seqcontlen, tag, aclass);
- for (i = 0, tt = it->templates; i < it->tcount; tt++, i++)
- {
+ for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
const ASN1_TEMPLATE *seqtt;
ASN1_VALUE **pseqval;
seqtt = asn1_do_adb(pval, tt, 1);
* the iclass argument may contain some additional flags
* which should be noted and passed down to other levels.
*/
- if (flags & ASN1_TFLG_TAG_MASK)
- {
+ if (flags & ASN1_TFLG_TAG_MASK) {
/* Error if argument and template tagging */
if (tag != -1)
/* FIXME: error code here */
/* Get tagging from template */
ttag = tt->tag;
tclass = flags & ASN1_TFLG_TAG_CLASS;
- }
- else if (tag != -1)
- {
+ } else if (tag != -1) {
/* No template tagging, get from arguments */
ttag = tag;
tclass = iclass & ASN1_TFLG_TAG_CLASS;
- }
- else
- {
+ } else {
ttag = -1;
tclass = 0;
}
ndef = 2;
else ndef = 1;
- if (flags & ASN1_TFLG_SK_MASK)
- {
+ if (flags & ASN1_TFLG_SK_MASK) {
/* SET OF, SEQUENCE OF */
STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval;
int isset, sktag, skaclass;
if (!*pval)
return 0;
- if (flags & ASN1_TFLG_SET_OF)
- {
+ if (flags & ASN1_TFLG_SET_OF) {
isset = 1;
/* 2 means we reorder */
if (flags & ASN1_TFLG_SEQUENCE_OF)
/* Work out inner tag value: if EXPLICIT
* or no tagging use underlying type.
*/
- if ((ttag != -1) && !(flags & ASN1_TFLG_EXPTAG))
- {
+ if ((ttag != -1) && !(flags & ASN1_TFLG_EXPTAG)) {
sktag = ttag;
skaclass = tclass;
- }
- else
- {
+ } else {
skaclass = V_ASN1_UNIVERSAL;
if (isset)
sktag = V_ASN1_SET;
/* Determine total length of items */
skcontlen = 0;
- for (i = 0; i < sk_ASN1_VALUE_num(sk); i++)
- {
+ for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
skitem = sk_ASN1_VALUE_value(sk, i);
skcontlen += ASN1_item_ex_i2d(&skitem, NULL,
ASN1_ITEM_ptr(tt->item),
/* And the stuff itself */
asn1_set_seq_out(sk, out, skcontlen, ASN1_ITEM_ptr(tt->item),
isset, iclass);
- if (ndef == 2)
- {
+ if (ndef == 2) {
ASN1_put_eoc(out);
if (flags & ASN1_TFLG_EXPTAG)
ASN1_put_eoc(out);
return ret;
}
- if (flags & ASN1_TFLG_EXPTAG)
- {
+ if (flags & ASN1_TFLG_EXPTAG) {
/* EXPLICIT tagging */
/* Find length of tagged item */
i = ASN1_item_ex_i2d(pval, NULL, ASN1_ITEM_ptr(tt->item),
return 0;
/* Find length of EXPLICIT tag */
ret = ASN1_object_size(ndef, i, ttag);
- if (out)
- {
+ if (out) {
/* Output tag and item */
ASN1_put_object(out, ndef, i, ttag, tclass);
ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item),
/* Don't need to sort less than 2 items */
if (sk_ASN1_VALUE_num(sk) < 2)
do_sort = 0;
- else
- {
+ else {
derlst = malloc(sk_ASN1_VALUE_num(sk)
* sizeof(*derlst));
tmpdat = malloc(skcontlen);
}
}
/* If not sorting just output each item */
- if (!do_sort)
- {
- for (i = 0; i < sk_ASN1_VALUE_num(sk); i++)
- {
+ if (!do_sort) {
+ for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
skitem = sk_ASN1_VALUE_value(sk, i);
ASN1_item_ex_i2d(&skitem, out, item, -1, iclass);
}
p = tmpdat;
/* Doing sort: build up a list of each member's DER encoding */
- for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++)
- {
+ for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) {
skitem = sk_ASN1_VALUE_value(sk, i);
tder->data = p;
tder->length = ASN1_item_ex_i2d(&skitem, &p, item, -1, iclass);
qsort(derlst, sk_ASN1_VALUE_num(sk), sizeof(*derlst), der_cmp);
/* Output sorted DER encoding */
p = *out;
- for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++)
- {
+ for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) {
memcpy(p, tder->data, tder->length);
p += tder->length;
}
*out = p;
/* If do_sort is 2 then reorder the STACK */
- if (do_sort == 2)
- {
- for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk);
- i++, tder++)
+ if (do_sort == 2) {
+ for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++)
(void)sk_ASN1_VALUE_set(sk, i, tder->field);
}
free(derlst);
return 0;
/* -2 return is special meaning use ndef */
- if (len == -2)
- {
+ if (len == -2) {
ndef = 2;
len = 0;
}
if (tag == -1) tag = utype;
/* Output tag+length followed by content octets */
- if (out)
- {
+ if (out) {
if (usetag)
ASN1_put_object(out, ndef, len, tag, aclass);
asn1_ex_i2c(pval, *out, &utype, it);
return pf->prim_i2c(pval, cout, putype, it);
/* Should type be omitted? */
- if ((it->itype != ASN1_ITYPE_PRIMITIVE)
- || (it->utype != V_ASN1_BOOLEAN))
- {
+ if ((it->itype != ASN1_ITYPE_PRIMITIVE) || (it->utype != V_ASN1_BOOLEAN)) {
if (!*pval) return -1;
}
- if (it->itype == ASN1_ITYPE_MSTRING)
- {
+ if (it->itype == ASN1_ITYPE_MSTRING) {
/* If MSTRING type set the underlying type */
strtmp = (ASN1_STRING *)*pval;
utype = strtmp->type;
*putype = utype;
- }
- else if (it->utype == V_ASN1_ANY)
- {
+ } else if (it->utype == V_ASN1_ANY) {
/* If ANY set type and pointer to value */
ASN1_TYPE *typ;
typ = (ASN1_TYPE *)*pval;
}
else utype = *putype;
- switch(utype)
- {
- case V_ASN1_OBJECT:
+ switch(utype) {
+ case V_ASN1_OBJECT:
otmp = (ASN1_OBJECT *)*pval;
cont = otmp->data;
len = otmp->length;
break;
- case V_ASN1_NULL:
+ case V_ASN1_NULL:
cont = NULL;
len = 0;
break;
- case V_ASN1_BOOLEAN:
+ case V_ASN1_BOOLEAN:
tbool = (ASN1_BOOLEAN *)pval;
if (*tbool == -1)
return -1;
- if (it->utype != V_ASN1_ANY)
- {
+ if (it->utype != V_ASN1_ANY) {
/* Default handling if value == size field then omit */
if (*tbool && (it->size > 0))
return -1;
len = 1;
break;
- case V_ASN1_BIT_STRING:
+ case V_ASN1_BIT_STRING:
return i2c_ASN1_BIT_STRING((ASN1_BIT_STRING *)*pval,
cout ? &cout : NULL);
break;
- case V_ASN1_INTEGER:
- case V_ASN1_NEG_INTEGER:
- case V_ASN1_ENUMERATED:
- case V_ASN1_NEG_ENUMERATED:
+ case V_ASN1_INTEGER:
+ case V_ASN1_NEG_INTEGER:
+ case V_ASN1_ENUMERATED:
+ case V_ASN1_NEG_ENUMERATED:
/* These are all have the same content format
* as ASN1_INTEGER
*/
cout ? &cout : NULL);
break;
- case V_ASN1_OCTET_STRING:
- case V_ASN1_NUMERICSTRING:
- case V_ASN1_PRINTABLESTRING:
- case V_ASN1_T61STRING:
- case V_ASN1_VIDEOTEXSTRING:
- case V_ASN1_IA5STRING:
- case V_ASN1_UTCTIME:
- case V_ASN1_GENERALIZEDTIME:
- case V_ASN1_GRAPHICSTRING:
- case V_ASN1_VISIBLESTRING:
- case V_ASN1_GENERALSTRING:
- case V_ASN1_UNIVERSALSTRING:
- case V_ASN1_BMPSTRING:
- case V_ASN1_UTF8STRING:
- case V_ASN1_SEQUENCE:
- case V_ASN1_SET:
- default:
+ case V_ASN1_OCTET_STRING:
+ case V_ASN1_NUMERICSTRING:
+ case V_ASN1_PRINTABLESTRING:
+ case V_ASN1_T61STRING:
+ case V_ASN1_VIDEOTEXSTRING:
+ case V_ASN1_IA5STRING:
+ case V_ASN1_UTCTIME:
+ case V_ASN1_GENERALIZEDTIME:
+ case V_ASN1_GRAPHICSTRING:
+ case V_ASN1_VISIBLESTRING:
+ case V_ASN1_GENERALSTRING:
+ case V_ASN1_UNIVERSALSTRING:
+ case V_ASN1_BMPSTRING:
+ case V_ASN1_UTF8STRING:
+ case V_ASN1_SEQUENCE:
+ case V_ASN1_SET:
+ default:
/* All based on ASN1_STRING and handled the same */
strtmp = (ASN1_STRING *)*pval;
/* Special handling for NDEF */
if ((it->size == ASN1_TFLG_NDEF)
- && (strtmp->flags & ASN1_STRING_FLAG_NDEF))
- {
- if (cout)
- {
+ && (strtmp->flags & ASN1_STRING_FLAG_NDEF)) {
+ if (cout) {
strtmp->data = cout;
strtmp->length = 0;
}
else
asn1_cb = 0;
- switch(it->itype)
- {
+ switch(it->itype) {
- case ASN1_ITYPE_PRIMITIVE:
+ case ASN1_ITYPE_PRIMITIVE:
if (it->templates)
ASN1_template_free(pval, it->templates);
else
ASN1_primitive_free(pval, it);
break;
- case ASN1_ITYPE_MSTRING:
+ case ASN1_ITYPE_MSTRING:
ASN1_primitive_free(pval, it);
break;
- case ASN1_ITYPE_CHOICE:
- if (asn1_cb)
- {
+ case ASN1_ITYPE_CHOICE:
+ if (asn1_cb) {
i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL);
if (i == 2)
return;
}
i = asn1_get_choice_selector(pval, it);
- if ((i >= 0) && (i < it->tcount))
- {
+ if ((i >= 0) && (i < it->tcount)) {
ASN1_VALUE **pchval;
tt = it->templates + i;
pchval = asn1_get_field_ptr(pval, tt);
}
if (asn1_cb)
asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL);
- if (!combine)
- {
+ if (!combine) {
free(*pval);
*pval = NULL;
}
break;
- case ASN1_ITYPE_COMPAT:
+ case ASN1_ITYPE_COMPAT:
cf = it->funcs;
if (cf && cf->asn1_free)
cf->asn1_free(*pval);
break;
- case ASN1_ITYPE_EXTERN:
+ case ASN1_ITYPE_EXTERN:
ef = it->funcs;
if (ef && ef->asn1_ex_free)
ef->asn1_ex_free(pval, it);
break;
- case ASN1_ITYPE_NDEF_SEQUENCE:
- case ASN1_ITYPE_SEQUENCE:
+ case ASN1_ITYPE_NDEF_SEQUENCE:
+ case ASN1_ITYPE_SEQUENCE:
if (asn1_do_lock(pval, -1, it) > 0)
return;
- if (asn1_cb)
- {
+ if (asn1_cb) {
i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL);
if (i == 2)
return;
* free up in reverse order.
*/
tt = it->templates + it->tcount - 1;
- for (i = 0; i < it->tcount; tt--, i++)
- {
+ for (i = 0; i < it->tcount; tt--, i++) {
ASN1_VALUE **pseqval;
seqtt = asn1_do_adb(pval, tt, 0);
if (!seqtt)
}
if (asn1_cb)
asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL);
- if (!combine)
- {
+ if (!combine) {
free(*pval);
*pval = NULL;
}
void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
{
int i;
- if (tt->flags & ASN1_TFLG_SK_MASK)
- {
+ if (tt->flags & ASN1_TFLG_SK_MASK) {
STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval;
- for (i = 0; i < sk_ASN1_VALUE_num(sk); i++)
- {
+ for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
ASN1_VALUE *vtmp;
vtmp = sk_ASN1_VALUE_value(sk, i);
asn1_item_combine_free(&vtmp, ASN1_ITEM_ptr(tt->item),
void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
{
int utype;
- if (it)
- {
+ if (it) {
const ASN1_PRIMITIVE_FUNCS *pf;
pf = it->funcs;
- if (pf && pf->prim_free)
- {
+ if (pf && pf->prim_free) {
pf->prim_free(pval, it);
return;
}
}
/* Special case: if 'it' is NULL free contents of ASN1_TYPE */
- if (!it)
- {
+ if (!it) {
ASN1_TYPE *typ = (ASN1_TYPE *)*pval;
utype = typ->type;
pval = &typ->value.asn1_value;
if (!*pval)
return;
- }
- else if (it->itype == ASN1_ITYPE_MSTRING)
- {
+ } else if (it->itype == ASN1_ITYPE_MSTRING) {
utype = -1;
if (!*pval)
return;
- }
- else
- {
+ } else {
utype = it->utype;
if ((utype != V_ASN1_BOOLEAN) && !*pval)
return;
}
- switch(utype)
- {
- case V_ASN1_OBJECT:
+ switch(utype) {
+ case V_ASN1_OBJECT:
ASN1_OBJECT_free((ASN1_OBJECT *)*pval);
break;
- case V_ASN1_BOOLEAN:
+ case V_ASN1_BOOLEAN:
if (it)
*(ASN1_BOOLEAN *)pval = it->size;
else
*(ASN1_BOOLEAN *)pval = -1;
return;
- case V_ASN1_NULL:
+ case V_ASN1_NULL:
break;
- case V_ASN1_ANY:
+ case V_ASN1_ANY:
ASN1_primitive_free(pval, NULL);
free(*pval);
break;
- default:
+ default:
ASN1_STRING_free((ASN1_STRING *)*pval);
*pval = NULL;
break;
CRYPTO_push_info(it->sname);
#endif
- switch(it->itype)
- {
+ switch(it->itype) {
- case ASN1_ITYPE_EXTERN:
+ case ASN1_ITYPE_EXTERN:
ef = it->funcs;
- if (ef && ef->asn1_ex_new)
- {
+ if (ef && ef->asn1_ex_new) {
if (!ef->asn1_ex_new(pval, it))
goto memerr;
}
break;
- case ASN1_ITYPE_COMPAT:
+ case ASN1_ITYPE_COMPAT:
cf = it->funcs;
if (cf && cf->asn1_new) {
*pval = cf->asn1_new();
if (!*pval)
goto memerr;
- }
+ }
break;
- case ASN1_ITYPE_PRIMITIVE:
- if (it->templates)
- {
+ case ASN1_ITYPE_PRIMITIVE:
+ if (it->templates) {
if (!ASN1_template_new(pval, it->templates))
goto memerr;
}
goto memerr;
break;
- case ASN1_ITYPE_MSTRING:
+ case ASN1_ITYPE_MSTRING:
if (!ASN1_primitive_new(pval, it))
goto memerr;
break;
- case ASN1_ITYPE_CHOICE:
- if (asn1_cb)
- {
+ case ASN1_ITYPE_CHOICE:
+ if (asn1_cb) {
i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL);
if (!i)
goto auxerr;
- if (i==2)
- {
+ if (i==2) {
#ifdef CRYPTO_MDEBUG
if (it->sname)
CRYPTO_pop_info();
return 1;
}
}
- if (!combine)
- {
+ if (!combine) {
*pval = malloc(it->size);
if (!*pval)
goto memerr;
goto auxerr;
break;
- case ASN1_ITYPE_NDEF_SEQUENCE:
- case ASN1_ITYPE_SEQUENCE:
- if (asn1_cb)
- {
+ case ASN1_ITYPE_NDEF_SEQUENCE:
+ case ASN1_ITYPE_SEQUENCE:
+ if (asn1_cb) {
i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL);
if (!i)
goto auxerr;
- if (i==2)
- {
+ if (i==2) {
#ifdef CRYPTO_MDEBUG
if (it->sname)
CRYPTO_pop_info();
return 1;
}
}
- if (!combine)
- {
+ if (!combine) {
*pval = malloc(it->size);
if (!*pval)
goto memerr;
asn1_do_lock(pval, 0, it);
asn1_enc_init(pval, it);
}
- for (i = 0, tt = it->templates; i < it->tcount; tt++, i++)
- {
+ for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
pseqval = asn1_get_field_ptr(pval, tt);
if (!ASN1_template_new(pseqval, tt))
goto memerr;
{
const ASN1_EXTERN_FUNCS *ef;
- switch(it->itype)
- {
+ switch(it->itype) {
- case ASN1_ITYPE_EXTERN:
+ case ASN1_ITYPE_EXTERN:
ef = it->funcs;
if (ef && ef->asn1_ex_clear)
ef->asn1_ex_clear(pval, it);
break;
- case ASN1_ITYPE_PRIMITIVE:
+ case ASN1_ITYPE_PRIMITIVE:
if (it->templates)
asn1_template_clear(pval, it->templates);
else
asn1_primitive_clear(pval, it);
break;
- case ASN1_ITYPE_MSTRING:
+ case ASN1_ITYPE_MSTRING:
asn1_primitive_clear(pval, it);
break;
- case ASN1_ITYPE_COMPAT:
- case ASN1_ITYPE_CHOICE:
- case ASN1_ITYPE_SEQUENCE:
- case ASN1_ITYPE_NDEF_SEQUENCE:
+ case ASN1_ITYPE_COMPAT:
+ case ASN1_ITYPE_CHOICE:
+ case ASN1_ITYPE_SEQUENCE:
+ case ASN1_ITYPE_NDEF_SEQUENCE:
*pval = NULL;
break;
}
{
const ASN1_ITEM *it = ASN1_ITEM_ptr(tt->item);
int ret;
- if (tt->flags & ASN1_TFLG_OPTIONAL)
- {
+ if (tt->flags & ASN1_TFLG_OPTIONAL) {
asn1_template_clear(pval, tt);
return 1;
}
/* If ANY DEFINED BY nothing to do */
- if (tt->flags & ASN1_TFLG_ADB_MASK)
- {
+ if (tt->flags & ASN1_TFLG_ADB_MASK) {
*pval = NULL;
return 1;
}
CRYPTO_push_info(tt->field_name);
#endif
/* If SET OF or SEQUENCE OF, its a STACK */
- if (tt->flags & ASN1_TFLG_SK_MASK)
- {
+ if (tt->flags & ASN1_TFLG_SK_MASK) {
STACK_OF(ASN1_VALUE) *skval;
skval = sk_ASN1_VALUE_new_null();
- if (!skval)
- {
+ if (!skval) {
ASN1err(ASN1_F_ASN1_TEMPLATE_NEW, ERR_R_MALLOC_FAILURE);
ret = 0;
goto done;
ASN1_STRING *str;
int utype;
- if (it && it->funcs)
- {
+ if (it && it->funcs) {
const ASN1_PRIMITIVE_FUNCS *pf = it->funcs;
if (pf->prim_new)
return pf->prim_new(pval, it);
utype = -1;
else
utype = it->utype;
- switch(utype)
- {
- case V_ASN1_OBJECT:
+ switch(utype) {
+ case V_ASN1_OBJECT:
*pval = (ASN1_VALUE *)OBJ_nid2obj(NID_undef);
return 1;
- case V_ASN1_BOOLEAN:
+ case V_ASN1_BOOLEAN:
*(ASN1_BOOLEAN *)pval = it->size;
return 1;
- case V_ASN1_NULL:
+ case V_ASN1_NULL:
*pval = (ASN1_VALUE *)1;
return 1;
- case V_ASN1_ANY:
+ case V_ASN1_ANY:
typ = malloc(sizeof(ASN1_TYPE));
if (!typ)
return 0;
*pval = (ASN1_VALUE *)typ;
break;
- default:
+ default:
str = ASN1_STRING_type_new(utype);
if (it->itype == ASN1_ITYPE_MSTRING && str)
str->flags |= ASN1_STRING_FLAG_MSTRING;
static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
{
int utype;
- if (it && it->funcs)
- {
+ if (it && it->funcs) {
const ASN1_PRIMITIVE_FUNCS *pf = it->funcs;
if (pf->prim_clear)
pf->prim_clear(pval, it);
{
ASN1_PCTX *ret;
ret = malloc(sizeof(ASN1_PCTX));
- if (ret == NULL)
- {
+ if (ret == NULL) {
ASN1err(ASN1_F_ASN1_PCTX_NEW, ERR_R_MALLOC_FAILURE);
return NULL;
}
ASN1_aux_cb *asn1_cb;
ASN1_PRINT_ARG parg;
int i;
- if (aux && aux->asn1_cb)
- {
+ if (aux && aux->asn1_cb) {
parg.out = out;
parg.indent = indent;
parg.pctx = pctx;
}
else asn1_cb = 0;
- if(*fld == NULL)
- {
- if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_ABSENT)
- {
+ if(*fld == NULL) {
+ if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_ABSENT) {
if (!nohdr && !asn1_print_fsname(out, indent,
fname, sname, pctx))
return 0;
return 1;
}
- switch(it->itype)
- {
- case ASN1_ITYPE_PRIMITIVE:
- if(it->templates)
- {
+ switch(it->itype) {
+ case ASN1_ITYPE_PRIMITIVE:
+ if(it->templates) {
if (!asn1_template_print_ctx(out, fld, indent,
it->templates, pctx))
return 0;
}
/* fall thru */
- case ASN1_ITYPE_MSTRING:
+ case ASN1_ITYPE_MSTRING:
if (!asn1_primitive_print(out, fld, it,
indent, fname, sname,pctx))
return 0;
break;
- case ASN1_ITYPE_EXTERN:
+ case ASN1_ITYPE_EXTERN:
if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx))
return 0;
/* Use new style print routine if possible */
ef = it->funcs;
- if (ef && ef->asn1_ex_print)
- {
+ if (ef && ef->asn1_ex_print) {
i = ef->asn1_ex_print(out, fld, indent, "", pctx);
if (!i)
return 0;
return 0;
break;
- case ASN1_ITYPE_CHOICE:
+ case ASN1_ITYPE_CHOICE:
#if 0
if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx))
return 0;
/* CHOICE type, get selector */
i = asn1_get_choice_selector(fld, it);
/* This should never happen... */
- if((i < 0) || (i >= it->tcount))
- {
+ if((i < 0) || (i >= it->tcount)) {
if (BIO_printf(out,
"ERROR: selector [%d] invalid\n", i) <= 0)
return 0;
return 0;
break;
- case ASN1_ITYPE_SEQUENCE:
- case ASN1_ITYPE_NDEF_SEQUENCE:
+ case ASN1_ITYPE_SEQUENCE:
+ case ASN1_ITYPE_NDEF_SEQUENCE:
if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx))
return 0;
- if (fname || sname)
- {
- if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE)
- {
+ if (fname || sname) {
+ if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) {
if (BIO_puts(out, " {\n") <= 0)
return 0;
- }
- else
- {
+ } else {
if (BIO_puts(out, "\n") <= 0)
return 0;
}
}
- if (asn1_cb)
- {
+ if (asn1_cb) {
i = asn1_cb(ASN1_OP_PRINT_PRE, fld, it, &parg);
if (i == 0)
return 0;
}
/* Print each field entry */
- for(i = 0, tt = it->templates; i < it->tcount; i++, tt++)
- {
+ for(i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
const ASN1_TEMPLATE *seqtt;
seqtt = asn1_do_adb(fld, tt, 1);
tmpfld = asn1_get_field_ptr(fld, seqtt);
indent + 2, seqtt, pctx))
return 0;
}
- if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE)
- {
+ if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) {
if (BIO_printf(out, "%*s}\n", indent, "") < 0)
return 0;
}
- if (asn1_cb)
- {
+ if (asn1_cb) {
i = asn1_cb(ASN1_OP_PRINT_POST, fld, it, &parg);
if (i == 0)
return 0;
fname = NULL;
else
fname = tt->field_name;
- if(flags & ASN1_TFLG_SK_MASK)
- {
+ if(flags & ASN1_TFLG_SK_MASK) {
char *tname;
ASN1_VALUE *skitem;
STACK_OF(ASN1_VALUE) *stack;
/* SET OF, SEQUENCE OF */
- if (fname)
- {
- if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_SSOF)
- {
+ if (fname) {
+ if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_SSOF) {
if(flags & ASN1_TFLG_SET_OF)
tname = "SET";
else
return 0;
}
stack = (STACK_OF(ASN1_VALUE) *)*fld;
- for(i = 0; i < sk_ASN1_VALUE_num(stack); i++)
- {
+ for(i = 0; i < sk_ASN1_VALUE_num(stack); i++) {
if ((i > 0) && (BIO_puts(out, "\n") <= 0))
return 0;
}
if (!i && BIO_printf(out, "%*s<EMPTY>\n", indent + 2, "") <= 0)
return 0;
- if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE)
- {
+ if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) {
if (BIO_printf(out, "%*s}\n", indent, "") <= 0)
return 0;
}
return 1;
#endif
- while (indent > nspaces)
- {
+ while (indent > nspaces) {
if (BIO_write(out, spaces, nspaces) != nspaces)
return 0;
indent -= nspaces;
fname = NULL;
if (!sname && !fname)
return 1;
- if (fname)
- {
+ if (fname) {
if (BIO_puts(out, fname) <= 0)
return 0;
}
- if (sname)
- {
- if (fname)
- {
+ if (sname) {
+ if (fname) {
if (BIO_printf(out, " (%s)", sname) <= 0)
return 0;
- }
- else
- {
+ } else {
if (BIO_puts(out, sname) <= 0)
return 0;
}
const ASN1_PCTX *pctx)
{
const char *str;
- switch (boolval)
- {
- case -1:
+ switch (boolval) {
+ case -1:
str = "BOOL ABSENT";
break;
- case 0:
+ case 0:
str = "FALSE";
break;
static int asn1_print_obstring_ctx(BIO *out, ASN1_STRING *str, int indent,
const ASN1_PCTX *pctx)
{
- if (str->type == V_ASN1_BIT_STRING)
- {
+ if (str->type == V_ASN1_BIT_STRING) {
if (BIO_printf(out, " (%ld unused bits)\n",
str->flags & 0x7) <= 0)
return 0;
utype = str->type & ~V_ASN1_NEG;
else
utype = it->utype;
- if (utype == V_ASN1_ANY)
- {
+ if (utype == V_ASN1_ANY) {
ASN1_TYPE *atype = (ASN1_TYPE *)*fld;
utype = atype->type;
fld = &atype->value.asn1_value;
pname = NULL;
else
pname = ASN1_tag2str(utype);
- }
- else
- {
+ } else {
if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_TYPE)
pname = ASN1_tag2str(utype);
else
pname = NULL;
}
- if (utype == V_ASN1_NULL)
- {
+ if (utype == V_ASN1_NULL) {
if (BIO_puts(out, "NULL\n") <= 0)
return 0;
return 1;
}
- if (pname)
- {
+ if (pname) {
if (BIO_puts(out, pname) <= 0)
return 0;
if (BIO_puts(out, ":") <= 0)
return 0;
}
- switch (utype)
- {
- case V_ASN1_BOOLEAN:
+ switch (utype) {
+ case V_ASN1_BOOLEAN:
{
int boolval = *(int *)fld;
if (boolval == -1)
}
break;
- case V_ASN1_INTEGER:
- case V_ASN1_ENUMERATED:
+ case V_ASN1_INTEGER:
+ case V_ASN1_ENUMERATED:
ret = asn1_print_integer_ctx(out, str, pctx);
break;
- case V_ASN1_UTCTIME:
+ case V_ASN1_UTCTIME:
ret = ASN1_UTCTIME_print(out, str);
break;
- case V_ASN1_GENERALIZEDTIME:
+ case V_ASN1_GENERALIZEDTIME:
ret = ASN1_GENERALIZEDTIME_print(out, str);
break;
- case V_ASN1_OBJECT:
+ case V_ASN1_OBJECT:
ret = asn1_print_oid_ctx(out, (const ASN1_OBJECT *)*fld, pctx);
break;
- case V_ASN1_OCTET_STRING:
- case V_ASN1_BIT_STRING:
+ case V_ASN1_OCTET_STRING:
+ case V_ASN1_BIT_STRING:
ret = asn1_print_obstring_ctx(out, str, indent, pctx);
needlf = 0;
break;
- case V_ASN1_SEQUENCE:
- case V_ASN1_SET:
- case V_ASN1_OTHER:
+ case V_ASN1_SEQUENCE:
+ case V_ASN1_SET:
+ case V_ASN1_OTHER:
if (BIO_puts(out, "\n") <= 0)
return 0;
if (ASN1_parse_dump(out, str->data, str->length,
needlf = 0;
break;
- default:
+ default:
ret = ASN1_STRING_print_ex(out, str, pctx->str_flags);
}
if (!aux || !(aux->flags & ASN1_AFLG_REFCOUNT))
return 0;
lck = offset2ptr(*pval, aux->ref_offset);
- if (op == 0)
- {
+ if (op == 0) {
*lck = 1;
return 1;
}
{
ASN1_ENCODING *enc;
enc = asn1_get_enc_ptr(pval, it);
- if (enc)
- {
+ if (enc) {
enc->enc = NULL;
enc->len = 0;
enc->modified = 1;
{
ASN1_ENCODING *enc;
enc = asn1_get_enc_ptr(pval, it);
- if (enc)
- {
+ if (enc) {
if (enc->enc)
free(enc->enc);
enc->enc = NULL;
enc = asn1_get_enc_ptr(pval, it);
if (!enc || enc->modified)
return 0;
- if (out)
- {
+ if (out) {
memcpy(*out, enc->enc, enc->len);
*out += enc->len;
}
sfld = offset2ptr(*pval, adb->offset);
/* Check if NULL */
- if (!sfld)
- {
+ if (!sfld) {
if (!adb->null_tt)
goto err;
return adb->null_tt;
{
if (!alg)
return 0;
- if (ptype != V_ASN1_UNDEF)
- {
+ if (ptype != V_ASN1_UNDEF) {
if (alg->parameter == NULL)
alg->parameter = ASN1_TYPE_new();
if (alg->parameter == NULL)
return 0;
}
- if (alg)
- {
+ if (alg) {
if (alg->algorithm)
ASN1_OBJECT_free(alg->algorithm);
alg->algorithm = aobj;
}
if (ptype == 0)
return 1;
- if (ptype == V_ASN1_UNDEF)
- {
- if (alg->parameter)
- {
+ if (ptype == V_ASN1_UNDEF) {
+ if (alg->parameter) {
ASN1_TYPE_free(alg->parameter);
alg->parameter = NULL;
}
{
if (paobj)
*paobj = algor->algorithm;
- if (pptype)
- {
- if (algor->parameter == NULL)
- {
+ if (pptype) {
+ if (algor->parameter == NULL) {
*pptype = V_ASN1_UNDEF;
return;
}
/* Just set cmp function here. We don't sort because that
* would affect the output of X509_CRL_print().
*/
- case ASN1_OP_D2I_POST:
+ case ASN1_OP_D2I_POST:
(void)sk_X509_REVOKED_set_cmp_func(a->revoked,X509_REVOKED_cmp);
break;
-}
+ }
return 1;
}
revoked = X509_CRL_get_REVOKED(crl);
gens = NULL;
- for (i = 0; i < sk_X509_REVOKED_num(revoked); i++)
- {
+ for (i = 0; i < sk_X509_REVOKED_num(revoked); i++) {
X509_REVOKED *rev = sk_X509_REVOKED_value(revoked, i);
STACK_OF(X509_EXTENSION) *exts;
ASN1_ENUMERATED *reason;
gtmp = X509_REVOKED_get_ext_d2i(rev,
NID_certificate_issuer,
&j, NULL);
- if (!gtmp && (j != -1))
- {
+ if (!gtmp && (j != -1)) {
crl->flags |= EXFLAG_INVALID;
return 1;
}
- if (gtmp)
- {
+ if (gtmp) {
gens = gtmp;
- if (!crl->issuers)
- {
+ if (!crl->issuers) {
crl->issuers = sk_GENERAL_NAMES_new_null();
if (!crl->issuers)
return 0;
reason = X509_REVOKED_get_ext_d2i(rev, NID_crl_reason,
&j, NULL);
- if (!reason && (j != -1))
- {
+ if (!reason && (j != -1)) {
crl->flags |= EXFLAG_INVALID;
return 1;
}
- if (reason)
- {
+ if (reason) {
rev->reason = ASN1_ENUMERATED_get(reason);
ASN1_ENUMERATED_free(reason);
- }
- else
+ } else
rev->reason = CRL_REASON_NONE;
/* Check for critical CRL entry extensions */
exts = rev->extensions;
- for (j = 0; j < sk_X509_EXTENSION_num(exts); j++)
- {
+ for (j = 0; j < sk_X509_EXTENSION_num(exts); j++) {
ext = sk_X509_EXTENSION_value(exts, j);
- if (ext->critical > 0)
- {
+ if (ext->critical > 0) {
if (OBJ_obj2nid(ext->object) ==
NID_certificate_issuer)
continue;
X509_EXTENSION *ext;
int idx;
- switch(operation)
- {
- case ASN1_OP_NEW_POST:
+ switch(operation) {
+ case ASN1_OP_NEW_POST:
crl->idp = NULL;
crl->akid = NULL;
crl->flags = 0;
crl->base_crl_number = NULL;
break;
- case ASN1_OP_D2I_POST:
+ case ASN1_OP_D2I_POST:
#ifndef OPENSSL_NO_SHA
X509_CRL_digest(crl, EVP_sha1(), crl->sha1_hash, NULL);
#endif
exts = crl->crl->extensions;
- for (idx = 0; idx < sk_X509_EXTENSION_num(exts); idx++)
- {
+ for (idx = 0; idx < sk_X509_EXTENSION_num(exts); idx++) {
int nid;
ext = sk_X509_EXTENSION_value(exts, idx);
nid = OBJ_obj2nid(ext->object);
if (nid == NID_freshest_crl)
crl->flags |= EXFLAG_FRESHEST;
- if (ext->critical > 0)
- {
+ if (ext->critical > 0) {
/* We handle IDP and deltas */
if ((nid == NID_issuing_distribution_point)
|| (nid == NID_delta_crl))
if (!crl_set_issuers(crl))
return 0;
- if (crl->meth->crl_init)
- {
+ if (crl->meth->crl_init) {
if (crl->meth->crl_init(crl) == 0)
return 0;
}
break;
- case ASN1_OP_FREE_POST:
- if (crl->meth->crl_free)
- {
+ case ASN1_OP_FREE_POST:
+ if (crl->meth->crl_free) {
if (!crl->meth->crl_free(crl))
return 0;
}
int idp_only = 0;
/* Set various flags according to IDP */
crl->idp_flags |= IDP_PRESENT;
- if (idp->onlyuser > 0)
- {
+ if (idp->onlyuser > 0) {
idp_only++;
crl->idp_flags |= IDP_ONLYUSER;
}
- if (idp->onlyCA > 0)
- {
+ if (idp->onlyCA > 0) {
idp_only++;
crl->idp_flags |= IDP_ONLYCA;
}
- if (idp->onlyattr > 0)
- {
+ if (idp->onlyattr > 0) {
idp_only++;
crl->idp_flags |= IDP_ONLYATTR;
}
if (idp->indirectCRL > 0)
crl->idp_flags |= IDP_INDIRECT;
- if (idp->onlysomereasons)
- {
+ if (idp->onlysomereasons) {
crl->idp_flags |= IDP_REASONS;
if (idp->onlysomereasons->length > 0)
crl->idp_reasons = idp->onlysomereasons->data[0];
{
int i;
- if (!rev->issuer)
- {
+ if (!rev->issuer) {
if (!nm)
return 1;
if (!X509_NAME_cmp(nm, X509_CRL_get_issuer(crl)))
if (!nm)
nm = X509_CRL_get_issuer(crl);
- for (i = 0; i < sk_GENERAL_NAME_num(rev->issuer); i++)
- {
+ for (i = 0; i < sk_GENERAL_NAME_num(rev->issuer); i++) {
GENERAL_NAME *gen = sk_GENERAL_NAME_value(rev->issuer, i);
if (gen->type != GEN_DIRNAME)
continue;
/* Sort revoked into serial number order if not already sorted.
* Do this under a lock to avoid race condition.
*/
- if (!sk_X509_REVOKED_is_sorted(crl->crl->revoked))
- {
+ if (!sk_X509_REVOKED_is_sorted(crl->crl->revoked)) {
CRYPTO_w_lock(CRYPTO_LOCK_X509_CRL);
sk_X509_REVOKED_sort(crl->crl->revoked);
CRYPTO_w_unlock(CRYPTO_LOCK_X509_CRL);
if(idx < 0)
return 0;
/* Need to look for matching name */
- for(;idx < sk_X509_REVOKED_num(crl->crl->revoked); idx++)
- {
+ for(;idx < sk_X509_REVOKED_num(crl->crl->revoked); idx++) {
rev = sk_X509_REVOKED_value(crl->crl->revoked, idx);
if (ASN1_INTEGER_cmp(rev->serialNumber, serial))
return 0;
- if (crl_revoked_issuer_match(crl, issuer, rev))
- {
+ if (crl_revoked_issuer_match(crl, issuer, rev)) {
if (ret)
*ret = rev;
if (rev->reason == CRL_REASON_REMOVE_FROM_CRL)
X509_INFO *ret=NULL;
ret=(X509_INFO *)malloc(sizeof(X509_INFO));
- if (ret == NULL)
- {
+ if (ret == NULL) {
ASN1err(ASN1_F_X509_INFO_NEW,ERR_R_MALLOC_FAILURE);
return(NULL);
}
memerr:
ASN1err(ASN1_F_X509_NAME_EX_NEW, ERR_R_MALLOC_FAILURE);
- if (ret)
- {
+ if (ret) {
if (ret->entries)
sk_X509_NAME_ENTRY_free(ret->entries);
free(ret);
}
static void local_sk_X509_NAME_ENTRY_free(STACK_OF(X509_NAME_ENTRY) *ne)
- {
+{
sk_X509_NAME_ENTRY_free(ne);
- }
+}
static void local_sk_X509_NAME_ENTRY_pop_free(STACK_OF(X509_NAME_ENTRY) *ne)
- {
+{
sk_X509_NAME_ENTRY_pop_free(ne, X509_NAME_ENTRY_free);
- }
+}
static int x509_name_encode(X509_NAME *a)
{
int indent,
const char *fname,
const ASN1_PCTX *pctx)
- {
+{
if (X509_NAME_print_ex(out, (X509_NAME *)*pval,
indent, pctx->nm_flags) <= 0)
return 0;
return 2;
- }
+}
/* This function generates the canonical encoding of the Name structure.
* In it all strings are converted to UTF8, leading, trailing and
*/
static int x509_name_canon(X509_NAME *a)
- {
+{
unsigned char *p;
STACK_OF(STACK_OF_X509_NAME_ENTRY) *intname = NULL;
STACK_OF(X509_NAME_ENTRY) *entries = NULL;
X509_NAME_ENTRY *entry, *tmpentry = NULL;
int i, set = -1, ret = 0;
- if (a->canon_enc)
- {
+ if (a->canon_enc) {
free(a->canon_enc);
a->canon_enc = NULL;
}
/* Special case: empty X509_NAME => null encoding */
- if (sk_X509_NAME_ENTRY_num(a->entries) == 0)
- {
+ if (sk_X509_NAME_ENTRY_num(a->entries) == 0) {
a->canon_enclen = 0;
return 1;
- }
+ }
intname = sk_STACK_OF_X509_NAME_ENTRY_new_null();
if(!intname)
goto err;
- for(i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++)
- {
+ for(i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {
entry = sk_X509_NAME_ENTRY_value(a->entries, i);
- if(entry->set != set)
- {
+ if(entry->set != set) {
entries = sk_X509_NAME_ENTRY_new_null();
if(!entries)
goto err;
if(!sk_STACK_OF_X509_NAME_ENTRY_push(intname, entries))
goto err;
set = entry->set;
- }
+ }
tmpentry = X509_NAME_ENTRY_new();
tmpentry->object = OBJ_dup(entry->object);
if (!asn1_string_canon(tmpentry->value, entry->value))
if(!sk_X509_NAME_ENTRY_push(entries, tmpentry))
goto err;
tmpentry = NULL;
- }
+ }
/* Finally generate encoding */
sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname,
local_sk_X509_NAME_ENTRY_pop_free);
return ret;
- }
+}
/* Bitmap of all the types of string that will be canonicalized. */
static int asn1_string_canon(ASN1_STRING *out, ASN1_STRING *in)
- {
+{
unsigned char *to, *from;
int len, i;
/* If type not in bitmask just copy string across */
- if (!(ASN1_tag2bit(in->type) & ASN1_MASK_CANON))
- {
+ if (!(ASN1_tag2bit(in->type) & ASN1_MASK_CANON)) {
if (!ASN1_STRING_copy(out, in))
return 0;
return 1;
- }
+ }
out->type = V_ASN1_UTF8STRING;
out->length = ASN1_STRING_to_UTF8(&out->data, in);
*/
/* Ignore leading spaces */
- while((len > 0) && !(*from & 0x80) && isspace(*from))
- {
+ while((len > 0) && !(*from & 0x80) && isspace(*from)) {
from++;
len--;
- }
+ }
to = from + len - 1;
/* Ignore trailing spaces */
- while ((len > 0) && !(*to & 0x80) && isspace(*to))
- {
+ while ((len > 0) && !(*to & 0x80) && isspace(*to)) {
to--;
len--;
- }
+ }
to = out->data;
i = 0;
- while(i < len)
- {
+ while(i < len) {
/* If MSB set just copy across */
- if (*from & 0x80)
- {
+ if (*from & 0x80) {
*to++ = *from++;
i++;
}
/* Collapse multiple spaces */
- else if (isspace(*from))
- {
+ else if (isspace(*from)) {
/* Copy one space across */
*to++ = ' ';
/* Ignore subsequent spaces. Note: don't need to
* check len here because we know the last
* character is a non-space so we can't overflow.
*/
- do
- {
+ do {
from++;
i++;
- }
- while(!(*from & 0x80) && isspace(*from));
- }
- else
- {
+ } while(!(*from & 0x80) && isspace(*from));
+ } else {
*to++ = tolower(*from);
from++;
i++;
- }
}
+ }
out->length = to - out->data;
return 1;
- }
+}
static int i2d_name_canon(STACK_OF(STACK_OF_X509_NAME_ENTRY) *_intname,
unsigned char **in)
- {
+{
int i, len, ltmp;
ASN1_VALUE *v;
STACK_OF(ASN1_VALUE) *intname = (STACK_OF(ASN1_VALUE) *)_intname;
len = 0;
- for (i = 0; i < sk_ASN1_VALUE_num(intname); i++)
- {
+ for (i = 0; i < sk_ASN1_VALUE_num(intname); i++) {
v = sk_ASN1_VALUE_value(intname, i);
ltmp = ASN1_item_ex_i2d(&v, in,
ASN1_ITEM_rptr(X509_NAME_ENTRIES), -1, -1);
if (ltmp < 0)
return ltmp;
len += ltmp;
- }
- return len;
}
+ return len;
+}
int X509_NAME_set(X509_NAME **xn, X509_NAME *name)
- {
+{
X509_NAME *in;
if (!xn || !name) return(0);
- if (*xn != name)
- {
+ if (*xn != name) {
in=X509_NAME_dup(name);
- if (in != NULL)
- {
+ if (in != NULL) {
X509_NAME_free(*xn);
*xn=in;
- }
}
- return(*xn != NULL);
}
+ return(*xn != NULL);
+}
IMPLEMENT_STACK_OF(X509_NAME_ENTRY)
IMPLEMENT_ASN1_SET_OF(X509_NAME_ENTRY)
ret->cipher.cipher=EVP_get_cipherbyname(
OBJ_nid2ln(OBJ_obj2nid(ret->enc_algor->algorithm)));
- if (ret->cipher.cipher == NULL)
- {
+ if (ret->cipher.cipher == NULL) {
c.error=ASN1_R_UNSUPPORTED_CIPHER;
c.line=__LINE__;
goto err;
}
- if (ret->enc_algor->parameter->type == V_ASN1_OCTET_STRING)
- {
+ if (ret->enc_algor->parameter->type == V_ASN1_OCTET_STRING) {
i=ret->enc_algor->parameter->value.octet_string->length;
- if (i > EVP_MAX_IV_LENGTH)
- {
+ if (i > EVP_MAX_IV_LENGTH) {
c.error=ASN1_R_IV_TOO_LARGE;
c.line=__LINE__;
goto err;
static int pubkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
void *exarg)
{
- if (operation == ASN1_OP_FREE_POST)
- {
+ if (operation == ASN1_OP_FREE_POST) {
X509_PUBKEY *pubkey = (X509_PUBKEY *)*pval;
EVP_PKEY_free(pubkey->pkey);
}
if ((pk=X509_PUBKEY_new()) == NULL) goto error;
- if (pkey->ameth)
- {
- if (pkey->ameth->pub_encode)
- {
- if (!pkey->ameth->pub_encode(pk, pkey))
- {
+ if (pkey->ameth) {
+ if (pkey->ameth->pub_encode) {
+ if (!pkey->ameth->pub_encode(pk, pkey)) {
X509err(X509_F_X509_PUBKEY_SET,
X509_R_PUBLIC_KEY_ENCODE_ERROR);
goto error;
}
- }
- else
- {
+ } else {
X509err(X509_F_X509_PUBKEY_SET,
X509_R_METHOD_NOT_SUPPORTED);
goto error;
}
- }
- else
- {
+ } else {
X509err(X509_F_X509_PUBKEY_SET,X509_R_UNSUPPORTED_ALGORITHM);
goto error;
}
if (key == NULL) goto error;
- if (key->pkey != NULL)
- {
+ if (key->pkey != NULL) {
CRYPTO_add(&key->pkey->references, 1, CRYPTO_LOCK_EVP_PKEY);
return key->pkey;
}
if (key->public_key == NULL) goto error;
- if ((ret = EVP_PKEY_new()) == NULL)
- {
+ if ((ret = EVP_PKEY_new()) == NULL) {
X509err(X509_F_X509_PUBKEY_GET, ERR_R_MALLOC_FAILURE);
goto error;
}
- if (!EVP_PKEY_set_type(ret, OBJ_obj2nid(key->algor->algorithm)))
- {
+ if (!EVP_PKEY_set_type(ret, OBJ_obj2nid(key->algor->algorithm))) {
X509err(X509_F_X509_PUBKEY_GET,X509_R_UNSUPPORTED_ALGORITHM);
goto error;
}
- if (ret->ameth->pub_decode)
- {
- if (!ret->ameth->pub_decode(ret, key))
- {
+ if (ret->ameth->pub_decode) {
+ if (!ret->ameth->pub_decode(ret, key)) {
X509err(X509_F_X509_PUBKEY_GET,
X509_R_PUBLIC_KEY_DECODE_ERROR);
goto error;
}
- }
- else
- {
+ } else {
X509err(X509_F_X509_PUBKEY_GET, X509_R_METHOD_NOT_SUPPORTED);
goto error;
}
/* Check to see if another thread set key->pkey first */
CRYPTO_w_lock(CRYPTO_LOCK_EVP_PKEY);
- if (key->pkey)
- {
+ if (key->pkey) {
CRYPTO_w_unlock(CRYPTO_LOCK_EVP_PKEY);
EVP_PKEY_free(ret);
ret = key->pkey;
- }
- else
- {
+ } else {
key->pkey = ret;
CRYPTO_w_unlock(CRYPTO_LOCK_EVP_PKEY);
}
pktmp = X509_PUBKEY_get(xpk);
X509_PUBKEY_free(xpk);
if(!pktmp) return NULL;
- if(a)
- {
+ if(a) {
EVP_PKEY_free(*a);
*a = pktmp;
}
EVP_PKEY_free(pkey);
if (!key) return NULL;
*pp = q;
- if (a)
- {
+ if (a) {
RSA_free(*a);
*a = key;
}
int ret;
if (!a) return 0;
pktmp = EVP_PKEY_new();
- if (!pktmp)
- {
+ if (!pktmp) {
ASN1err(ASN1_F_I2D_RSA_PUBKEY, ERR_R_MALLOC_FAILURE);
return 0;
}
EVP_PKEY_free(pkey);
if (!key) return NULL;
*pp = q;
- if (a)
- {
+ if (a) {
DSA_free(*a);
*a = key;
}
int ret;
if(!a) return 0;
pktmp = EVP_PKEY_new();
- if(!pktmp)
- {
+ if(!pktmp) {
ASN1err(ASN1_F_I2D_DSA_PUBKEY, ERR_R_MALLOC_FAILURE);
return 0;
}
EVP_PKEY_free(pkey);
if (!key) return(NULL);
*pp = q;
- if (a)
- {
+ if (a) {
EC_KEY_free(*a);
*a = key;
}
EVP_PKEY *pktmp;
int ret;
if (!a) return(0);
- if ((pktmp = EVP_PKEY_new()) == NULL)
- {
+ if ((pktmp = EVP_PKEY_new()) == NULL) {
ASN1err(ASN1_F_I2D_EC_PUBKEY, ERR_R_MALLOC_FAILURE);
return(0);
}
{
if (!X509_ALGOR_set0(pub->algor, aobj, ptype, pval))
return 0;
- if (penc)
- {
+ if (penc) {
if (pub->public_key->data)
free(pub->public_key->data);
pub->public_key->data = penc;
{
if (ppkalg)
*ppkalg = pub->algor->algorithm;
- if (pk)
- {
+ if (pk) {
*pk = pub->public_key->data;
*ppklen = pub->public_key->length;
}
switch(operation) {
- case ASN1_OP_NEW_POST:
+ case ASN1_OP_NEW_POST:
ret->valid=0;
ret->name = NULL;
ret->ex_flags = 0;
CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509, ret, &ret->ex_data);
break;
- case ASN1_OP_D2I_POST:
+ case ASN1_OP_D2I_POST:
if (ret->name != NULL) free(ret->name);
ret->name=X509_NAME_oneline(ret->cert_info->subject,NULL,0);
break;
- case ASN1_OP_FREE_POST:
+ case ASN1_OP_FREE_POST:
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_X509, ret, &ret->ex_data);
X509_CERT_AUX_free(ret->aux);
ASN1_OCTET_STRING_free(ret->skid);
int X509_alias_set1(X509 *x, unsigned char *name, int len)
{
X509_CERT_AUX *aux;
- if (!name)
- {
+ if (!name) {
if (!x || !x->aux || !x->aux->alias)
return 1;
ASN1_UTF8STRING_free(x->aux->alias);
int X509_keyid_set1(X509 *x, unsigned char *id, int len)
{
X509_CERT_AUX *aux;
- if (!id)
- {
+ if (!id) {
if (!x || !x->aux || !x->aux->keyid)
return 1;
ASN1_OCTET_STRING_free(x->aux->keyid);