esnacc / esnacc-ng

A continuation of the Enhanced SNACC ASN.1 compiler - See http://mail.esnacc.org/mailman/listinfo/dev
http://esnacc.org
GNU General Public License v2.0
32 stars 30 forks source link

Correct PrintXML of OCTET STRING #50

Closed jarek556 closed 1 year ago

jarek556 commented 5 years ago

PrintXML presents Identifier ::= OCTET STRING as <OCTET_STRING>Identifier-'3132333435'H -- "12345" --</OCTET_STRING> With attached patch OCTET STRING will be presented as: <Identifier typeName="OCTET_STRING">3132333435</Identifier>

=============================================

--- a/cxx-lib/src/asn-octs.cpp
+++ b/cxx-lib/src/asn-octs.cpp
@@ -89,19 +89,28 @@ void AsnOcts::PrintXML (std::ostream &os, const char *lpszTitle,
     const char *tagName = "OCTET_STRING";
     if (lpszType)
         tagName = lpszType;
-    os << "<" << tagName << ">";
+    //os << "<" << tagName << ">";
+    if( lpszTitle )
+        os << "<" << lpszTitle << " typeName=\"" << tagName << "\">";
+    else
+        os << "<" << tagName << ">";

     std::ios_base::fmtflags old_flags = os.flags();
     os << std::hex;
     for (size_t i = 0; i < Len(); ++i) {
+       if( (unsigned int)(c_ustr()[i]) < 16 )
+               os << '0';
         os << (unsigned int)(c_ustr()[i]);
     }
     os.flags(old_flags);

-    if (lpszType)
-        os << "</" << lpszType << ">\n";
+    //if (lpszType)
+    //    os << "</" << lpszType << ">\n";
+    //else
+    if( lpszTitle )
+        os << "</" << lpszTitle << ">\n";
     else
-        os << "</OCTET_STRING>\n";
+        os << "</" << tagName << ">";
 }

 // Prints the AsnOcts to the given ostream in Value Notation.
apconole commented 5 years ago

Which branch were you using to get this result? Latest branch should present:

HEX

So you'd like to change it to HEX ?

jarek556 commented 5 years ago

W dniu 15.10.2019, wto o godzinie 08∶19 -0700, użytkownik Aaron Conole napisał:

Which branch were you using to get this result?  Latest branch should present:

It is possible that the value:  Identifier-'3132333435'H  -- "12345" -- was from some older release. Anyway latest version is still far from perfect: beside the tag name,presented HEX value is invalid because every byte less than 0x10 is presented as one hex digit, so the hex string of 010203 will be presented as 123. best regardsJaroslaw Tabor

[ { "@context": "http://schema.org", "@type": "EmailMessage", "potentialAction": { "@type": "ViewAction", "target": "https://github.com/esnacc/esnacc-ng/issues/50?email_source =notifications\u0026email_token=ADGYJGDJTOD37WUBFZ2GXWLQOXNR5A5CNFSM4 I6CAKP2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEB JFGAI#issuecomment-542266113", "url": "https://github.com/esnacc/esnacc-ng/issues/50?email_source=no tifications\u0026email_token=ADGYJGDJTOD37WUBFZ2GXWLQOXNR5A5CNFSM4I6C AKP2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBJFG AI#issuecomment-542266113", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { "@type": "Organization", "name": "GitHub", "url": "https://github.com" } } ]

apconole commented 5 years ago

Agreed, I'll submit a fix for that. Will the latest version (with the aforementioned fix) suffice?

apconole commented 5 years ago

I plan to submit the following to the list today (after I test):

diff --git a/cxx-lib/src/asn-octs.cpp b/cxx-lib/src/asn-octs.cpp
index 228774d..e857fd6 100644
--- a/cxx-lib/src/asn-octs.cpp
+++ b/cxx-lib/src/asn-octs.cpp
@@ -2,6 +2,7 @@
 #include "asn-incl.h"

 #include <stdlib.h>
+#include <iomanip>

 _BEGIN_SNACC_NAMESPACE

@@ -92,7 +93,7 @@ void AsnOcts::PrintXML (std::ostream &os, const char *lpszTitle,
     os << "<" << tagName << ">";

     std::ios_base::fmtflags old_flags = os.flags();
-    os << std::hex;
+    os << std::hex << std::setw(2) << std::setfill('0');
     for (size_t i = 0; i < Len(); ++i) {
         os << (unsigned int)(c_ustr()[i]);
     }
apconole commented 1 year ago

Closing this now.