Convert-ASN1
view release on metacpan or search on metacpan
lib/Convert/ASN1.pod view on Meta::CPAN
Default tagging conventions are normally given in the ASN.1 module definition (not supported by the parser). The ASN.1 spec states EXPLICIT tagging is the default, but this option has IMPLICIT tagging default for backward compatibility reasons.
=back
Encode options
=over 4
=item real
Which encoding to use for real's. One of 'binary', 'nr1', 'nr2', 'nr3'
=item time
This controls how UTCTime and GeneralizedTime elements are encoded. The default
is C<withzone>.
=over 4
=item utctime
The value passed will be encoded without a zone, ie a UTC value.
=item withzone
The value will be encoded with a zone. By default it will be encoded
using the local time offset. The offset may be set using the C<timezone>
configure option.
=item raw
The value passed should already be in the correct format and will be copied
into the PDU as-is.
=back
=item timezone
By default UTCTime and GeneralizedTime will be encoded using the local
time offset from UTC. This will over-ride that. It is an offset from UTC
in seconds. This option can be overridden by passing a reference to a
list of two values as the time value. The list should contain the time
value and the offset from UTC in seconds.
=item bigint
If during encoding an value greater than 32 bits is discovered and
is not already a big integer object, then the value will first be
converted into a big integer object. This option controls the big
integer class into which the objects will be blessed. The default
is to use Math::BigInt
=back
Decode options
=over 4
=item time
This controls how a UTCTime or a GeneralizedTime element will be decoded. The default
is C<utctime>.
=over 4
=item utctime
The value returned will be a time value as returned by the C<time> function.
=item withzone
The value returned will be a reference to an array of two values. The first is the
same as with C<utctime>, the second is the timezone offset, in seconds, that was
used in the encoding.
=item raw
The value returned will be the raw encoding as extracted from the PDU.
=back
=item bigint
If during decoding any big integers are discovered (integers greater
than 32 bits), they will be decoded into big integer objects. This option
controls the big integer class into which the objects will be blessed.
The default is to use Math::BigInt.
=item null
The value to decode ASN.1 NULL types into.
If not set, it defaults to C<1>.
=back
=head2 prepare ( ASN )
Compile the given ASN.1 description which can be passed as a string
or as a filehandle. The syntax used is very close to ASN.1, but has
a few differences. If the ASN describes only one macro then encode/decode can be
called on this object. If ASN describes more than one ASN.1 macro then C<find>
must be called. The method returns undef on error.
=head2 prepare_file ( ASNPATH )
Compile the ASN.1 description to be read from the specified pathname.
=head2 find ( MACRO )
Find a macro from a prepared ASN.1 description. Returns an object which can
be used for encode/decode.
=head2 encode ( VARIABLES )
Encode a PDU. Top-level variable are passed as name-value pairs, or as a reference
to a hash containing them. Returns the encoded PDU, or undef on error.
=head2 decode ( PDU )
Decode the PDU, returns a reference to a hash containing the values for the PDU. Returns
undef if there was an error.
=head2 registeroid ( OID, HANDLER )
Register a handler for all ASN.1 elements
that are C<DEFINED BY> the given OID.
B<HANDLER> must be a Convert::ASN1 object, e.g. as returned by L</"find ( MACRO )">.
=head2 registertype ( NAME, OID, HANDLER )
Register a handler for all ASN.1 elements named C<NAME>,
that are C<DEFINED BY> the given OID.
B<HANDLER> must be a Convert::ASN1 object, e.g. as returned by L</"find ( MACRO )">.
=head1 EXPORTS
As well as providing an object interface for encoding/decoding PDUs Convert::ASN1
also provides the following functions.
=head2 IO Functions
=over 4
lib/Convert/ASN1.pod view on Meta::CPAN
=item asn_read ( FH, BUFFER )
Will read a single element from the filehandle FH into BUFFER. Returns the
number of bytes read if a complete element was read, -1 if an incomplete
element was read or undef if there was an error. If OFFSET is specified
then it is assumed that BUFFER already contains an incomplete element
and new data will be appended starting at OFFSET.
If FH is a socket the asn_recv is used to read the element, so the same
restriction applies if FH is a socket of type SOCK_DGRAM.
=item asn_send ( SOCK, BUFFER, FLAGS, TO )
=item asn_send ( SOCK, BUFFER, FLAGS )
Identical to calling C<send>, see L<perlfunc>
=item asn_write ( FH, BUFFER )
Identical to calling C<syswrite> with 2 arguments, see L<perlfunc>
=item asn_get ( FH )
C<asn_get> provides buffered IO. Because it needs a buffer FH must be a GLOB
or a reference to a GLOB. C<asn_get> will use two entries in the hash element
of the GLOB to use as its buffer:
asn_buffer - input buffer
asn_need - number of bytes needed for the next element, if known
Returns an element or undef if there was an error.
=item asn_ready ( FH )
C<asn_ready> works with C<asn_get>. It will return true if C<asn_get> has already
read enough data into the buffer to return a complete element.
=back
=head2 Encode/Decode Functions
=over 4
=item asn_tag ( CLASS, VALUE )
Given B<CLASS> and a B<VALUE>, calculate an integer which when encoded
will become the tag.
=item asn_decode_tag ( TAG )
Decode the given ASN.1 encoded C<TAG>.
=item asn_encode_tag ( TAG )
Encode B<TAG> value for encoding.
We assume that the tag has been correctly generated with L</"asn_tag ( CLASS, VALUE )">.
=item asn_decode_length ( LEN )
Decode the given ASN.1 decoded C<LEN>.
=item asn_encode_length ( LEN )
Encode the given C<LEN> to its ASN.1 encoding.
=back
=head2 Constants
=over 4
=item ASN_BIT_STR
=item ASN_BOOLEAN
=item ASN_ENUMERATED
=item ASN_GENERAL_TIME
=item ASN_IA5_STR
=item ASN_INTEGER
=item ASN_NULL
=item ASN_OBJECT_ID
=item ASN_OCTET_STR
=item ASN_PRINT_STR
=item ASN_REAL
=item ASN_SEQUENCE
=item ASN_SET
=item ASN_UTC_TIME
=item ASN_APPLICATION
=item ASN_CONTEXT
=item ASN_PRIVATE
=item ASN_UNIVERSAL
=item ASN_PRIMITIVE
=item ASN_CONSTRUCTOR
=item ASN_LONG_LEN
=item ASN_EXTENSION_ID
=item ASN_BIT
=back
=head2 Debug Functions
( run in 1.991 second using v1.01-cache-2.11-cpan-39bf76dae61 )