xref: /onnv-gate/usr/src/lib/libldap5/sources/ldap/common/secutil.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * Copyright (c) 2001 by Sun Microsystems, Inc.
3*0Sstevel@tonic-gate  * All rights reserved.
4*0Sstevel@tonic-gate  */
5*0Sstevel@tonic-gate 
6*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
7*0Sstevel@tonic-gate 
8*0Sstevel@tonic-gate #include <stdlib.h>
9*0Sstevel@tonic-gate #include <string.h>
10*0Sstevel@tonic-gate #include <ctype.h>
11*0Sstevel@tonic-gate 
12*0Sstevel@tonic-gate static char	hexdig[] = "0123456789abcdef";
13*0Sstevel@tonic-gate 
hexa_print(char * aString,int aLen)14*0Sstevel@tonic-gate char* hexa_print(char *aString, int aLen)
15*0Sstevel@tonic-gate {
16*0Sstevel@tonic-gate 	char *res;
17*0Sstevel@tonic-gate 	int i =0;
18*0Sstevel@tonic-gate 
19*0Sstevel@tonic-gate 	if ((res = (char *)calloc (aLen*2 + 1, 1 )) == NULL){
20*0Sstevel@tonic-gate 		return (NULL);
21*0Sstevel@tonic-gate 	}
22*0Sstevel@tonic-gate 	for (;;){
23*0Sstevel@tonic-gate 		if (aLen < 1)
24*0Sstevel@tonic-gate 			break;
25*0Sstevel@tonic-gate 		res[i] = hexdig[ ( *aString & 0xf0 ) >> 4 ];
26*0Sstevel@tonic-gate 		res[i + 1] = hexdig[ *aString & 0x0f ];
27*0Sstevel@tonic-gate 		i+= 2;
28*0Sstevel@tonic-gate 		aLen--;
29*0Sstevel@tonic-gate 		aString++;
30*0Sstevel@tonic-gate 	}
31*0Sstevel@tonic-gate 	return (res);
32*0Sstevel@tonic-gate }
33