By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,825 Members | 957 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,825 IT Pros & Developers. It's quick & easy.

Pyasn1 decoding with OS Specific carriage return --' \r\n'

P: 1
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 [b]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.
Feb 4 '13 #1
Share this Question
Share on Google+
1 Reply

bvdet
Expert Mod 2.5K+
P: 2,851
I don't know anything about pyasn1 or the data you are describing. If you could strip out the '\r', would that help with your issue?
Expand|Select|Wrap|Line Numbers
  1. >>> "".join('\xa0\x06\x80\x04\r\n\xc4\x086'.split("\r"))
  2. '\xa0\x06\x80\x04\n\xc4\x086'
  3. >>> "".join([chr(n) for n in map(ord, '\xa0\x06\x80\x04\r\n\xc4\x086') if n != 13])
  4. '\xa0\x06\x80\x04\n\xc4\x086'
  5. >>> 
Feb 7 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.