//----------------------------------------------------------------// bool USLuaState::Encode ( int idx, USCipher& cipher ) { if ( !this->IsType ( idx, LUA_TSTRING )) return false; size_t len; cc8* buffer = lua_tolstring ( this->mState, idx, &len ); if ( !len ) return false; USCipherStream cipherStream; USMemStream stream; cipherStream.OpenCipher ( stream, cipher ); cipherStream.WriteBytes ( buffer, len ); cipherStream.CloseCipher (); len = stream.GetLength (); void* temp = malloc ( len ); stream.Seek ( 0, SEEK_SET ); stream.ReadBytes (( void* )temp, len ); lua_pushlstring ( this->mState, ( cc8* )temp, len ); free ( temp ); return true; }
//----------------------------------------------------------------// void STLString::base_64_encode ( const void* buffer, u32 len ) { ( *this ) = ""; if ( !len ) return; USCipherStream cipherStream; USMemStream memStream; USBase64Cipher base64; cipherStream.OpenCipher ( memStream, base64 ); cipherStream.WriteBytes ( buffer, len ); cipherStream.CloseCipher (); memStream.Seek ( 0, SEEK_SET ); ( *this ) = memStream.ToString ( memStream.GetLength ()); }
//----------------------------------------------------------------// bool USData::Encode ( USCipher& cipher ) { this->mMutex.Lock (); USCipherStream cipherStream; USMemStream stream; cipherStream.OpenCipher ( stream, cipher ); cipherStream.WriteBytes ( this->mBytes, this->mBytes.Size ()); cipherStream.CloseCipher (); size_t len = stream.GetLength (); this->mBytes.Init ( len ); stream.Seek ( 0, SEEK_SET ); stream.ReadBytes ( this->mBytes, len ); this->mMutex.Unlock (); return true; }