FreeBSD/contrib/subversion/subversion/libsvn_subr/x509info.c
/* Given an OID return a null-terminated C string representation.
 * For example an OID with the bytes "\x2A\x86\x48\x86\xF7\x0D\x01\x09\x01"
 * would be converted to the string "1.2.840.113549.1.9.1". */
Given an OID return a null-terminated C string representation.
Given an OID return a null - terminated C string representation .
const char *
svn_x509_oid_to_string(const unsigned char *oid, apr_size_t oid_len,
                       apr_pool_t *scratch_pool, apr_pool_t *result_pool)
{
  svn_stringbuf_t *out = svn_stringbuf_create_empty(result_pool);
  const unsigned char *p = oid;
  const unsigned char *end = p + oid_len;
  const char *temp;
  while (p != end) {
    if (p == oid)
      {
        temp = apr_psprintf(scratch_pool, "%d.%d", *p / 40, *p % 40);
        p++;
      }
    else if (*p < 128)
      {
        temp = apr_psprintf(scratch_pool, ".%d", *p);
        p++;
      }
    else
      {
        unsigned int collector = 0;
        svn_boolean_t dot = FALSE;
        do {
          if (collector == 0 && *p == 0x80)
            {
              if (!dot)
                {
                  svn_stringbuf_appendbyte(out, '.');
                  dot = TRUE;
                }
              svn_stringbuf_appendbyte(out, '0');
            }
          else if (collector > UINT_MAX >> 7)
            {
              return NULL;
            }
          collector = collector << 7 | (*(p++) & 0x7f);
        } while (p != end && *p > 127);
        if (collector > UINT_MAX >> 7)
          return NULL; 
        collector = collector << 7 | *(p++);
        temp = apr_psprintf(scratch_pool, "%s%d", dot ? "" : ".", collector);
      }
    svn_stringbuf_appendcstr(out, temp);
  }
  if (svn_stringbuf_isempty(out))
    return NULL;
  return out->data;
}
const char * svn_x509_oid_to_string ( const unsigned char * oid , apr_size_t oid_len , apr_pool_t * scratch_pool , apr_pool_t * result_pool ) { svn_stringbuf_t * out = svn_stringbuf_create_empty ( result_pool ) ; const unsigned char * p = oid ; const unsigned char * end = p + oid_len ; const char * temp ; while ( p != end ) { if ( p == oid ) { temp = apr_psprintf ( scratch_pool , " " , * p / 40 , * p % 40 ) ; p ++ ; } else if ( * p < 128 ) { temp = apr_psprintf ( scratch_pool , " " , * p ) ; p ++ ; } else { unsigned int collector = 0 ; svn_boolean_t dot = FALSE ; do { if ( collector == 0 && * p == 0x80 ) { if ( ! dot ) { svn_stringbuf_appendbyte ( out , ' ' ) ; dot = TRUE ; } svn_stringbuf_appendbyte ( out , ' ' ) ; } else if ( collector > UINT_MAX >> 7 ) { return NULL ; } collector = collector << 7 | ( * ( p ++ ) & 0x7f ) ; } while ( p != end && * p > 127 ) ; if ( collector > UINT_MAX >> 7 ) return NULL ; collector = collector << 7 | * ( p ++ ) ; temp = apr_psprintf ( scratch_pool , " " , dot ? " " : " " , collector ) ; } svn_stringbuf_appendcstr ( out , temp ) ; } if ( svn_stringbuf_isempty ( out ) ) return NULL ; return out -> data ; }
Given an OID return a null-terminated C string representation.
Given an OID return a null - terminated C string representation .
/* Handle decoding the first two values of the OID.  These values
         * are encoded by taking the first value and adding 40 to it and
         * adding the result to the second value, then placing this single
         * value in the first byte of the output.  This is unambiguous since
         * the first value is apparently limited to 0, 1 or 2 and the second
         * is limited to 0 to 39. */ /* The remaining values if they're less than 128 are just
         * the number one to one encoded */ /* Values greater than 128 are encoded as a series of 7 bit values
         * with the left most bit set to indicate this encoding with the
         * last octet missing the left most bit to finish out the series.. */ /* include leading zeros in the string representation
                 technically not legal, but this seems nicer than just
                 returning NULL */ /* overflow */ /* overflow */