//----------------------------------------------------------------// bool USData::Decode ( USCipher& cipher ) { this->mMutex.Lock (); USByteStream cryptStream; cryptStream.SetBuffer ( this->mBytes, this->mBytes.Size ()); cryptStream.SetLength ( this->mBytes.Size ()); USCipherStream cipherStream; cipherStream.OpenCipher ( cryptStream, cipher ); USMemStream plainStream; plainStream.Pipe ( cipherStream ); cipherStream.CloseCipher (); size_t len = plainStream.GetLength (); this->mBytes.Init ( len ); plainStream.Seek ( 0, SEEK_SET ); plainStream.ReadBytes ( this->mBytes, len ); this->mMutex.Unlock (); return true; }
//----------------------------------------------------------------// 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; }
//----------------------------------------------------------------// bool USLuaState::Decode ( int idx, USCipher& cipher ) { if ( !this->IsType ( idx, LUA_TSTRING )) return false; size_t len; void* buffer = ( void* )lua_tolstring ( this->mState, idx, &len ); if ( !len ) return false; USByteStream cryptStream; cryptStream.SetBuffer ( buffer, len ); cryptStream.SetLength ( len ); USCipherStream cipherStream; cipherStream.OpenCipher ( cryptStream, cipher ); USMemStream plainStream; plainStream.Pipe ( cipherStream ); cipherStream.CloseCipher (); len = plainStream.GetLength (); buffer = malloc ( len ); plainStream.Seek ( 0, SEEK_SET ); plainStream.ReadBytes ( buffer, len ); lua_pushlstring ( this->mState, ( cc8* )buffer, len ); free ( buffer ); 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; }