home *** CD-ROM | disk | FTP | other *** search
-
- <HTML>
- <HEAD>
- <TITLE>Convert::BER - ASN.1 Basic Encoding Rules</TITLE>
- <LINK REL="stylesheet" HREF="../../../Active.css" TYPE="text/css">
- <LINK REV="made" HREF="mailto:">
- </HEAD>
-
- <BODY>
- <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
- <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
- <STRONG><P CLASS=block> Convert::BER - ASN.1 Basic Encoding Rules</P></STRONG>
- </TD></TR>
- </TABLE>
-
- <A NAME="__index__"></A>
- <!-- INDEX BEGIN -->
-
- <UL>
-
- <LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
-
- <LI><A HREF="#synopsis">SYNOPSIS</A></LI>
- <LI><A HREF="#note">NOTE</A></LI>
- <LI><A HREF="#description">DESCRIPTION</A></LI>
- <LI><A HREF="#methods">METHODS</A></LI>
- <UL>
-
- <LI><A HREF="#io methods">IO METHODS</A></LI>
- </UL>
-
- <LI><A HREF="#oplist">OPLIST</A></LI>
- <LI><A HREF="#special operators">SPECIAL OPERATORS</A></LI>
- <LI><A HREF="#tags">TAGS</A></LI>
- <LI><A HREF="#subclassing">SUB-CLASSING</A></LI>
- <UL>
-
- <LI><A HREF="#defining new packing operators">DEFINING NEW PACKING OPERATORS</A></LI>
- </UL>
-
- <LI><A HREF="#limitations">LIMITATIONS</A></LI>
- <LI><A HREF="#bugs">BUGS</A></LI>
- <LI><A HREF="#author">AUTHOR</A></LI>
- <LI><A HREF="#copyright">COPYRIGHT</A></LI>
- </UL>
- <!-- INDEX END -->
-
- <HR>
- <P>
- <H1><A NAME="name">NAME</A></H1>
- <P>Convert::BER - ASN.1 Basic Encoding Rules</P>
- <P>
- <HR>
- <H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
- <UL>
- <LI>Linux</LI>
- <LI>Solaris</LI>
- <LI>Windows</LI>
- </UL>
- <HR>
- <H1><A NAME="synopsis">SYNOPSIS</A></H1>
- <PRE>
- use Convert::BER;
- </PRE>
- <PRE>
-
- $ber = new Convert::BER;</PRE>
- <PRE>
-
- $ber->encode(
- INTEGER => 1,
- SEQUENCE => [
- STRING => [ qw(a b c) ]
- ]
- );</PRE>
- <PRE>
-
- $ber->decode(
- INTEGER => \$i,
- SEQUENCE => [
- STRING => \@str
- ]
- );</PRE>
- <PRE>
-
- $ber->buffer("");</PRE>
- <PRE>
-
- $ber->encode(
- SEQUENCE_OF => [ \%hash
- STRING => sub { $_[0] },
- INTEGER => sub { $hash{ $_[0] } }
- ]
- );</PRE>
- <PRE>
-
- $ber->decode(
- SEQUENCE_OF => [ \$count
- STRING => sub { push @keys, undef; \$keys[-1] },
- INTEGER => sub { push @values, undef; \$values[-1] }
- ]
- );</PRE>
- <P>
- <HR>
- <H1><A NAME="note">NOTE</A></H1>
- <P><STRONG>This documentation is still under construction. Convert::BER is a</STRONG>
- <STRONG>a very flexable package that supports a lot of options. see the</STRONG>
- <STRONG>tests in t/ for examples</STRONG></P>
- <P>
- <HR>
- <H1><A NAME="description">DESCRIPTION</A></H1>
- <P><CODE>Convert::BER</CODE> provides an OO interface to encoding and decoding
- data into packets using the ASN.1 Basic Encoding Rules (BER)</P>
- <P>
- <HR>
- <H1><A NAME="methods">METHODS</A></H1>
- <DL>
- <DT><STRONG><A NAME="item_new">new</A></STRONG><BR>
- <DD>
- <DT><STRONG>new ( BUFFER )</STRONG><BR>
- <DD>
- <DT><STRONG>new ( opList )</STRONG><BR>
- <DD>
- <A HREF="#item_new"><CODE>new</CODE></A> creates a new <CODE>Convert::BER</CODE> object.
- <P></P>
- <DT><STRONG><A NAME="item_encode">encode ( opList )</A></STRONG><BR>
- <DD>
- Encode data in <EM>opList</EM> appending to the data in the buffer.
- <P></P>
- <DT><STRONG><A NAME="item_decode">decode ( opList )</A></STRONG><BR>
- <DD>
- Decode the data in the buffer as described by <EM>opList</EM>, starting
- where the last decode finished or position set by <A HREF="#item_pos"><CODE>pos</CODE></A>
- <P></P>
- <DT><STRONG><A NAME="item_buffer">buffer ( [ BUFFER ] )</A></STRONG><BR>
- <DD>
- Return the buffer contents. If <EM>BUFFER</EM> is specified the set the buffer
- contents and reset pos to zero.
- <P></P>
- <DT><STRONG><A NAME="item_pos">pos ( [ POS ] )</A></STRONG><BR>
- <DD>
- Without any arguments <A HREF="#item_pos"><CODE>pos</CODE></A> returns the offset where the last decode
- finished, or the last offset set by <A HREF="#item_pos"><CODE>pos</CODE></A>. If <EM>POS</EM> is specified
- then <EM>POS</EM> will be where the next decode starts.
- <P></P></DL>
- <P>
- <H2><A NAME="io methods">IO METHODS</A></H2>
- <DL>
- <DT><STRONG><A NAME="item_read">read ( IO )</A></STRONG><BR>
- <DD>
- <DT><STRONG><A NAME="item_write">write ( IO )</A></STRONG><BR>
- <DD>
- <DT><STRONG><A NAME="item_recv">recv ( SOCK )</A></STRONG><BR>
- <DD>
- <DT><STRONG><A NAME="item_send">send ( SOCK [, ADDR ] )</A></STRONG><BR>
- <DD>
- </DL>
- <P>
- <HR>
- <H1><A NAME="oplist">OPLIST</A></H1>
- <P>An <EM>opList</EM> is a list of <EM>operator</EM>-<EM>value</EM> pairs. An operator can
- be any defined below, or any defined by a sub-class of <CODE>Convert::BER</CODE>,
- which will probably be derived from the primitives given here.</P>
- <P>For the following operators if encoding the <EM>value</EM> is the value of the
- data to be encoded, if decoding it is a reference to where the decoded
- will be put.</P>
- <P>If <EM>value</EM> is a reference to a list then, for encode each item in the list
- will be encoded in turn. If decoding then as many a possible items of
- teh given type will be decoded an placed into the array, but there must be
- at least one or the whole decode will fail.</P>
- <P>If <EM>value</EM> is a CODE reference, then the code will be evaluated and the
- result used. For encode the code should return either the data to be encoded
- or a reference to a list of data to be encoded. For decode the code should
- return a reference to where the decoded data should be placed or a
- reference to a list. The arguments that are passed to the code are described
- below in the <A HREF="#item_SEQUENCE_OF"><CODE>SEQUENCE_OF</CODE></A> section.</P>
- <DL>
- <DT><STRONG><A NAME="item_BOOLEAN">BOOLEAN</A></STRONG><BR>
- <DD>
- <DT><STRONG><A NAME="item_INTEGER">INTEGER</A></STRONG><BR>
- <DD>
- <DT><STRONG><A NAME="item_STRING">STRING</A></STRONG><BR>
- <DD>
- <DT><STRONG><A NAME="item_NULL">NULL</A></STRONG><BR>
- <DD>
- <DT><STRONG><A NAME="item_OBJECT_ID">OBJECT_ID</A></STRONG><BR>
- <DD>
- <DT><STRONG><A NAME="item_ENUM">ENUM</A></STRONG><BR>
- <DD>
- </DL>
- <P>Other operators avaliable are</P>
- <DL>
- <DT><STRONG><A NAME="item_BIT_STRING">BIT_STRING</A></STRONG><BR>
- <DD>
- A bit string is represented as a string of <CODE>0</CODE>'s and <CODE>1</CODE>'s, these sequences
- can be packed using the perl <A HREF="../../../lib/Pod/perlfunc.html#item_pack"><CODE>pack</CODE></A> operator and the character <CODE>B</CODE>, but
- in doing so the number of bits will be rounded up to a multiple of 8
- <P></P>
- <DT><STRONG><A NAME="item_SEQUENCE">SEQUENCE</A></STRONG><BR>
- <DD>
- A SEQUENCE can be encoded ....
- <P></P>
- <DT><STRONG><A NAME="item_SET">SET</A></STRONG><BR>
- <DD>
- A set it treated in an identical way to a SEQUENCE.
- <P></P>
- <DT><STRONG><A NAME="item_SEQUENCE_OF">SEQUENCE_OF</A></STRONG><BR>
- <DD>
- </DL>
- <P>
- <HR>
- <H1><A NAME="special operators">SPECIAL OPERATORS</A></H1>
- <DL>
- <DT><STRONG><A NAME="item_BER">BER</A></STRONG><BR>
- <DD>
- <STRONG>Encode</STRONG>: <EM>value</EM> should be a <CODE>Convert::BER</CODE> object, which will
- be inserted into the buffer. If <EM>value</EM> is undefined then nothing
- is added.
- <P><STRONG>Decode</STRONG>: <EM>value</EM> should be a reference to a scalar, which will
- contain a <CODE>Convert::BER</CODE> object. This object will contain the
- remainder of the current sequence.</P>
- <P></P>
- <DT><STRONG><A NAME="item_ANY">ANY</A></STRONG><BR>
- <DD>
- Like <A HREF="#item_BER"><CODE>BER</CODE></A> except that when decoding only the next item is
- decoded and placed into the <CODE>Convert::BER</CODE> object returned.
- <P></P>
- <DT><STRONG><A NAME="item_OPTIONAL">OPTIONAL</A></STRONG><BR>
- <DD>
- The <EM>value</EM> to this operator must be a reference to an <EM>opList</EM>.
- <P><STRONG>Encode</STRONG>: The contents <EM>value</EM> are encoded into the buffer, providing
- no entry in the list is undefined.</P>
- <P><STRONG>Decode</STRONG>: The contents of <EM>value</EM> are decoded if possible, if
- not then decode continues at the next <EM>operator</EM>-<EM>value</EM> pair.</P>
- <P></P></DL>
- <P>
- <HR>
- <H1><A NAME="tags">TAGS</A></H1>
- <P>Each operator, other than the special operators, has a tag value
- associated with it. Some applications require these tag values
- to be different from the default values. <CODE>Convert::BER</CODE> supports
- two ways of doing this. One method is to sub-class <CODE>Convert::BER</CODE>,
- which is described in the next section. For small applications or those
- that think sub-classing is just too much then the operatorm may be
- passed an arrayref. The array must contain two elements, the first
- is the usual operator name and the second if the tag value to use, as
- shown below.</P>
- <PRE>
- $ber->encode(
- [ SEQUENCE => 0x34 ] => [
- INTEGER => 10,
- STRING => "A"
- ]
- );</PRE>
- <P>This will encode a sequence, with a tag value of <CODE>0x34</CODE>, which will contain
- and integer and a string which will have thier default tag values.</P>
- <P>
- <HR>
- <H1><A NAME="subclassing">SUB-CLASSING</A></H1>
- <P>For large applications where operators with non default tags are used a lot
- the above maechanism can be very erroroneous, for this porpose <CODE>Convert::BER</CODE>
- may be sub-classed.</P>
- <P>To do this the sub-class must call a method <CODE>define</CODE> as a static method
- on the sub-class. The arguments to <CODE>define</CODE> is a list if arrayref's. Each
- arrayref will define one new operator. Each arrayref contains three values,
- the first is the name of the operator, the second is how the data is encoded
- and the third is the tag value. To aid with the creation of these arguments
- <CODE>Convert::BER</CODE> exports some variables and constant subroutines.</P>
- <P>For each operator defined by <CODE>Convert::BER</CODE>, or a <CODE>Convert::BER</CODE> sub-class,
- a scalar variable with the same name is avaliable for import,
- for example <CODE>$INTEGER</CODE> is avaliable from <CODE>Convert::BER</CODE>. And any operators
- defined by a new sub-class will be avaliable for import from that class.
- One of these variables may be used as the second element of each arrayref.</P>
- <P><CODE>Convert::BER</CODE> also exports some constant subroutines that can be used
- to create the tag value. The subroutines exported are.</P>
- <PRE>
- BER_BOOLEAN
- BER_INTEGER
- BER_BIT_STR
- BER_OCTET_STR
- BER_NULL
- BER_OBJECT_ID
- BER_SEQUENCE
- BER_SET
- </PRE>
- <PRE>
-
- BER_UNIVERSAL
- BER_APPLICATION
- BER_CONTEXT
- BER_PRIVATE
- BER_PRIMITIVE
- BER_CONSTRUCTOR</PRE>
- <P>Using this information a sub-class of Convert::BER can be created as shown
- below.</P>
- <PRE>
- package Net::LDAP::BER;</PRE>
- <PRE>
- use Convert::BER qw(/^(\$|BER_)/);</PRE>
- <PRE>
- use strict;
- use vars qw($VERSION @ISA);</PRE>
- <PRE>
- @ISA = qw(Convert::BER);
- $VERSION = "1.00";</PRE>
- <PRE>
- Net::LDAP::BER->define(</PRE>
- <PRE>
- # Name Type Tag
- ########################################</PRE>
- <PRE>
- [ REQ_UNBIND => $NULL,
- BER_APPLICATION | 0x02 ],
- </PRE>
- <PRE>
-
- [ REQ_COMPARE => $SEQUENCE,
- BER_APPLICATION | BER_CONSTRUCTOR | 0x0E ],</PRE>
- <PRE>
-
- [ REQ_ABANDON => $INTEGER,
- BER_APPLICATION | 0x10 ],
- );</PRE>
- <P>This will create a new class <CODE>Net::LDAP::BER</CODE> which has three new operators
- avaliable. This class then may be used as follows</P>
- <PRE>
- $ber = new Net::LDAP::BER;
- </PRE>
- <PRE>
-
- $ber->encode(
- REQ_UNBIND => 0,
- REQ_COMPARE => [
- REQ_ABANDON => 123,
- ]
- );</PRE>
- <PRE>
- $ber->decode(
- REQ_UNBIND => \$var,
- REQ_COMPARE => [
- REQ_ABANDON => \$num,
- ]
- );</PRE>
- <P>Which will encode or decode the data using the formats and tags defined in
- the <CODE>Net::LDAP::BER</CODE> sub-class. It also helps to make the code more readable.</P>
- <P>
- <H2><A NAME="defining new packing operators">DEFINING NEW PACKING OPERATORS</A></H2>
- <P>As well as defining new operators which inherit from existing operators
- it is also possible to define a new operator and how data is encoded
- and decoded. The interface for doing this is still changing but
- will be documented here when it is done. to be continued ...</P>
- <P>
- <HR>
- <H1><A NAME="limitations">LIMITATIONS</A></H1>
- <P>Convert::BER cannot support tags that contain more bits than
- can be stored in a scalar variable, typically this is 32 bits.</P>
- <P>Convert::BER cannot support items that have a packed length which cannot be
- stored in 32 bits</P>
- <DL>
- <DT><STRONG><A NAME="item_TODO">TODO</A></STRONG><BR>
- <DD>
- CONSTRUCTED operator
- <P></P></DL>
- <P>
- <HR>
- <H1><A NAME="bugs">BUGS</A></H1>
- <P>None known, but there may be some</P>
- <P>
- <HR>
- <H1><A NAME="author">AUTHOR</A></H1>
- <P>Graham Barr <<EM><A HREF="mailto:gbarr@pobox.com">gbarr@pobox.com</A></EM>></P>
- <P>
- <HR>
- <H1><A NAME="copyright">COPYRIGHT</A></H1>
- <P>Copyright (c) 1995-1999 Graham Barr. All rights reserved.
- This program is free software; you can redistribute it and/or modify it
- under the same terms as Perl itself.</P>
- <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
- <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
- <STRONG><P CLASS=block> Convert::BER - ASN.1 Basic Encoding Rules</P></STRONG>
- </TD></TR>
- </TABLE>
-
- </BODY>
-
- </HTML>
-