Manual Pages for UNIX Darwin command on man Convert::ASN1
MyWebUniversity

Manual Pages for UNIX Darwin command on man Convert::ASN1

Convert::ASN1(3) User Contributed Perl Documentation Convert::ASN1(3)

NAME

Convert::ASN1 - ASN.1 Encode/Decode library

SSYYNNOOPPSSYYSS

use Convert::ASN1;

$asn = Convert::ASN1->new;

$asn->prepare(q<

[APPLICATION 7] SEQUENCE { int INTEGER, str OCTET STRING } >);

$pdu = $asn->encode( int => 7, str => "string");

$out = $asn->decode($pdu);

print $out->{int}," ",$out->{str},"\n";

use Convert::ASN1 qw(:io);

$peer = asnrecv($sock,$buffer,0);

$nbytes = asnread($fh, $buffer);

$nbytes = asnsend($sock, $buffer, $peer);

$nbytes = asnsend($sock, $buffer);

$nbytes = asnwrite($fh, $buffer);

$buffer = asnget($fh);

$yes = asnready($fh)

DESCRIPTION

Convert::ASN1 encodes and decodes ASN.1 data structures using BER/DER

rules. MMEETTHHOODDSS nneeww Contructor, creates a new object. eerrrroorr Returns the last error. ccoonnffiigguurree (( OOPPTTIIOONNSS ))

Configure options to control how Convert::ASN1 will perform various

tasks. Options are passed as name-value pairs.

encode Reference to a hash which contains various encode options. decode Reference to a hash which contains various decode options. encoding One of 'BER' or 'DER'. The default is 'BER' Encode options real Which encoding to use for real's. One of 'binary', 'nr1', 'nr2', 'nr3' time This controls how UTCTime and GeneralizedTime elements are encoded. The default is "withzone". utctime The value passed will be encoded without a zone, ie a UTC value. 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 "timezone" configure option. raw The value passed should already be in the correct format and

will be copied into the PDU as-is.

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 overriden 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. 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 Decode options time This controls how a UTCTime or a GeneralizedTime element will be decoded. The default is "utctime". utctime The value returned will be a time value as returned by the "time" function. withzone The value returned will be a reference to an array of two values. The first is the same as with "utctime", the second is the timezone offset, in seconds, that was used in the encoding. raw The value returned will be the raw encoding as extracted from the PDU. 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. pprreeppaarree (( AASSNN )) Compile the given ASN.1 descripton 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 decribes only one macro then encode/decode can be called on this object. If ASN describes more than one ASN.1 macro then "find" must be called. The method returns undef on error. pprreeppaarreeffiillee (( AASSNNPPAATTHH )) Compile the ASN.1 description to be read from the specified pathname. ffiinndd (( MMAACCRROO )) Find a macro from a prepared ASN.1 description. Returns an object which can be used for encode/decode. eennccooddee (( VVAARRIIAABBLLEESS ))

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. ddeeccooddee (( PPDDUU )) Decode the PDU, returns a reference to a hash containg the values for the PDU. Returns undef if there was an error. EEXXPPOORRTTSS As well as providing an object interface for encoding/decoding PDUs

Convert::ASN1 also provides the following functions.

IIOO FFuunnccttiioonnss asnrecv SOCK, BUFFER, FLAGS Will read a single element from the socket SOCK into BUFFER. FLAGS may be MSGPEEK as exported by "Socket". Returns the address of the sender, or undef if there was an error. Some systems do not support the return of the peer address when the socket is a connected socket, in these cases the empty string will be returned. This is the same behaviour as the "recv" function in perl itself. It is recommended that if the socket is of type SOCKDGRAM then "recv" be called directly instead of calling "asnrecv". asnread FH, BUFFER, OFFSET asnread 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 asnrecv is used to read the element, so the same restiction applies if FH is a socket of type SOCKDGRAM. asnsend SOCK, BUFFER, FLAGS, TO asnsend SOCK, BUFFER, FLAGS Identical to calling "send", see perlfunc asnwrite FH, BUFFER Identical to calling "syswrite" with 2 arguments, see perlfunc asnget FH "asnget" provides buffered IO. Because it needs a buffer FH must be a GLOB or a reference to a GLOB. "asnget" will use two entries in the hash element of the GLOB to use as its buffer:

asnbuffer - input buffer

asnneed - number of bytes needed for the next element, if known

Returns an element or undef if there was an error. asnready FH "asnready" works with "asnget". It will return true if "asnget" has already read enough data into the buffer to return a complete element. EEnnccooddee//DDeeccooddee FFuunnccttiioonnss asntag asndecodetag asnencodetag asndecodelength asnencodelength CCoonnssttaannttss ASNBITSTR ASNBOOLEAN ASNENUMERATED ASNGENERALTIME ASNIA5STR ASNINTEGER ASNNULL ASNOBJECTID ASNOCTETSTR ASNPRINTSTR ASNREAL ASNSEQUENCE ASNSET ASNUTCTIME ASNAPPLICATION

ASNCONTEXT

ASNPRIVATE ASNUNIVERSAL ASNPRIMITIVE ASNCONSTRUCTOR ASNLONGLEN ASNEXTENSIONID ASNBIT DDeebbuugg FFuunnccttiioonnss asndump asnhexdump EEXXPPOORRTT TTAAGGSS :all All exported functions :const ASNBOOLEAN, ASNINTEGER, ASNBITSTR, ASNOCTETSTR, ASNNULL, ASNOBJECTID, ASNREAL, ASNENUMERATED, ASNSEQUENCE, ASNSET, ASNPRINTSTR, ASNIA5STR, ASNUTCTIME, ASNGENERALTIME, ASNUNIVERSAL,

ASNAPPLICATION, ASNCONTEXT, ASNPRIVATE, ASNPRIMITIVE,

ASNCONSTRUCTOR, ASNLONGLEN, ASNEXTENSIONID, ASNBIT :debug asndump, asndumphex :io asnrecv, asnsend, asnread, asnwrite, asnget, asnready :tag asntag, asndecodetag, asnencodetag, asndecodelength, asnencodelength MMAAPPPPIINNGG AASSNN..11 TTOO PPEERRLL Every element in the ASN.1 definition has a name, in perl a hash is used with these names as an index and the element value as the hash value.

# ASN.1

int INTEGER, str OCTET STRING

# Perl

{ int => 5, str => "text" } In the case of a SEQUENCE, SET or CHOICE then the value in the namespace will be a hash reference which will be the namespce for the elements with that element.

# ASN.1

int INTEGER, seq SEQUENCE { str OCTET STRING, bool BOOLEAN }

# Perl

{ int => 5, seq => { str => "text", bool => 1}} If the element is a SEQUENCE OF, or SET OF, then the value in the namespace will be an array reference. The elements in the array will be of the type expected by the type following the OF. For example with "SEQUENCE OF STRING" the array would contain strings. With "SEQUENCE OF SEQUENCE { ... }" the array will contain hash references which will be used as namespaces

# ASN.1

int INTEGER, str SEQUENCE OF OCTET STRING

# Perl

{ int => 5, str => [ "text1", "text2"]}

# ASN.1

int INTEGER, str SEQUENCE OF SEQUENCE { type OCTET STRING, value INTEGER }

# Perl

{ int => 5, str => [ { type => "abc", value => 4 },

{ type => "def", value => -1 },

]} EExxcceeppttiioonnss

There are some exceptions where Convert::ASN1 does not require an

element to be named. These are SEQUENCE {...}, SET {...} and CHOICE. In each case if the element is not given a name then the elements inside the {...} will share the same namespace as the elements outside of the {...}. TTOODDOO +o XS implementation. +o More documentation. +o More tests. AUTHOR Graham Barr , Report bugs via

COPYRIGHT

Copyright (c) 2000-2005 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.

perl v5.8.8 2006-02-21 Convert::ASN1(3)




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™