security/nss/cmd/oidcalc/oidcalc.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #include <stdio.h>
michael@0 6 #include <stdlib.h>
michael@0 7 #include <string.h>
michael@0 8
michael@0 9 int
michael@0 10 main(int argc, char **argv)
michael@0 11 {
michael@0 12 char *curstr;
michael@0 13 char *nextstr;
michael@0 14 unsigned int firstval;
michael@0 15 unsigned int secondval;
michael@0 16 unsigned int val;
michael@0 17 unsigned char buf[5];
michael@0 18 int count;
michael@0 19
michael@0 20 if ( argc != 2 ) {
michael@0 21 fprintf(stderr, "wrong number of args\n");
michael@0 22 exit(-1);
michael@0 23 }
michael@0 24
michael@0 25 curstr = argv[1];
michael@0 26
michael@0 27 nextstr = strchr(curstr, '.');
michael@0 28
michael@0 29 if ( nextstr == NULL ) {
michael@0 30 fprintf(stderr, "only one component\n");
michael@0 31 exit(-1);
michael@0 32 }
michael@0 33
michael@0 34 *nextstr = '\0';
michael@0 35 firstval = atoi(curstr);
michael@0 36
michael@0 37 curstr = nextstr + 1;
michael@0 38
michael@0 39 nextstr = strchr(curstr, '.');
michael@0 40
michael@0 41 if ( nextstr ) {
michael@0 42 *nextstr = '\0';
michael@0 43 }
michael@0 44
michael@0 45 secondval = atoi(curstr);
michael@0 46
michael@0 47 if ( ( firstval < 0 ) || ( firstval > 2 ) ) {
michael@0 48 fprintf(stderr, "first component out of range\n");
michael@0 49 exit(-1);
michael@0 50
michael@0 51 }
michael@0 52
michael@0 53 if ( ( secondval < 0 ) || ( secondval > 39 ) ) {
michael@0 54 fprintf(stderr, "second component out of range\n");
michael@0 55 exit(-1);
michael@0 56 }
michael@0 57
michael@0 58 printf("0x%x, ", ( firstval * 40 ) + secondval );
michael@0 59 while ( nextstr ) {
michael@0 60 curstr = nextstr + 1;
michael@0 61
michael@0 62 nextstr = strchr(curstr, '.');
michael@0 63
michael@0 64 if ( nextstr ) {
michael@0 65 *nextstr = '\0';
michael@0 66 }
michael@0 67
michael@0 68 memset(buf, 0, sizeof(buf));
michael@0 69 val = atoi(curstr);
michael@0 70 count = 0;
michael@0 71 while ( val ) {
michael@0 72 buf[count] = ( val & 0x7f );
michael@0 73 val = val >> 7;
michael@0 74 count++;
michael@0 75 }
michael@0 76
michael@0 77 while ( count-- ) {
michael@0 78 if ( count ) {
michael@0 79 printf("0x%x, ", buf[count] | 0x80 );
michael@0 80 } else {
michael@0 81 printf("0x%x, ", buf[count] );
michael@0 82 }
michael@0 83 }
michael@0 84 }
michael@0 85 printf("\n");
michael@0 86 return 0;
michael@0 87 }
michael@0 88

mercurial