Skip to content
Snippets Groups Projects
Commit e94e3e51 authored by Lev Walkin's avatar Lev Walkin
Browse files

converted from tex

parent fecbd1e9
No related branches found
No related tags found
No related merge requests found
...@@ -41,93 +41,103 @@ Contents</A> ...@@ -41,93 +41,103 @@ Contents</A>
<!--Table of Contents--> <!--Table of Contents-->
<UL> <UL>
<LI><A NAME="tex2html48" <LI><A NAME="tex2html50"
HREF="asn1c-usage.html#SECTION02000000000000000000">ASN.1 Basics</A> HREF="asn1c-usage.html#SECTION02000000000000000000">ASN.1 Basics</A>
<UL> <UL>
<LI><A NAME="tex2html49" <LI><A NAME="tex2html51"
HREF="asn1c-usage.html#SECTION02100000000000000000">Abstract Syntax Notation: ASN.1</A> HREF="asn1c-usage.html#SECTION02100000000000000000">Abstract Syntax Notation: ASN.1</A>
<UL> <UL>
<LI><A NAME="tex2html50" <LI><A NAME="tex2html52"
HREF="asn1c-usage.html#SECTION02110000000000000000">Some of the ASN.1 Basic Types</A> HREF="asn1c-usage.html#SECTION02110000000000000000">Some of the ASN.1 Basic Types</A>
<UL> <UL>
<LI><A NAME="tex2html51" <LI><A NAME="tex2html53"
HREF="asn1c-usage.html#SECTION02111000000000000000">The BOOLEAN type</A> HREF="asn1c-usage.html#SECTION02111000000000000000">The BOOLEAN type</A>
<LI><A NAME="tex2html52" <LI><A NAME="tex2html54"
HREF="asn1c-usage.html#SECTION02112000000000000000">The INTEGER type</A> HREF="asn1c-usage.html#SECTION02112000000000000000">The INTEGER type</A>
<LI><A NAME="tex2html53" <LI><A NAME="tex2html55"
HREF="asn1c-usage.html#SECTION02113000000000000000">The ENUMERATED type</A> HREF="asn1c-usage.html#SECTION02113000000000000000">The ENUMERATED type</A>
<LI><A NAME="tex2html54" <LI><A NAME="tex2html56"
HREF="asn1c-usage.html#SECTION02114000000000000000">The OCTET STRING type</A> HREF="asn1c-usage.html#SECTION02114000000000000000">The OCTET STRING type</A>
<LI><A NAME="tex2html55" <LI><A NAME="tex2html57"
HREF="asn1c-usage.html#SECTION02115000000000000000">The OBJECT IDENTIFIER type</A> HREF="asn1c-usage.html#SECTION02115000000000000000">The OBJECT IDENTIFIER type</A>
<LI><A NAME="tex2html56" <LI><A NAME="tex2html58"
HREF="asn1c-usage.html#SECTION02116000000000000000">The RELATIVE-OID type</A> HREF="asn1c-usage.html#SECTION02116000000000000000">The RELATIVE-OID type</A>
</UL> </UL>
<LI><A NAME="tex2html57" <LI><A NAME="tex2html59"
HREF="asn1c-usage.html#SECTION02120000000000000000">Some of the ASN.1 String Types</A> HREF="asn1c-usage.html#SECTION02120000000000000000">Some of the ASN.1 String Types</A>
<UL> <UL>
<LI><A NAME="tex2html58" <LI><A NAME="tex2html60"
HREF="asn1c-usage.html#SECTION02121000000000000000">The IA5String type</A> HREF="asn1c-usage.html#SECTION02121000000000000000">The IA5String type</A>
<LI><A NAME="tex2html59" <LI><A NAME="tex2html61"
HREF="asn1c-usage.html#SECTION02122000000000000000">The UTF8String type</A> HREF="asn1c-usage.html#SECTION02122000000000000000">The UTF8String type</A>
<LI><A NAME="tex2html60" <LI><A NAME="tex2html62"
HREF="asn1c-usage.html#SECTION02123000000000000000">The NumericString type</A> HREF="asn1c-usage.html#SECTION02123000000000000000">The NumericString type</A>
<LI><A NAME="tex2html61" <LI><A NAME="tex2html63"
HREF="asn1c-usage.html#SECTION02124000000000000000">The PrintableString type</A> HREF="asn1c-usage.html#SECTION02124000000000000000">The PrintableString type</A>
<LI><A NAME="tex2html62" <LI><A NAME="tex2html64"
HREF="asn1c-usage.html#SECTION02125000000000000000">The VisibleString type</A> HREF="asn1c-usage.html#SECTION02125000000000000000">The VisibleString type</A>
</UL> </UL>
<LI><A NAME="tex2html63" <LI><A NAME="tex2html65"
HREF="asn1c-usage.html#SECTION02130000000000000000">ASN.1 Constructed Types</A> HREF="asn1c-usage.html#SECTION02130000000000000000">ASN.1 Constructed Types</A>
<UL> <UL>
<LI><A NAME="tex2html64" <LI><A NAME="tex2html66"
HREF="asn1c-usage.html#SECTION02131000000000000000">The SEQUENCE type</A> HREF="asn1c-usage.html#SECTION02131000000000000000">The SEQUENCE type</A>
<LI><A NAME="tex2html65" <LI><A NAME="tex2html67"
HREF="asn1c-usage.html#SECTION02132000000000000000">The SET type</A> HREF="asn1c-usage.html#SECTION02132000000000000000">The SET type</A>
<LI><A NAME="tex2html66" <LI><A NAME="tex2html68"
HREF="asn1c-usage.html#SECTION02133000000000000000">The CHOICE type</A> HREF="asn1c-usage.html#SECTION02133000000000000000">The CHOICE type</A>
<LI><A NAME="tex2html67" <LI><A NAME="tex2html69"
HREF="asn1c-usage.html#SECTION02134000000000000000">The SEQUENCE OF type</A> HREF="asn1c-usage.html#SECTION02134000000000000000">The SEQUENCE OF type</A>
<LI><A NAME="tex2html68" <LI><A NAME="tex2html70"
HREF="asn1c-usage.html#SECTION02135000000000000000">The SET OF type</A> HREF="asn1c-usage.html#SECTION02135000000000000000">The SET OF type</A>
</UL> </UL>
</UL> </UL>
</UL><BR> </UL><BR>
<LI><A NAME="tex2html69" <LI><A NAME="tex2html71"
HREF="asn1c-usage.html#SECTION03000000000000000000">Using the ASN.1 Compiler</A> HREF="asn1c-usage.html#SECTION03000000000000000000">Using the ASN.1 Compiler</A>
<UL> <UL>
<LI><A NAME="tex2html70" <LI><A NAME="tex2html72"
HREF="asn1c-usage.html#SECTION03100000000000000000">Introduction to the ASN.1 Compiler</A> HREF="asn1c-usage.html#SECTION03100000000000000000">Introduction to the ASN.1 Compiler</A>
<LI><A NAME="tex2html71" <LI><A NAME="tex2html73"
HREF="asn1c-usage.html#SECTION03200000000000000000">Quick start</A> HREF="asn1c-usage.html#SECTION03200000000000000000">Quick start</A>
<LI><A NAME="tex2html72" <LI><A NAME="tex2html74"
HREF="asn1c-usage.html#SECTION03300000000000000000">Using the ASN.1 Compiler</A> HREF="asn1c-usage.html#SECTION03300000000000000000">Using the ASN.1 Compiler</A>
<UL> <UL>
<LI><A NAME="tex2html73" <LI><A NAME="tex2html75"
HREF="asn1c-usage.html#SECTION03310000000000000000">Command-line options</A> HREF="asn1c-usage.html#SECTION03310000000000000000">Command-line options</A>
<LI><A NAME="tex2html74" <LI><A NAME="tex2html76"
HREF="asn1c-usage.html#SECTION03320000000000000000">Recognizing compiler output</A> HREF="asn1c-usage.html#SECTION03320000000000000000">Recognizing compiler output</A>
<LI><A NAME="tex2html75" <LI><A NAME="tex2html77"
HREF="asn1c-usage.html#SECTION03330000000000000000">Invoking the ASN.1 helper code from an application</A> HREF="asn1c-usage.html#SECTION03330000000000000000">Invoking the ASN.1 helper code from an application</A>
<UL> <UL>
<LI><A NAME="tex2html76" <LI><A NAME="tex2html78"
HREF="asn1c-usage.html#SECTION03331000000000000000">Decoding BER</A> HREF="asn1c-usage.html#SECTION03331000000000000000">Decoding BER</A>
<LI><A NAME="tex2html77" <LI><A NAME="tex2html79"
HREF="asn1c-usage.html#SECTION03332000000000000000">Encoding DER</A> HREF="asn1c-usage.html#SECTION03332000000000000000">Encoding DER</A>
<LI><A NAME="tex2html78" <LI><A NAME="tex2html80"
HREF="asn1c-usage.html#SECTION03333000000000000000">Encoding XER</A> HREF="asn1c-usage.html#SECTION03333000000000000000">Encoding XER</A>
<LI><A NAME="tex2html79" <LI><A NAME="tex2html81"
HREF="asn1c-usage.html#SECTION03334000000000000000">Validating the target structure</A> HREF="asn1c-usage.html#SECTION03334000000000000000">Validating the target structure</A>
<LI><A NAME="tex2html80" <LI><A NAME="tex2html82"
HREF="asn1c-usage.html#SECTION03335000000000000000">Printing the target structure</A> HREF="asn1c-usage.html#SECTION03335000000000000000">Printing the target structure</A>
<LI><A NAME="tex2html81" <LI><A NAME="tex2html83"
HREF="asn1c-usage.html#SECTION03336000000000000000">Freeing the target structure</A> HREF="asn1c-usage.html#SECTION03336000000000000000">Freeing the target structure</A>
</UL> </UL>
</UL> </UL>
</UL><BR> </UL><BR>
<LI><A NAME="tex2html82" <LI><A NAME="tex2html84"
HREF="asn1c-usage.html#SECTION04000000000000000000">Examples</A> HREF="asn1c-usage.html#SECTION04000000000000000000">Examples</A>
<LI><A NAME="tex2html83" <UL>
<LI><A NAME="tex2html85"
HREF="asn1c-usage.html#SECTION04100000000000000000">Step by step examples</A>
<UL>
<LI><A NAME="tex2html86"
HREF="asn1c-usage.html#SECTION04110000000000000000">A ''Rectangle'' Encoder</A>
<LI><A NAME="tex2html87"
HREF="asn1c-usage.html#SECTION04120000000000000000">A ''Rectangle'' Decoder</A>
</UL>
</UL><BR>
<LI><A NAME="tex2html88"
HREF="asn1c-usage.html#SECTION05000000000000000000">Bibliography</A> HREF="asn1c-usage.html#SECTION05000000000000000000">Bibliography</A>
</UL> </UL>
<!--End of Table of Contents--> <!--End of Table of Contents-->
...@@ -570,7 +580,7 @@ language structures and surrounding maintenance code. For example, ...@@ -570,7 +580,7 @@ language structures and surrounding maintenance code. For example,
the C structure which may be created by compiler to represent the the C structure which may be created by compiler to represent the
simple <I>Rectangle</I> specification defined earlier in this document, simple <I>Rectangle</I> specification defined earlier in this document,
may look like this<A NAME="tex2html2" may look like this<A NAME="tex2html2"
HREF="#foot574"><SUP>2.2</SUP></A>: HREF="#foot739"><SUP>2.2</SUP></A>:
<P> <P>
...@@ -596,8 +606,8 @@ Quick start</A> ...@@ -596,8 +606,8 @@ Quick start</A>
<P> <P>
After building and installing the compiler, the <I>asn1c</I><A NAME="tex2html4" After building and installing the compiler, the <I>asn1c</I><A NAME="tex2html4"
HREF="#foot575"><SUP>3.1</SUP></A> command may be used to compile the ASN.1 specification<A NAME="tex2html5" HREF="#foot740"><SUP>3.1</SUP></A> command may be used to compile the ASN.1 specification<A NAME="tex2html5"
HREF="#foot576"><SUP>3.2</SUP></A>: HREF="#foot741"><SUP>3.2</SUP></A>:
<P> <P>
...@@ -663,7 +673,7 @@ the compiler's behavior. ...@@ -663,7 +673,7 @@ the compiler's behavior.
<P> <P>
<BR><P></P> <BR><P></P>
<DIV ALIGN="CENTER"><A NAME="579"></A> <DIV ALIGN="CENTER"><A NAME="744"></A>
<TABLE> <TABLE>
<CAPTION><STRONG><A NAME=Table1>Table 1:</A></STRONG> <CAPTION><STRONG><A NAME=Table1>Table 1:</A></STRONG>
The list of asn1c command line options</CAPTION> The list of asn1c command line options</CAPTION>
...@@ -807,7 +817,7 @@ be possible to compile everything with the single instruction: ...@@ -807,7 +817,7 @@ be possible to compile everything with the single instruction:
<BLOCKQUOTE><PRE> <BLOCKQUOTE><PRE>
cc&nbsp;-o&nbsp;rectangle&nbsp;*.c&nbsp;&nbsp;&nbsp;#&nbsp;It&nbsp;could&nbsp;be&nbsp;<I>that</I>&nbsp;simple<A NAME="tex2html7" cc&nbsp;-o&nbsp;rectangle&nbsp;*.c&nbsp;&nbsp;&nbsp;#&nbsp;It&nbsp;could&nbsp;be&nbsp;<I>that</I>&nbsp;simple<A NAME="tex2html7"
HREF="#foot582"><SUP>4.1</SUP></A> HREF="#foot747"><SUP>4.1</SUP></A>
</PRE> </PRE>
</BLOCKQUOTE> </BLOCKQUOTE>
...@@ -1059,19 +1069,6 @@ function, which is somewhat simpler: ...@@ -1059,19 +1069,6 @@ function, which is somewhat simpler:
<P> <P>
<BLOCKQUOTE><PRE> <BLOCKQUOTE><PRE>
/*
&nbsp;*&nbsp;This&nbsp;is&nbsp;a&nbsp;custom&nbsp;function&nbsp;which&nbsp;writes&nbsp;the
&nbsp;*&nbsp;encoded&nbsp;output&nbsp;into&nbsp;some&nbsp;FILE&nbsp;stream.
&nbsp;*/
static&nbsp;int
write_stream(const&nbsp;void&nbsp;*buffer,&nbsp;size_t&nbsp;size,&nbsp;void&nbsp;*app_key)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;FILE&nbsp;*ostream&nbsp;=&nbsp;app_key;
&nbsp;&nbsp;&nbsp;&nbsp;size_t&nbsp;wrote;
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;wrote&nbsp;=&nbsp;fwrite(buffer,&nbsp;1,&nbsp;size,&nbsp;ostream);
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;(wrote&nbsp;==&nbsp;size)&nbsp;?&nbsp;0&nbsp;:&nbsp;-1;
}
&nbsp; &nbsp;
/* /*
&nbsp;*&nbsp;This&nbsp;is&nbsp;the&nbsp;serializer&nbsp;itself, &nbsp;*&nbsp;This&nbsp;is&nbsp;the&nbsp;serializer&nbsp;itself,
...@@ -1112,7 +1109,7 @@ DER encoder will essentially do the same thing (i.e., encode the data) ...@@ -1112,7 +1109,7 @@ DER encoder will essentially do the same thing (i.e., encode the data)
but no callbacks will be invoked (so the data goes nowhere). It may but no callbacks will be invoked (so the data goes nowhere). It may
prove useful to determine the size of the structure's encoding before prove useful to determine the size of the structure's encoding before
actually doing the encoding<A NAME="tex2html9" actually doing the encoding<A NAME="tex2html9"
HREF="#foot329"><SUP>4.3</SUP></A>. HREF="#foot322"><SUP>4.3</SUP></A>.
<P> <P>
Please look into der_encoder.h for the precise definition of der_encode() Please look into der_encoder.h for the precise definition of der_encode()
...@@ -1299,11 +1296,159 @@ Examples</A> ...@@ -1299,11 +1296,159 @@ Examples</A>
<P> <P>
<H1><A NAME="SECTION04100000000000000000"> <H1><A NAME="SECTION04100000000000000000">
Step-by-step: A ''Rectangle'' Decoder</A> Step by step examples</A>
</H1>
<P>
<H1><A NAME="SECTION04110000000000000000">
A ''Rectangle'' Encoder</A>
</H1>
<P>
This chapter will help you to create a simple BER and XER encoder
of a ''Rectangle'' type used throughout this document.
<P>
<OL>
<LI>Create a file named <B>rectangle.asn1</B> with the following contents:
<P>
<BLOCKQUOTE><PRE>
RectangleModule1&nbsp;DEFINITIONS&nbsp;::=
BEGIN
&nbsp;
Rectangle&nbsp;::=&nbsp;SEQUENCE&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;height&nbsp;&nbsp;INTEGER,
&nbsp;&nbsp;&nbsp;&nbsp;width&nbsp;&nbsp;&nbsp;INTEGER
}
&nbsp;
END
</PRE>
</BLOCKQUOTE>
</LI>
<LI>Compile it into the set of .c and .h files using asn1c compiler [<A
HREF="asn1c-usage.html#ASN1C">ASN1C</A>]:
<P>
<BLOCKQUOTE><PRE>
<I>asn1c&nbsp;-fnative-types</I>&nbsp;<B>rectangle.asn1</B>
</PRE>
</BLOCKQUOTE>
</LI>
<LI>Alternatively, use the Online ASN.1 compiler [<A
HREF="asn1c-usage.html#AONL">AONL</A>] by uploading
the <B>rectangle.asn1</B> file into the Web form and unpacking the
produced archive on your computer.
</LI>
<LI>By this time, you should have gotten multiple files in the current
directory, including the <B>Rectangle.c</B> and <B>Rectangle.h</B>.
</LI>
<LI>Create a main() routine which creates the Rectangle_t structure in
memory and encodes it using BER and XER encoding rules. Let's name
the file <B>main.c</B>:
<P>
<BLOCKQUOTE><PRE>
<FONT SIZE="-1">#include&nbsp;&lt;stdio.h&gt;</FONT>
<FONT SIZE="-1">#include&nbsp;&lt;sys/types.h&gt;</FONT>
<FONT SIZE="-1">#include&nbsp;&lt;Rectangle.h&gt;&nbsp;&nbsp;&nbsp;/*&nbsp;Rectangle&nbsp;ASN.1&nbsp;type&nbsp;&nbsp;*/</FONT>
&nbsp;
<FONT SIZE="-1">/*</FONT>
&nbsp;<FONT SIZE="-1">*&nbsp;This&nbsp;is&nbsp;a&nbsp;custom&nbsp;function&nbsp;which&nbsp;writes&nbsp;the</FONT>
&nbsp;<FONT SIZE="-1">*&nbsp;encoded&nbsp;output&nbsp;into&nbsp;some&nbsp;FILE&nbsp;stream.</FONT>
&nbsp;<FONT SIZE="-1">*/</FONT>
<FONT SIZE="-1">static&nbsp;int</FONT>
<FONT SIZE="-1">write_out(const&nbsp;void&nbsp;*buffer,&nbsp;size_t&nbsp;size,&nbsp;void&nbsp;*app_key)&nbsp;{</FONT>
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;FILE&nbsp;*out_fp&nbsp;=&nbsp;app_key;</FONT>
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;size_t&nbsp;wrote;</FONT>
&nbsp;
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;wrote&nbsp;=&nbsp;fwrite(buffer,&nbsp;1,&nbsp;size,&nbsp;out_fp);</FONT>
&nbsp;
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;return&nbsp;(wrote&nbsp;==&nbsp;size)&nbsp;?&nbsp;0&nbsp;:&nbsp;-1;</FONT>
<FONT SIZE="-1">}</FONT>
&nbsp;
<FONT SIZE="-1">int&nbsp;main(int&nbsp;ac,&nbsp;char&nbsp;*av)&nbsp;{</FONT>
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;Rectangle_t&nbsp;*rectangle;&nbsp;/*&nbsp;Type&nbsp;to&nbsp;encode&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/</FONT>
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;asn_enc_rval_t&nbsp;ec;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;Encoder&nbsp;return&nbsp;value&nbsp;&nbsp;*/</FONT>
&nbsp;
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;/*&nbsp;Allocate&nbsp;the&nbsp;Rectangle_t&nbsp;*/</FONT>
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;rectangle&nbsp;=&nbsp;calloc(1,&nbsp;sizeof(Rectangle_t);&nbsp;/*&nbsp;not&nbsp;malloc!&nbsp;*/</FONT>
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;if(!rectangle)&nbsp;{</FONT>
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;perror(''calloc()&nbsp;failed'');</FONT>
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit(71);&nbsp;/*&nbsp;better,&nbsp;EX_OSERR&nbsp;*/</FONT>
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;}</FONT>
&nbsp;
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;/*&nbsp;Initialize&nbsp;the&nbsp;Rectangle&nbsp;members&nbsp;*/</FONT>
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;rectangle-&gt;height&nbsp;=&nbsp;42;&nbsp;&nbsp;/*&nbsp;any&nbsp;random&nbsp;value&nbsp;*/</FONT>
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;rectangle-&gt;width&nbsp;&nbsp;=&nbsp;23;&nbsp;&nbsp;/*&nbsp;any&nbsp;random&nbsp;value&nbsp;*/</FONT>
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;&nbsp;</FONT>
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;/*&nbsp;BER&nbsp;encode&nbsp;the&nbsp;data&nbsp;if&nbsp;filename&nbsp;is&nbsp;given&nbsp;*/</FONT>
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;if(ac&nbsp;&lt;&nbsp;2)&nbsp;{</FONT>
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fprintf(stderr,&nbsp;''Specify&nbsp;filename&nbsp;for&nbsp;BER&nbsp;output&#92;n'');</FONT>
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{</FONT>
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;const&nbsp;char&nbsp;*filename&nbsp;=&nbsp;av[1];</FONT>
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FILE&nbsp;*fp&nbsp;=&nbsp;fopen(filename,&nbsp;''w'');&nbsp;&nbsp;&nbsp;/*&nbsp;for&nbsp;BER&nbsp;output&nbsp;*/</FONT>
&nbsp;
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!fp)&nbsp;{</FONT>
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;perror(filename);</FONT>
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit(71);&nbsp;/*&nbsp;better,&nbsp;EX_OSERR&nbsp;*/</FONT>
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</FONT>
&nbsp;<FONT SIZE="-1">&nbsp;</FONT>
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;Encode&nbsp;the&nbsp;Rectangle&nbsp;type&nbsp;as&nbsp;BER&nbsp;(DER)&nbsp;*/</FONT>
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ec&nbsp;=&nbsp;der_encode(&amp;asn_DEF_Rectangle,</FONT>
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rectangle,&nbsp;write_out,&nbsp;stream);</FONT>
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fclose(fp);</FONT>
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(ec.encoded&nbsp;==&nbsp;-1)&nbsp;{</FONT>
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fprintf(stderr,</FONT>
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;''Could&nbsp;not&nbsp;encode&nbsp;Rectangle&nbsp;(at&nbsp;%s)&#92;n'',</FONT>
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ec.failed_type&nbsp;?&nbsp;ec.failed_type-&gt;name&nbsp;:&nbsp;''unknown'');</FONT>
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit(65);&nbsp;/*&nbsp;better,&nbsp;EX_DATAERR&nbsp;*/</FONT>
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{</FONT>
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fprintf(stderr,&nbsp;''Created&nbsp;%s&nbsp;with&nbsp;BER&nbsp;encoded&nbsp;Rectangle&#92;n'',</FONT>
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;filename);</FONT>
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</FONT>
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;}</FONT>
&nbsp;
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;/*&nbsp;Also&nbsp;print&nbsp;the&nbsp;constructed&nbsp;Rectangle&nbsp;XER&nbsp;encoded&nbsp;(XML)&nbsp;*/</FONT>
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;xer_fprint(stdout,&nbsp;&amp;asn_DEF_Rectangle,&nbsp;rectangle);</FONT>
&nbsp;
&nbsp;<FONT SIZE="-1">&nbsp;&nbsp;&nbsp;return&nbsp;0;&nbsp;/*&nbsp;Encoding&nbsp;finished&nbsp;successfully&nbsp;*/</FONT>
<FONT SIZE="-1">}</FONT>
</PRE>
</BLOCKQUOTE>
</LI>
<LI>Compile all files together using C compiler (varies by platform):
<P>
<BLOCKQUOTE><PRE>
<I>cc&nbsp;-I.&nbsp;-o</I>&nbsp;<B><I>rencode</I></B>&nbsp;<I>*.c</I>
</PRE>
</BLOCKQUOTE>
</LI>
<LI>Voila! You have just created the BER and XER encoder of a Rectangle
type, named <B>rencode</B>!
</LI>
</OL>
<P>
<H1><A NAME="SECTION04120000000000000000">
A ''Rectangle'' Decoder</A>
</H1> </H1>
<P> <P>
This chapter will help you to create a simple decoder of a simple This chapter will help you to create a simple BER decoder of a simple
''Rectangle'' type used throughout this document. ''Rectangle'' type used throughout this document.
<P> <P>
...@@ -1417,7 +1562,8 @@ it as it were a BER-encoded Rectangle type, and prints out the text ...@@ -1417,7 +1562,8 @@ it as it were a BER-encoded Rectangle type, and prints out the text
</BLOCKQUOTE> </BLOCKQUOTE>
</LI> </LI>
<LI>Voila! You have just created the Rectangle type decoder named <B>rdecode</B>! <LI>Voila! You have just created the BER decoder of a Rectangle type,
named <B>rdecode</B>!
</LI> </LI>
</OL> </OL>
<H2><A NAME="SECTION05000000000000000000"> <H2><A NAME="SECTION05000000000000000000">
...@@ -1442,7 +1588,7 @@ ISBN:0-12-6333361-0. ...@@ -1442,7 +1588,7 @@ ISBN:0-12-6333361-0.
not a definitive factor. not a definitive factor.
</DD> </DD>
<DT><A NAME="foot574">... this</A><A <DT><A NAME="foot739">... this</A><A
HREF="asn1c-usage.html#tex2html2"><SUP>2.2</SUP></A></DT> HREF="asn1c-usage.html#tex2html2"><SUP>2.2</SUP></A></DT>
<DD><I>-fnative-types</I> compiler option is used to produce basic C <I>int</I> <DD><I>-fnative-types</I> compiler option is used to produce basic C <I>int</I>
types instead of infinite width INTEGER_t structures. See <A HREF=#Table1>Table 1</A>. types instead of infinite width INTEGER_t structures. See <A HREF=#Table1>Table 1</A>.
...@@ -1454,19 +1600,19 @@ types instead of infinite width INTEGER_t structures. See <A HREF=#Table1>Table ...@@ -1454,19 +1600,19 @@ types instead of infinite width INTEGER_t structures. See <A HREF=#Table1>Table
text (XML) based. text (XML) based.
</DD> </DD>
<DT><A NAME="foot575">...asn1c</A><A <DT><A NAME="foot740">...asn1c</A><A
HREF="asn1c-usage.html#tex2html4"><SUP>3.1</SUP></A></DT> HREF="asn1c-usage.html#tex2html4"><SUP>3.1</SUP></A></DT>
<DD>The 1 symbol in asn<B>1</B>c is a digit, not an ''ell'' letter. <DD>The 1 symbol in asn<B>1</B>c is a digit, not an ''ell'' letter.
</DD> </DD>
<DT><A NAME="foot576">... specification</A><A <DT><A NAME="foot741">... specification</A><A
HREF="asn1c-usage.html#tex2html5"><SUP>3.2</SUP></A></DT> HREF="asn1c-usage.html#tex2html5"><SUP>3.2</SUP></A></DT>
<DD>This is probably <B>not</B> what you want to try out right now - <DD>This is probably <B>not</B> what you want to try out right now -
read through the rest of this chapter to find out about <B>-P</B> read through the rest of this chapter to find out about <B>-P</B>
and <B>-R</B> options. and <B>-R</B> options.
</DD> </DD>
<DT><A NAME="foot582">...that&nbsp;simple</A><A <DT><A NAME="foot747">...that&nbsp;simple</A><A
HREF="asn1c-usage.html#tex2html7"><SUP>4.1</SUP></A></DT> HREF="asn1c-usage.html#tex2html7"><SUP>4.1</SUP></A></DT>
<DD>Provided that you've also created a .c file with the <I>int main()</I> <DD>Provided that you've also created a .c file with the <I>int main()</I>
routine. routine.
...@@ -1479,7 +1625,7 @@ it will fail, but may later be invoked again with the rest of the ...@@ -1479,7 +1625,7 @@ it will fail, but may later be invoked again with the rest of the
buffer to continue decoding. buffer to continue decoding.
</DD> </DD>
<DT><A NAME="foot329">... encoding</A><A <DT><A NAME="foot322">... encoding</A><A
HREF="asn1c-usage.html#tex2html9"><SUP>4.3</SUP></A></DT> HREF="asn1c-usage.html#tex2html9"><SUP>4.3</SUP></A></DT>
<DD>It is actually faster too: the encoder might skip over some computations <DD>It is actually faster too: the encoder might skip over some computations
which aren't important for the size determination. which aren't important for the size determination.
...@@ -1488,7 +1634,7 @@ which aren't important for the size determination. ...@@ -1488,7 +1634,7 @@ which aren't important for the size determination.
</DL><BR><HR> </DL><BR><HR>
<ADDRESS> <ADDRESS>
Lev Walkin Lev Walkin
2005-01-17 2005-01-31
</ADDRESS> </ADDRESS>
</BODY> </BODY>
</HTML> </HTML>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment