|
From: Graham B. <gb...@us...> - 2003-10-08 12:28:15
|
Update of /cvsroot/perl-ldap/asn/lib/Convert/ASN1
In directory sc8-pr-cvs1:/tmp/cvs-serv15157/Convert/ASN1
Modified Files:
_encode.pm
Log Message:
Fix bug in encoding BIT STRINGS where chr() was causing an upgrade to UTF8
Index: _encode.pm
===================================================================
RCS file: /cvsroot/perl-ldap/asn/lib/Convert/ASN1/_encode.pm,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- _encode.pm 6 May 2003 21:29:07 -0000 1.18
+++ _encode.pm 8 Oct 2003 12:28:09 -0000 1.19
@@ -106,21 +106,27 @@
sub _enc_bitstring {
# 0 1 2 3 4 5 6
# $optn, $op, $stash, $var, $buf, $loop, $path
+ my $vref = ref($_[3]) ? \($_[3]->[0]) : \$_[3];
+
+ if (CHECK_UTF8 and Encode::is_utf8($$vref)) {
+ utf8::encode(my $tmp = $$vref);
+ $vref = \$tmp;
+ }
if (ref($_[3])) {
my $less = (8 - ($_[3]->[1] & 7)) & 7;
my $len = ($_[3]->[1] + 7)/8;
$_[4] .= asn_encode_length(1+$len);
$_[4] .= chr($less);
- $_[4] .= substr($_[3]->[0], 0, $len);
+ $_[4] .= substr($$vref, 0, $len);
if ($less && $len) {
- substr($_[4],-1) &= chr(0xff << $less);
+ substr($_[4],-1) &= chr((0xff << $less) & 0xff);
}
}
else {
- $_[4] .= asn_encode_length(1+length $_[3]);
+ $_[4] .= asn_encode_length(1+length $$vref);
$_[4] .= chr(0);
- $_[4] .= $_[3];
+ $_[4] .= $$vref;
}
}
|