]> WPIA git - cassiopeia.git/blobdiff - src/slipBio.cpp
upd: move more code to remoteSigner
[cassiopeia.git] / src / slipBio.cpp
index 5baae773cb55f084e3a9d99b414b83489031961c..ced5a6fb4639a6a6dafbcacb96b4055f993e4136 100644 (file)
@@ -21,20 +21,15 @@ char hexDigit( char c ) {
 }
 
 std::string toHex( const char* buf, int len ) {
-    char* c = ( char* ) malloc( len * 2 );
-
-    if( !c ) {
-        return "<malloc fail>";
-    }
-
-    std::shared_ptr<char> mem = std::shared_ptr<char>( c, free );
+    std::string data = "000000";
 
     for( int i = 0; i < len; i++ ) {
-        c[i * 2] = hexDigit( ( buf[i] >> 4 ) & 0xF );
-        c[i * 2 + 1] = hexDigit( buf[i] & 0xF );
+        data.append( 1, ' ' );
+        data.append( 1, hexDigit( ( buf[i] >> 4 ) & 0xF ) );
+        data.append( 1, hexDigit( buf[i] & 0xF ) );
     }
 
-    return std::string( mem.get(), len * 2 );
+    return data;
 }
 
 SlipBIO::SlipBIO() {
@@ -42,6 +37,7 @@ SlipBIO::SlipBIO() {
     this->decodeTarget = 0;
     this->decodePos = 0;
     this->rawPos = 0;
+    this->failed = false;
 }
 
 void SlipBIO::setTarget( std::shared_ptr<OpensslBIO> target ) {
@@ -50,6 +46,7 @@ void SlipBIO::setTarget( std::shared_ptr<OpensslBIO> target ) {
 
 SlipBIO::SlipBIO( std::shared_ptr<OpensslBIO> target ) {
     this->target = target;
+
     this->buffer = std::vector<char>( 4096 );
     this->decodeTarget = 0;
     this->decodePos = 0;