/* converts an OID in normal decimal numeric form e.g. .1.2.3.4 to a hex BER string. OR vice versa */ #include #include #include void main (int argc, char *argv[]) { int om_ret; int a, b; OM_object_identifier oid; char *str; unsigned char oidv[100]; for (a = 1 ; a < argc; a++) { if ( 0 != strchr(argv[a], '.')) { om_ret = at_str_to_oid (argv[a], &oid); if (om_ret != OM_SUCCESS) { printf ("at_str_to_oid() failed: %d for object instance %s.\n", om_ret, argv[a]); continue; } printf ("\""); for (b =0; b < oid.length; b++) { printf("\\x%2.2x", ((unsigned char *)oid.elements)[b] & 0xff); } printf ("\"; // %s\n", argv[a]); } else { /* reversing a BER OID string back to text */ for (b =0, str = argv[a], oid.length = 0; str[b]; b+=1) { int n; switch (str[b]) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': n = str[b] - '0'; break; case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': n = str[b] - 'a' + 10; break; case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': n = str[b] - 'A' + 10; break; default: n = 0; } oidv[oid.length] = n << 4; b +=1; switch (str[b]) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': n = str[b] - '0'; break; case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': n = str[b] - 'a' + 10; break; case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': n = str[b] - 'A' + 10; break; default: n = 0; } oidv[oid.length++] |= n ; } oid.elements = oidv; om_ret = at_oid_to_str (oid, &str); if (om_ret != OM_SUCCESS) { printf ("at_oid_to_str() failed: %d for object instance %s.\n", om_ret, argv[a]); continue; } printf("%s => %s\n", argv[a], str); } } }