386BSD 0.1 development
[unix-history] / usr / othersrc / contrib / isode / dsap / common / pe.c
CommitLineData
04c6839a
WJ
1/* pe.c - General PE utility routines */
2
3#ifndef lint
4static char *rcsid = "$Header: /f/osi/dsap/common/RCS/pe.c,v 7.2 91/02/22 09:19:56 mrose Interim $";
5#endif
6
7/*
8 * $Header: /f/osi/dsap/common/RCS/pe.c,v 7.2 91/02/22 09:19:56 mrose Interim $
9 *
10 *
11 * $Log: pe.c,v $
12 * Revision 7.2 91/02/22 09:19:56 mrose
13 * Interim 6.8
14 *
15 * Revision 7.1 90/10/17 11:42:32 mrose
16 * sync
17 *
18 * Revision 7.0 89/11/23 21:44:20 mrose
19 * Release 6.0
20 *
21 */
22
23/*
24 * NOTICE
25 *
26 * Acquisition, use, and distribution of this module and related
27 * materials are subject to the restrictions of a license agreement.
28 * Consult the Preface in the User's Manual for the full terms of
29 * this agreement.
30 *
31 */
32
33
34/* LINTLIBRARY */
35
36#include "quipu/util.h"
37#include "psap.h"
38#include "quipu/attr.h" /* for defn of READOUT */
39
40extern LLog * log_dsap;
41
42pe_print (ps, pe, format)
43PS ps;
44PE pe;
45int format;
46{
47register char * ptr, *s;
48register int i, j;
49PS sps;
50static char hex[] = "0123456789abcdef";
51char buffer [LINESIZE];
52
53 if ( format == FILEOUT) {
54 (void) pe2ps (ps,pe);
55 return;
56 }
57
58 if ((format == READOUT) && (pe->pe_len >= LINESIZE)) {
59 ps_print (ps,"ASN attribute too big to print here!");
60 return;
61 }
62
63 if ((sps = ps_alloc (str_open)) == NULLPS)
64 return;
65 if (str_setup (sps,NULLCP,LINESIZE,0) == NOTOK)
66 return;
67
68 if (format != READOUT)
69 (void) ps_write (ps, (PElementData)"{ASN}", 5);
70
71 (void) pe2ps (sps,pe);
72
73 s = buffer;
74
75 ptr = sps->ps_base;
76 for (i=0, j=0; i<sps->ps_byteno; i++) {
77/*
78 ps_printf (sps2,fmt,*ptr++ & 255);
79*/
80 *s++ = hex [((*ptr & 255)/16) % 16];
81 *s++ = hex [(*ptr++ & 255) % 16];
82 j += 2;
83 if ( j >= LINESIZE ) {
84 (void) ps_write (ps, (PElementData)buffer, j);
85 s = buffer;
86 j = 0;
87 }
88 }
89 (void) ps_write (ps, (PElementData)buffer, j);
90 (void) ps_write (ps, (PElementData)"00", 2);
91 ps_free (sps);
92
93}
94
95PE asn2pe (str)
96char * str;
97{
98char * ptr;
99char * pe_ptr;
100register int i,j;
101PS sps;
102void StripSpace ();
103int val;
104PE pe;
105
106 StripSpace (str);
107
108 j = strlen (str);
109 pe_ptr = (char *) smalloc (j+10);
110 ptr = pe_ptr;
111
112 for ( i=0 ; i<j; i++) {
113 (void) sscanf (str,"%2x",&val);
114 *ptr++ = val & 0xff;
115 str++; str++;
116 }
117
118
119 if ((sps = ps_alloc (str_open)) == NULLPS)
120 return(NULLPE);
121 if (str_setup (sps,pe_ptr,j,1) == NOTOK)
122 return(NULLPE);
123
124 pe = ps2pe (sps);
125 if (sps->ps_errno != PS_ERR_NONE) {
126 LLOG (log_dsap,LLOG_EXCEPTIONS,("%s in ASN attribute ",ps_error(sps->ps_errno)));
127 if (pe) {
128 pe_free (pe);
129 pe = NULLPE;
130 }
131 }
132
133 ps_free (sps);
134
135 return (pe);
136}