提交 3e3d2ea2 编写于 作者: D Dr. Stephen Henson

New function OBJ_obj2txt()

上级 770d19b8
...@@ -4,6 +4,12 @@ ...@@ -4,6 +4,12 @@
Changes between 0.9.3a and 0.9.4 [xx Jul/Aug/...? 1999] 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 *) 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, 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 otherwise bn_mod_exp was called. In the case of hardware keys for example
......
...@@ -171,77 +171,9 @@ err: ...@@ -171,77 +171,9 @@ err:
} }
int i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a) int i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a)
{ {
int i,idx=0,n=0,len,nid; return OBJ_obj2txt(buf, buf_len, a, 0);
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);
}
int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a) int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a)
{ {
......
...@@ -418,6 +418,72 @@ ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name) ...@@ -418,6 +418,72 @@ ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name)
return op; 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) int OBJ_txt2nid(char *s)
{ {
ASN1_OBJECT *obj; ASN1_OBJECT *obj;
......
...@@ -928,6 +928,7 @@ const char * OBJ_nid2ln(int n); ...@@ -928,6 +928,7 @@ const char * OBJ_nid2ln(int n);
const char * OBJ_nid2sn(int n); const char * OBJ_nid2sn(int n);
int OBJ_obj2nid(ASN1_OBJECT *o); int OBJ_obj2nid(ASN1_OBJECT *o);
ASN1_OBJECT * OBJ_txt2obj(const char *s, int no_name); 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_txt2nid(char *s);
int OBJ_ln2nid(const char *s); int OBJ_ln2nid(const char *s);
int OBJ_sn2nid(const char *s); int OBJ_sn2nid(const char *s);
......
...@@ -1842,3 +1842,4 @@ sk_POLICYQUALINFO_sort 1866 ...@@ -1842,3 +1842,4 @@ sk_POLICYQUALINFO_sort 1866
sk_X509_CRL_sort 1867 sk_X509_CRL_sort 1867
sk_DIST_POINT_sort 1868 sk_DIST_POINT_sort 1868
RSA_check_key 1869 RSA_check_key 1869
OBJ_obj2txt 1870
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册