From: Graham B. <gb...@us...> - 2002-03-25 07:46:11
|
Update of /cvsroot/perl-ldap/asn/lib/Convert In directory usw-pr-cvs1:/tmp/cvs-serv2349/lib/Convert Modified Files: ASN1.pm ASN1.pod Log Message: Patch from Wolfgang Laun Addition of prepare_file and the change prepare to accept a filehandle. POD updates. Fix decode of nested indefinate lengths Index: ASN1.pm =================================================================== RCS file: /cvsroot/perl-ldap/asn/lib/Convert/ASN1.pm,v retrieving revision 1.21 retrieving revision 1.22 diff -u -d -r1.21 -r1.22 --- ASN1.pm 10 Feb 2002 16:12:16 -0000 1.21 +++ ASN1.pm 25 Mar 2002 07:46:08 -0000 1.22 @@ -13,7 +13,7 @@ BEGIN { @ISA = qw(Exporter); - $VERSION = '0.15_01'; + $VERSION = '0.15_02'; %EXPORT_TAGS = ( io => [qw(asn_recv asn_send asn_read asn_write asn_get asn_ready)], @@ -128,17 +128,38 @@ my $asn = shift; $self = $self->new unless ref($self); - - my $tree = Convert::ASN1::parser::parse($asn); + my $tree; + if( ref($asn) eq 'GLOB' ){ + local $/ = undef; + my $txt = <$asn>; + $tree = Convert::ASN1::parser::parse($txt); + } else { + $tree = Convert::ASN1::parser::parse($asn); + } unless ($tree) { $self->{error} = $@; return; + ### If $self has been set to a new object, not returning + ### this object here will destroy the object, so the caller + ### won't be able to get at the error. } $self->{tree} = _pack_struct($tree); $self->{script} = (values %$tree)[0]; $self; +} + +sub prepare_file { + my $self = shift; + my $asnp = shift; + + local *ASN; + open( ASN, $asnp ) + or do{ $self->{error} = $@; return; }; + my $ret = $self->prepare( \*ASN ); + close( ASN ); + $ret; } # In XS the will convert the tree between perl and C structs Index: ASN1.pod =================================================================== RCS file: /cvsroot/perl-ldap/asn/lib/Convert/ASN1.pod,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- ASN1.pod 22 Jan 2002 11:24:28 -0000 1.5 +++ ASN1.pod 25 Mar 2002 07:46:08 -0000 1.6 @@ -155,14 +155,19 @@ =head2 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 +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 C<find> -must be called. +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 froma prepared ASN.1 description. Returns an object which can +Find a macro from a prepared ASN.1 description. Returns an object which can be used for encode/decode. =head2 encode ( VARIABLES ) @@ -178,7 +183,7 @@ =head1 EXPORTS As well as providing an object interface for encoding/decoding PDUs Convert::ASN1 -also provides the follow functions. +also provides the following functions. =head2 IO Functions @@ -193,7 +198,7 @@ cases the empty string will be returned. This is the same behaviour as the C<recv> function in perl itself. -It is reccomended that if the socket is of type SOCK_DGRAM then C<recv> +It is recommended that if the socket is of type SOCK_DGRAM then C<recv> be called directly instead of calling C<asn_recv>. =item asn_read FH, BUFFER, OFFSET @@ -223,7 +228,7 @@ 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 it's buffer +of the GLOB to use as its buffer: asn_buffer - input buffer asn_need - number of bytes needed for the next element, if known |