Reputation: 549
I'm handling BER encoded Call Data Records (CDR). from GPRS Tunneling protocol. In which I got one field's value with '\r\n'
in it.
'\xa0\x06\x80\x04\r\n\xc4\x086'
-- This is the encoded string or bytearray
which causing the issue. It has all the TLV information required for the tag a0, and its length is 06. There is an inner tag 80 and its length is 04. But if we take the output in the following way it prints like this.
The inner tag 80's value causing the issue. Its length is 04 but when we decode it with pyasn1
the length became 05 since it counts \r
and \n
separately. I think the encoder which encodes this data assumes that \r\n
is a single element. But while decoding this using pyasn1 it throwing an error due to this missing length on the TLV representation of encoded value.
map(ord, '\xa0\x06\x80\x04\r\n\xc4\x086')
[160, 6, 128, 4, 13, 10, 196, 8, 54]
We are using implicit tag numbers.
Is there any way to solve this using pyasn1's ber decoder and encoder.
Thanks and Regards,
Haridas N.
Upvotes: 0
Views: 496
Reputation: 1521
I'm not familiar with pyasn1, but I'd suggest focusing on the data coming in, as that to me suggests that there's something treating what should be a binary set of bytes as text...
If the inner tag is really of len 4 then has a \n been replaced by a \r\n?
Upvotes: 1