Cross Reference: secutil.c
xref
: /
osnet-11
/
usr
/
src
/
lib
/
libldap4
/
sec
/
secutil.c
Home
History
Annotate
Line#
Navigate
Download
Search
only in
./
1
N/A
/*
1
N/A
*
1
N/A
* Copyright 1998 Sun Microsystems, Inc. All rights reserved.
1
N/A
* Use is subject to license terms.
1
N/A
*
1
N/A
*
1
N/A
* Comments:
1
N/A
*
1
N/A
*/
1
N/A
1
N/A
#
pragma
ident
"%Z%%M% %I% %E% SMI"
1
N/A
1
N/A
#
include
<
stdlib.h
>
1
N/A
#
include
<
string.h
>
1
N/A
#
include
<
ctype.h
>
1
N/A
1
N/A
static
char
hexdig
[] =
"0123456789abcdef"
;
1
N/A
1
N/A
char
*
hexa_print
(
char
*
aString
,
int
aLen
)
1
N/A
{
1
N/A
char
*
res
;
1
N/A
int
i =0;
1
N/A
1
N/A
if
((
res
= (
char
*)
calloc
(
aLen
*
2
+
1
,
1
)) ==
NULL
){
1
N/A
return
(
NULL
);
1
N/A
}
1
N/A
for
(;;){
1
N/A
if
(
aLen
<
1
)
1
N/A
break
;
1
N/A
res
[i] =
hexdig
[ ( *
aString
&
0xf0
) >>
4
];
1
N/A
res
[i +
1
] =
hexdig
[ *
aString
&
0x0f
];
1
N/A
i+=
2
;
1
N/A
aLen
--;
1
N/A
aString
++;
1
N/A
}
1
N/A
return
(
res
);
1
N/A
}
1
N/A
1
N/A
1
N/A
static
int
1
N/A
unhex
(
char
c )
1
N/A
{
1
N/A
return
( c >=
'0'
&& c <=
'9'
? c -
'0'
1
N/A
: c >=
'A'
&& c <=
'F'
? c -
'A'
+
10
1
N/A
: c -
'a'
+
10
);
1
N/A
}
1
N/A
1
N/A
char
*
hexa2str
(
char
*
anHexaStr
,
int
*
aResLen
) {
1
N/A
int
theLen
= 0;
1
N/A
char
*
theRes
=
malloc
(
strlen
(
anHexaStr
) /
2
+
1
);
1
N/A
1
N/A
while
(
isxdigit
(*
anHexaStr
)){
1
N/A
theRes
[
theLen
] =
unhex
(*
anHexaStr
) <<
4
;
1
N/A
if
(++
anHexaStr
!=
'\0'
){
1
N/A
theRes
[
theLen
] +=
unhex
(*
anHexaStr
);
1
N/A
anHexaStr
++;
1
N/A
}
1
N/A
theLen
++;
1
N/A
}
1
N/A
theRes
[
theLen
] =
'\0'
;
1
N/A
*
aResLen
=
theLen
;
1
N/A
return
(
theRes
);
1
N/A
}