New function OBJ_obj2txt()

This commit is contained in:
Dr. Stephen Henson 1999-07-27 22:22:58 +00:00
parent 770d19b862
commit 3e3d2ea2fc
5 changed files with 77 additions and 71 deletions

View File

@ -4,6 +4,12 @@
Changes between 0.9.3a and 0.9.4 [xx Jul/Aug/...? 1999]
*) New function OBJ_obj2txt(buf, buf_len, a, no_name), this converts
an ASN1_OBJECT to a text string. If the "no_name" parameter is set then
it will always use the numerical form of the OID, even if it has a short
or long name.
[Steve Henson]
*) Added an extra RSA flag: RSA_FLAG_EXT_PKEY. Previously the rsa_mod_exp
method only got called if p,q,dmp1,dmq1,iqmp components were present,
otherwise bn_mod_exp was called. In the case of hardware keys for example

View File

@ -171,77 +171,9 @@ err:
}
int i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a)
{
int i,idx=0,n=0,len,nid;
unsigned long l;
unsigned char *p;
const char *s;
char tbuf[32];
if (buf_len <= 0) return(0);
if ((a == NULL) || (a->data == NULL))
{
buf[0]='\0';
return(0);
}
nid=OBJ_obj2nid(a);
if (nid == NID_undef)
{
len=a->length;
p=a->data;
idx=0;
l=0;
while (idx < a->length)
{
l|=(p[idx]&0x7f);
if (!(p[idx] & 0x80)) break;
l<<=7L;
idx++;
}
idx++;
i=(int)(l/40);
if (i > 2) i=2;
l-=(long)(i*40);
sprintf(tbuf,"%d.%lu",i,l);
i=strlen(tbuf);
strncpy(buf,tbuf,buf_len);
buf_len-=i;
buf+=i;
n+=i;
l=0;
for (; idx<len; idx++)
{
l|=p[idx]&0x7f;
if (!(p[idx] & 0x80))
{
sprintf(tbuf,".%lu",l);
i=strlen(tbuf);
if (buf_len > 0)
strncpy(buf,tbuf,buf_len);
buf_len-=i;
buf+=i;
n+=i;
l=0;
}
l<<=7L;
}
}
else
{
s=OBJ_nid2ln(nid);
if (s == NULL)
s=OBJ_nid2sn(nid);
strncpy(buf,s,buf_len);
n=strlen(s);
}
buf[buf_len-1]='\0';
return(n);
}
{
return OBJ_obj2txt(buf, buf_len, a, 0);
}
int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a)
{

View File

@ -418,6 +418,72 @@ ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name)
return op;
}
int OBJ_obj2txt(char *buf, int buf_len, ASN1_OBJECT *a, int no_name)
{
int i,idx=0,n=0,len,nid;
unsigned long l;
unsigned char *p;
const char *s;
char tbuf[32];
if (buf_len <= 0) return(0);
if ((a == NULL) || (a->data == NULL)) {
buf[0]='\0';
return(0);
}
nid=OBJ_obj2nid(a);
if ((nid == NID_undef) || no_name) {
len=a->length;
p=a->data;
idx=0;
l=0;
while (idx < a->length) {
l|=(p[idx]&0x7f);
if (!(p[idx] & 0x80)) break;
l<<=7L;
idx++;
}
idx++;
i=(int)(l/40);
if (i > 2) i=2;
l-=(long)(i*40);
sprintf(tbuf,"%d.%lu",i,l);
i=strlen(tbuf);
strncpy(buf,tbuf,buf_len);
buf_len-=i;
buf+=i;
n+=i;
l=0;
for (; idx<len; idx++) {
l|=p[idx]&0x7f;
if (!(p[idx] & 0x80)) {
sprintf(tbuf,".%lu",l);
i=strlen(tbuf);
if (buf_len > 0)
strncpy(buf,tbuf,buf_len);
buf_len-=i;
buf+=i;
n+=i;
l=0;
}
l<<=7L;
}
} else {
s=OBJ_nid2ln(nid);
if (s == NULL)
s=OBJ_nid2sn(nid);
strncpy(buf,s,buf_len);
n=strlen(s);
}
buf[buf_len-1]='\0';
return(n);
}
int OBJ_txt2nid(char *s)
{
ASN1_OBJECT *obj;

View File

@ -928,6 +928,7 @@ const char * OBJ_nid2ln(int n);
const char * OBJ_nid2sn(int n);
int OBJ_obj2nid(ASN1_OBJECT *o);
ASN1_OBJECT * OBJ_txt2obj(const char *s, int no_name);
int OBJ_obj2txt(char *buf, int buf_len, ASN1_OBJECT *a, int no_name);
int OBJ_txt2nid(char *s);
int OBJ_ln2nid(const char *s);
int OBJ_sn2nid(const char *s);

View File

@ -1842,3 +1842,4 @@ sk_POLICYQUALINFO_sort 1866
sk_X509_CRL_sort 1867
sk_DIST_POINT_sort 1868
RSA_check_key 1869
OBJ_obj2txt 1870