Skip to content

Commit

Permalink
Remove using-declarations for std:: types
Browse files Browse the repository at this point in the history
  • Loading branch information
achernya committed Jul 30, 2023
1 parent 3d69249 commit 68024ad
Show file tree
Hide file tree
Showing 21 changed files with 173 additions and 189 deletions.
16 changes: 8 additions & 8 deletions src/crypto/crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ AlignedBuffer::AlignedBuffer( size_t len, const char *data )
}
}

Base64Key::Base64Key( string printable_key )
Base64Key::Base64Key( std::string printable_key )
{
if ( printable_key.length() != 22 ) {
throw CryptoException( "Key must be 22 letters long." );
}

string base64 = printable_key + "==";
std::string base64 = printable_key + "==";

size_t len = 16;
if ( !base64_decode( base64.data(), 24, key, &len ) ) {
Expand All @@ -140,19 +140,19 @@ Base64Key::Base64Key(PRNG &prng)
prng.fill( key, sizeof( key ) );
}

string Base64Key::printable_key( void ) const
std::string Base64Key::printable_key( void ) const
{
char base64[ 24 ];

base64_encode( key, 16, base64, 24 );

if ( (base64[ 23 ] != '=')
|| (base64[ 22 ] != '=') ) {
throw CryptoException( string( "Unexpected output from base64_encode: " ) + string( base64, 24 ) );
throw CryptoException( std::string( "Unexpected output from base64_encode: " ) + std::string( base64, 24 ) );
}

base64[ 22 ] = 0;
return string( base64 );
return std::string( base64 );
}

Session::Session( Base64Key s_key )
Expand Down Expand Up @@ -197,7 +197,7 @@ Nonce::Nonce( const char *s_bytes, size_t len )
memcpy( bytes + 4, s_bytes, 8 );
}

const string Session::encrypt( const Message & plaintext )
const std::string Session::encrypt( const Message & plaintext )
{
const size_t pt_len = plaintext.text.size();
const int ciphertext_len = pt_len + 16;
Expand Down Expand Up @@ -242,7 +242,7 @@ const string Session::encrypt( const Message & plaintext )
throw CryptoException( "Encrypted 2^47 blocks.", true );
}

string text( ciphertext_buffer.data(), ciphertext_len );
std::string text( ciphertext_buffer.data(), ciphertext_len );

return plaintext.nonce.cc_str() + text;
}
Expand Down Expand Up @@ -280,7 +280,7 @@ const Message Session::decrypt( const char *str, size_t len )
throw CryptoException( "Packet failed integrity check." );
}

const Message ret( nonce, string( plaintext_buffer.data(), pt_len ) );
const Message ret( nonce, std::string( plaintext_buffer.data(), pt_len ) );

return ret;
}
Expand Down
20 changes: 9 additions & 11 deletions src/crypto/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,11 @@ long int myatoi( const char *str );
class PRNG;

namespace Crypto {
using std::string;

class CryptoException : public std::exception {
public:
string text;
std::string text;
bool fatal;
CryptoException( string s_text, bool s_fatal = false )
CryptoException( std::string s_text, bool s_fatal = false )
: text( s_text ), fatal( s_fatal ) {};
const char *what() const throw () { return text.c_str(); }
~CryptoException() throw () {}
Expand Down Expand Up @@ -95,8 +93,8 @@ namespace Crypto {
public:
Base64Key(); /* random key */
Base64Key(PRNG &prng);
Base64Key( string printable_key );
string printable_key( void ) const;
Base64Key( std::string printable_key );
std::string printable_key( void ) const;
unsigned char *data( void ) { return key; }
};

Expand All @@ -111,22 +109,22 @@ namespace Crypto {
Nonce( uint64_t val );
Nonce( const char *s_bytes, size_t len );

string cc_str( void ) const { return string( bytes + 4, 8 ); }
std::string cc_str( void ) const { return std::string( bytes + 4, 8 ); }
const char *data( void ) const { return bytes; }
uint64_t val( void ) const;
};

class Message {
public:
const Nonce nonce;
const string text;
const std::string text;

Message( const char *nonce_bytes, size_t nonce_len,
const char *text_bytes, size_t text_len )
: nonce( nonce_bytes, nonce_len ),
text( text_bytes, text_len ) {}

Message( const Nonce & s_nonce, const string & s_text )
Message( const Nonce & s_nonce, const std::string & s_text )
: nonce( s_nonce ),
text( s_text ) {}
};
Expand All @@ -150,9 +148,9 @@ namespace Crypto {
Session( Base64Key s_key );
~Session();

const string encrypt( const Message & plaintext );
const std::string encrypt( const Message & plaintext );
const Message decrypt( const char *str, size_t len );
const Message decrypt( const string & ciphertext ) {
const Message decrypt( const std::string & ciphertext ) {
return decrypt( ciphertext.data(), ciphertext.size() );
}

Expand Down
6 changes: 3 additions & 3 deletions src/examples/benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ int main( int argc, char **argv )
overlays.apply( *new_state );

/* calculate minimal difference from where we are */
const string diff( display.new_frame( false,
*local_framebuffer,
*new_state ) );
const std::string diff( display.new_frame( false,
*local_framebuffer,
*new_state ) );

/* make sure to use diff */
if ( diff.size() > INT_MAX ) {
Expand Down
2 changes: 1 addition & 1 deletion src/examples/encrypt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ int main( int argc, char *argv[] )

/* Encrypt message */

string ciphertext = session.encrypt( Message( nonce, input.str() ) );
std::string ciphertext = session.encrypt( Message( nonce, input.str() ) );

std::cerr << "Key: " << key.printable_key() << std::endl;

Expand Down
2 changes: 1 addition & 1 deletion src/frontend/mosh-client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ int main( int argc, char *argv[] )
char *predict_overwrite = getenv( "MOSH_PREDICTION_OVERWRITE" );
/* can be NULL */

string key( env_key );
std::string key( env_key );

if ( unsetenv( "MOSH_KEY" ) < 0 ) {
perror( "unsetenv" );
Expand Down
54 changes: 27 additions & 27 deletions src/frontend/mosh-server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ static void serve( int host_fd,
long network_signaled_timeout );

static int run_server( const char *desired_ip, const char *desired_port,
const string &command_path, char *command_argv[],
const std::string &command_path, char *command_argv[],
const int colors, unsigned int verbose, bool with_motd );


Expand All @@ -125,7 +125,7 @@ static void print_usage( FILE *stream, const char *argv0 )
static bool print_motd( const char *filename );
static void chdir_homedir( void );
static bool motd_hushed( void );
static void warn_unattached( const string & ignore_entry );
static void warn_unattached( const std::string & ignore_entry );

/* Simple spinloop */
static void spin( void )
Expand All @@ -142,19 +142,19 @@ static void spin( void )
}
}

static string get_SSH_IP( void )
static std::string get_SSH_IP( void )
{
const char *SSH_CONNECTION = getenv( "SSH_CONNECTION" );
if ( !SSH_CONNECTION ) { /* Older sshds don't set this */
fputs( "Warning: SSH_CONNECTION not found; binding to any interface.\n", stderr );
return string( "" );
return std::string( "" );
}
std::istringstream ss( SSH_CONNECTION );
string dummy, local_interface_IP;
std::string dummy, local_interface_IP;
ss >> dummy >> dummy >> local_interface_IP;
if ( !ss ) {
fputs( "Warning: Could not parse SSH_CONNECTION; binding to any interface.\n", stderr );
return string( "" );
return std::string( "" );
}

/* Strip IPv6 prefix. */
Expand All @@ -177,14 +177,14 @@ int main( int argc, char *argv[] )
fatal_assert( argc > 0 );

const char *desired_ip = NULL;
string desired_ip_str;
std::string desired_ip_str;
const char *desired_port = NULL;
string command_path;
std::string command_path;
char **command_argv = NULL;
int colors = 0;
unsigned int verbose = 0; /* don't close stdin/stdout/stderr */
/* Will cause mosh-server not to correctly detach on old versions of sshd. */
list<string> locale_vars;
std::list<std::string> locale_vars;

/* strip off command */
for ( int i = 1; i < argc; i++ ) {
Expand Down Expand Up @@ -249,7 +249,7 @@ int main( int argc, char *argv[] )
verbose++;
break;
case 'l':
locale_vars.push_back( string( optarg ) );
locale_vars.push_back( std::string( optarg ) );
break;
default:
/* don't die on unknown options */
Expand Down Expand Up @@ -286,7 +286,7 @@ int main( int argc, char *argv[] )

/* Get shell */
char *my_argv[ 2 ];
string shell_name;
std::string shell_name;
if ( !command_argv ) {
/* get shell name */
const char *shell = getenv( "SHELL" );
Expand All @@ -299,15 +299,15 @@ int main( int argc, char *argv[] )
shell = pw->pw_shell;
}

string shell_path( shell );
std::string shell_path( shell );
if ( shell_path.empty() ) { /* empty shell means Bourne shell */
shell_path = _PATH_BSHELL;
}

command_path = shell_path;

size_t shell_slash( shell_path.rfind('/') );
if ( shell_slash == string::npos ) {
if ( shell_slash == std::string::npos ) {
shell_name = shell_path;
} else {
shell_name = shell_path.substr(shell_slash + 1);
Expand All @@ -332,11 +332,11 @@ int main( int argc, char *argv[] )
if ( !is_utf8_locale() ) {
/* save details for diagnostic */
LocaleVar native_ctype = get_ctype();
string native_charset( locale_charset() );
std::string native_charset( locale_charset() );

/* apply locale-related environment variables from client */
clear_locale_variables();
for ( list<string>::const_iterator i = locale_vars.begin();
for ( std::list<std::string>::const_iterator i = locale_vars.begin();
i != locale_vars.end();
i++ ) {
char *env_string = strdup( i->c_str() );
Expand All @@ -350,7 +350,7 @@ int main( int argc, char *argv[] )
set_native_locale();
if ( !is_utf8_locale() ) {
LocaleVar client_ctype = get_ctype();
string client_charset( locale_charset() );
std::string client_charset( locale_charset() );

fprintf( stderr, "mosh-server needs a UTF-8 native locale to run.\n\n"
"Unfortunately, the local environment (%s) specifies\n"
Expand All @@ -377,7 +377,7 @@ int main( int argc, char *argv[] )
}

static int run_server( const char *desired_ip, const char *desired_port,
const string &command_path, char *command_argv[],
const std::string &command_path, char *command_argv[],
const int colors, unsigned int verbose, bool with_motd ) {
/* get network idle timeout */
long network_timeout = 0;
Expand Down Expand Up @@ -723,7 +723,7 @@ static void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &

now = Network::timestamp();
uint64_t time_since_remote_state = now - network.get_latest_remote_state().timestamp;
string terminal_to_host;
std::string terminal_to_host;

if ( sel.read( network_fd ) ) {
/* packet received from the network */
Expand Down Expand Up @@ -842,7 +842,7 @@ static void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &
if ( bytes_read <= 0 ) {
network.start_shutdown();
} else {
terminal_to_host += terminal.act( string( buf, bytes_read ) );
terminal_to_host += terminal.act( std::string( buf, bytes_read ) );

/* update client with new state of terminal */
network.set_current_state( terminal );
Expand Down Expand Up @@ -992,13 +992,13 @@ static bool motd_hushed( void )
#ifdef HAVE_UTMPX_H
static bool device_exists( const char *ut_line )
{
string device_name = string( "/dev/" ) + string( ut_line );
std::string device_name = std::string( "/dev/" ) + std::string( ut_line );
struct stat buf;
return 0 == lstat( device_name.c_str(), &buf );
}
#endif

static void warn_unattached( const string & ignore_entry )
static void warn_unattached( const std::string & ignore_entry )
{
#ifdef HAVE_UTMPX_H
/* get username */
Expand All @@ -1009,16 +1009,16 @@ static void warn_unattached( const string & ignore_entry )
return;
}

const string username( pw->pw_name );
const std::string username( pw->pw_name );

/* look for unattached sessions */
vector< string > unattached_mosh_servers;
std::vector< std::string > unattached_mosh_servers;

while ( struct utmpx *entry = getutxent() ) {
if ( (entry->ut_type == USER_PROCESS)
&& (username == string( entry->ut_user )) ) {
&& (username == std::string( entry->ut_user )) ) {
/* does line show unattached mosh session */
string text( entry->ut_host );
std::string text( entry->ut_host );
if ( (text.size() >= 5)
&& (text.substr( 0, 5 ) == "mosh ")
&& (text[ text.size() - 1 ] == ']')
Expand All @@ -1036,9 +1036,9 @@ static void warn_unattached( const string & ignore_entry )
printf( "\033[37;44mMosh: You have a detached Mosh session on this server (%s).\033[m\n\n",
unattached_mosh_servers.front().c_str() );
} else {
string pid_string;
std::string pid_string;

for ( vector< string >::const_iterator it = unattached_mosh_servers.begin();
for ( std::vector< std::string >::const_iterator it = unattached_mosh_servers.begin();
it != unattached_mosh_servers.end();
it++ ) {
pid_string += " - " + *it + "\n";
Expand Down
Loading

0 comments on commit 68024ad

Please sign in to comment.