ActivePerl Documentation
|
NAMEConvert::ASN1 - ASN.1 Encode/Decode library
SUPPORTED PLATFORMS
SYNOPSYSuse 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 = asn_recv($sock,$buffer,0); $nbytes = asn_read($fh, $buffer); $nbytes = asn_send($sock, $buffer, $peer); $nbytes = asn_send($sock, $buffer); $nbytes = asn_write($fh, $buffer); $buffer = asn_get($fh); $yes = asn_ready($fh)
DESCRIPTIONConvert::ASN1 encodes and decodes ASN.1 data structures using BER/DER rules.
METHODS
newContructor, creates a new object.
errorReturns the last error.
configure ( OPTIONS )Configure options to control how Convert::ASN1 will perform various tasks. Options are passed as name-value pairs.
Encode options
Decode options
prepare ( ASN )Compile the given ASN.1 descripton. The syntax used is very close to ASN.1, but has
a few differnces. 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 ( MACRO )Find a macro froma prepared ASN.1 description. Returns an object which can be used for encode/decode.
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.
decode ( PDU )Decode the PDU, returns a reference to a hash containg the values for the PDU. Returns undef if there was an error.
EXPORTSAs well as providing an object interface for encoding/decoding PDUs Convert::ASN1 also provides the follow functions.
IO Functions
Encode/Decode Functions
Constants
Debug Functions
EXPORT TAGS
MAPPING ASN.1 TO PERLEvery 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 },
]}
ExceptionsThere 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 {...}.
TODO
AUTHORGraham Barr <gbarr@pobox.xom>
COPYRIGHTCopyright (c) 2000 Graham Barr <gbarr@pobox.com>. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
|