1#!/usr/local/bin/perl 2 3# 4# Test the use of utf8 strings 5# 6 7use Convert::ASN1; 8BEGIN { require './t/funcs.pl' } 9 10if ($] < 5.007) { 11 print "1..0\n"; 12 exit; 13} 14 15print "1..12\n"; 16 17btest 1, $asn = Convert::ASN1->new() or warn $asn->error; 18btest 2, $asn->prepare(q( 19 str STRING 20)) or warn $asn->error; 21 22my $result = pack("C*", 0x04, 0x07, 0x75, 0x74, 0x66, 0x38, 0x20, 0xc6, 0x81); 23stest 3, $result, $asn->encode(str => "utf8 " . chr(0x181)) or warn $asn->error; 24 25btest 4, $ret = $asn->decode($result) or warn $asn->error; 26stest 5, "utf8 " . chr(0xc6) . chr(0x81), $ret->{str}; 27 28 29btest 6, $asn->prepare(q( 30 str UTF8String 31)) or warn $asn->error; 32my $utf_str = "utf8 " . chr(0x181); 33 34$result = pack("C*", 0x0c, 0x07, 0x75, 0x74, 0x66, 0x38, 0x20, 0xc6, 0x81); 35stest 7, $result, $asn->encode(str => $utf_str) or warn $asn->error; 36 37btest 8, $ret = $asn->decode($result) or warn $asn->error; 38stest 9, $utf_str, $ret->{str}; 39 40# Test that UTF8String will upgrade on encoding 41$result = pack("C*", 0x0c, 0x02, 0xc2, 0x81); 42stest 10, $result, $asn->encode(str => chr(0x81)) or warn $asn->error; 43 44btest 11, $ret = $asn->decode($result) or warn $asn->error; 45stest 12, chr(0x81), $ret->{str}; 46