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 c8279bf1357b7122475592e331f428a312b59912..4f516ffd5d1e43d98216ba09299f0fbe59e7c51b 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 3a8ae0305d836fbb9610e25b447f18f312ef8fe9..b94b418ee89a8f1ff424134fe022bccaad3867e3 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 d56edcdf964a31c703a83ab3aba272dac1ba72e9..d47b874399c7ea52db77ba2e2b8ade1a8f820331 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 e0f88f1f0360164a2e2aeb414b67693275995622..d03748e0228af03f211a2d176d32cfe04aeb6207 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 2761f905896bb4930e1aff59de04eceb5330b63d..97787a5975a6c1b8cbe9060d645b94ef8575af58 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