Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Convert-ASN1 CPAN distribution.

Report information
The Basics
Id: 12928
Status: resolved
Priority: 0/
Queue: Convert-ASN1

People
Owner: Nobody in particular
Requestors: javier.gutierrez [...] tap3edit.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: (no value)
Fixed in: (no value)



Subject: Convert-ASN1-0.19 new BCDString feature problem.
Hallo dear Graham, your module is awsome. Unfortunatelly I'm getting some problems with your last release Convert-ASN1-0.19. in the function "_enc_bcd", $str is -1 when the parameter of sprintf ($_[3]) is a big number, eg 9999999999. --function---------------------------------------------------- sub _enc_bcd { my $str = sprintf("%d",$_[3]); $str .= "F" if length($str) & 1; $_[4] .= asn_encode_length(length($str) / 2); $_[4] .= pack("H*", $str); } -------------------------------------------------------------- --example----------------------------------------------------- #!/usr/bin/perl -w use Convert::ASN1; $asn = Convert::ASN1->new; $asn->prepare(q< [APPLICATION 7] SEQUENCE { int INTEGER, str OCTET STRING, jav BCDString } Show quoted text
>);
$pdu = $asn->encode( int => 7, str => "string", jav =>"900019999911111" ); $out = $asn->decode($pdu); print $out->{int}," ",$out->{str}," ", $out->{jav},"\n"; ------------------------------------------------------------- I'm using linux over pentium (perl v5.8.3). cheers. Javier.
From: Graham Barr <gbarr [...] pobox.com>
Subject: Re: [cpan #12928] Convert-ASN1-0.19 new BCDString feature problem.
Date: Mon, 23 May 2005 14:58:06 -0500
To: bug-Convert-ASN1 [...] rt.cpan.org
RT-Send-Cc:
On May 23, 2005, at 12:03 PM, Guest via RT wrote: Show quoted text
> your module is awsome. Unfortunatelly I'm getting some problems with > your last release Convert-ASN1-0.19. > > in the function "_enc_bcd", $str is -1 when the parameter of sprintf > ($_[3]) is a big number, eg 9999999999.
Hm, I was not expecting a number larger than what can be stored in a perl number Try this change, it should work with Math::BigInt too Index: lib/Convert/ASN1/_encode.pm =================================================================== --- lib/Convert/ASN1/_encode.pm (revision 88) +++ lib/Convert/ASN1/_encode.pm (working copy) @@ -398,7 +398,7 @@ sub _enc_bcd { # 0 1 2 3 4 5 6 # $optn, $op, $stash, $var, $buf, $loop, $path - my $str = sprintf("%d",$_[3]); + my($str) = ("$_[3]" =~ /^(\d+)/)[0] || 0; $str .= "F" if length($str) & 1; $_[4] .= asn_encode_length(length($str) / 2); $_[4] .= pack("H*", $str); Graham.
From: Graham Barr <gbarr [...] pobox.com>
Subject: Re: [cpan #12928] Convert-ASN1-0.19 new BCDString feature problem.
Date: Mon, 23 May 2005 17:56:23 -0500
To: bug-Convert-ASN1 [...] rt.cpan.org
RT-Send-Cc:
On May 23, 2005, at 4:01 PM, javier.gutierrez@tap3edit.com via RT wrote: Show quoted text
> Such nice style the one you have! > But I think you forgot the "$" > > - my($str) = ("$_[3]" =~ /^(\d+)/)[0] || 0; > + my($str) = ("$_[3]" =~ /^(\d+)$/)[0] || 0; > > Otherwise if $_[3]="99999111A199999" => $str="99999111"
Yes, I was thinking about the $. But then before if you passed in 11A11 you would get 11 because that is how perl converts a string to a number. I wanted to stay away from giving a warning or croaking for bad data, because the rest of the code currently assumes that the user has already checked the data is valid. So I guess the question is, do you want it to encode "0" or "99999111" in the case above ? Graham.
From: Graham Barr <gbarr [...] pobox.com>
Subject: Re: [cpan #12928] Convert-ASN1-0.19 new BCDString feature problem.
Date: Tue, 24 May 2005 18:38:21 -0500
To: bug-Convert-ASN1 [...] rt.cpan.org
RT-Send-Cc:
On May 24, 2005, at 3:48 PM, javier.gutierrez@tap3edit.com via RT wrote: Show quoted text
> I see your point. Let's stick then to perls behaviour and leave it as > it is. > (without $). > Today I was struggling doing some other tests and what I am really > worried > about is the "0". In the GSM World is common to send sometimes these > fields > empty. So in this case if we decode and encode, all empty "" fields are > replaced by "0", which may cause troubles to some validation/billing > systems. > > So the correct line could be something like this: > - my($str) = ("$_[3]" =~ /^(\d+)/)[0] || 0; > + my($str) = ("$_[3]" =~ /^(\d+)/)[0] || ""; > > I don't know the impact on other systems but it would be great if you > can > implement it in this way.
I agree with your intent here. I was thinking after I sent my last replay that the RHS should be a string anyway. But the issue with this is that it would cause zero to be encoded as "", which is clearly wrong. So I suggest my $str = ("$_[3]" =~ /^(\d+)/) ? $1 : ""; So it is only "" if the match fails and not when the match matches "0" Graham.