From edd8dc56425a6f85b88a5328d28b536a8218cbdc Mon Sep 17 00:00:00 2001 From: oana Date: Thu, 13 Jun 2013 13:59:33 +0000 Subject: [PATCH] Bug fix: when encoding a long ASN.1 tag, insert it at the beginning of the payload, not at the end. git-svn-id: http://voip.null.ro/svn/yate@5543 acf43c95-373e-0410-b603-e72c3f656dc1 --- libs/yasn/asn.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/libs/yasn/asn.cpp b/libs/yasn/asn.cpp index efb09c68..a50b922b 100644 --- a/libs/yasn/asn.cpp +++ b/libs/yasn/asn.cpp @@ -1270,14 +1270,15 @@ void AsnTag::encode(Class clas, Type type, unsigned int code, DataBlock& data) } else { u_int8_t last = clas | type | 31; - data.append(&last,sizeof(last)); + DataBlock coding; + coding.append(&last,sizeof(last)); int size = sizeof(unsigned int); bool start = false; while (size > 1) { u_int8_t msb = (code >> ((size - 1) * 8)); if (start) { msb |= 0x80; - data.append(&msb,sizeof(msb)); + coding.append(&msb,sizeof(msb)); } else { if (msb == 0) { @@ -1287,18 +1288,19 @@ void AsnTag::encode(Class clas, Type type, unsigned int code, DataBlock& data) else { start = true; msb |= 0x80; - data.append(&msb,sizeof(msb)); + coding.append(&msb,sizeof(msb)); } } size--; } last = code; - data.append(&last,sizeof(last)); + coding.append(&last,sizeof(last)); + data.insert(coding); } #ifdef XDEBUG String str; str.hexify(data.data(),data.length(),' '); - XDebug(s_libName.c_str(),DebugAll,"AsnTag::encode(clas=0x%x, type=0x%x, code=%u) tag=%s",clas,type,code,str.c_str()); + Debug(s_libName.c_str(),DebugAll,"AsnTag::encode(clas=0x%x, type=0x%x, code=%u) tag=%s",clas,type,code,str.c_str()); #endif }