New function OBJ_obj2txt()
authorDr. Stephen Henson <steve@openssl.org>
Tue, 27 Jul 1999 22:22:58 +0000 (22:22 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Tue, 27 Jul 1999 22:22:58 +0000 (22:22 +0000)
CHANGES
crypto/asn1/a_object.c
crypto/objects/obj_dat.c
crypto/objects/objects.h
util/libeay.num

diff --git a/CHANGES b/CHANGES
index c8279bf..4f516ff 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -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
index 3a8ae03..b94b418 100644 (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)
        {
index d56edcd..d47b874 100644 (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;
index e0f88f1..d03748e 100644 (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);
index 2761f90..97787a5 100755 (executable)
@@ -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