[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 19/24] buffer: use ssh_buffer_get() instead of ssh_buffer_get_begin()
[Thread Prev] | [Thread Next]
- Subject: [PATCH 19/24] buffer: use ssh_buffer_get() instead of ssh_buffer_get_begin()
- From: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
- Reply-to: libssh@xxxxxxxxxx
- Date: Mon, 18 Jan 2016 10:07:00 +0100
- To: libssh@xxxxxxxxxx
- Cc: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
This commit is a preparatory stage for removing ssh_buffer_get_begin(). Note that removing ssh_buffer_get_begin() doesn't break API compatibility, as this functions has never been exposed (it only has the LIBSSH_API prefix). Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx> --- examples/sample.c | 4 ++-- src/dh.c | 2 +- src/gssapi.c | 6 +++--- src/kex1.c | 2 +- src/legacy.c | 2 +- src/packet1.c | 16 ++++++++-------- src/pki.c | 2 +- src/pki_container_openssh.c | 12 ++++++------ src/pki_gcrypt.c | 8 ++++---- 9 files changed, 27 insertions(+), 27 deletions(-) diff --git a/examples/sample.c b/examples/sample.c index b716a1b..247004e 100644 --- a/examples/sample.c +++ b/examples/sample.c @@ -252,7 +252,7 @@ static void select_loop(ssh_session session,ssh_channel channel){ ssh_channel_free(channel); channel=channels[0]=NULL; } else - if (write(1,ssh_buffer_get_begin(readbuf),lus) < 0) { + if (write(1,ssh_buffer_get(readbuf),lus) < 0) { fprintf(stderr, "Error writing to buffer\n"); return; } @@ -268,7 +268,7 @@ static void select_loop(ssh_session session,ssh_channel channel){ ssh_channel_free(channel); channel=channels[0]=NULL; } else - if (write(2,ssh_buffer_get_begin(readbuf),lus) < 0) { + if (write(2,ssh_buffer_get(readbuf),lus) < 0) { fprintf(stderr, "Error writing to buffer\n"); return; } diff --git a/src/dh.c b/src/dh.c index 67d1f4c..1291c5f 100644 --- a/src/dh.c +++ b/src/dh.c @@ -630,7 +630,7 @@ int ssh_make_sessionid(ssh_session session) { } #ifdef DEBUG_CRYPTO - ssh_print_hexa("hash buffer", ssh_buffer_get_begin(buf), ssh_buffer_get_len(buf)); + ssh_print_hexa("hash buffer", ssh_buffer_get(buf), ssh_buffer_get_len(buf)); #endif switch (session->next_crypto->kex_type) { diff --git a/src/gssapi.c b/src/gssapi.c index 1c5a2a4..ff0dac0 100644 --- a/src/gssapi.c +++ b/src/gssapi.c @@ -427,14 +427,14 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_gssapi_mic) } if (ssh_callbacks_exists(session->server_callbacks, gssapi_verify_mic_function)){ int rc = session->server_callbacks->gssapi_verify_mic_function(session, mic_token, - ssh_buffer_get_begin(mic_buffer), ssh_buffer_get_len(mic_buffer), + ssh_buffer_get(mic_buffer), ssh_buffer_get_len(mic_buffer), session->server_callbacks->userdata); if (rc != SSH_OK) { goto error; } } else { mic_buf.length = ssh_buffer_get_len(mic_buffer); - mic_buf.value = ssh_buffer_get_begin(mic_buffer); + mic_buf.value = ssh_buffer_get(mic_buffer); mic_token_buf.length = ssh_string_len(mic_token); mic_token_buf.value = ssh_string_data(mic_token); @@ -792,7 +792,7 @@ static int ssh_gssapi_send_mic(ssh_session session){ return SSH_ERROR; } mic_buf.length = ssh_buffer_get_len(mic_buffer); - mic_buf.value = ssh_buffer_get_begin(mic_buffer); + mic_buf.value = ssh_buffer_get(mic_buffer); maj_stat = gss_get_mic(&min_stat,session->gssapi->ctx, GSS_C_QOP_DEFAULT, &mic_buf, &mic_token_buf); if (GSS_ERROR(maj_stat)){ diff --git a/src/kex1.c b/src/kex1.c index 10e6327..1691984 100644 --- a/src/kex1.c +++ b/src/kex1.c @@ -66,7 +66,7 @@ static ssh_string make_rsa1_string(ssh_string e, ssh_string n){ goto error; } - ssh_string_fill(ret, ssh_buffer_get_begin(buffer), ssh_buffer_get_len(buffer)); + ssh_string_fill(ret, ssh_buffer_get(buffer), ssh_buffer_get_len(buffer)); error: ssh_buffer_free(buffer); ssh_string_free(rsa); diff --git a/src/legacy.c b/src/legacy.c index 15f287a..3f09992 100644 --- a/src/legacy.c +++ b/src/legacy.c @@ -145,7 +145,7 @@ void buffer_free(ssh_buffer buffer){ ssh_buffer_free(buffer); } void *buffer_get(ssh_buffer buffer){ - return ssh_buffer_get_begin(buffer); + return ssh_buffer_get(buffer); } uint32_t buffer_get_len(ssh_buffer buffer){ return ssh_buffer_get_len(buffer); diff --git a/src/packet1.c b/src/packet1.c index 25fc44b..ff33ca1 100644 --- a/src/packet1.c +++ b/src/packet1.c @@ -160,7 +160,7 @@ int ssh_packet_socket_callback1(const void *data, size_t receivedlen, void *user } processed += to_be_read; #ifdef DEBUG_CRYPTO - ssh_print_hexa("read packet:", ssh_buffer_get_begin(session->in_buffer), + ssh_print_hexa("read packet:", ssh_buffer_get(session->in_buffer), ssh_buffer_get_len(session->in_buffer)); #endif if (session->current_crypto) { @@ -172,7 +172,7 @@ int ssh_packet_socket_callback1(const void *data, size_t receivedlen, void *user if (buffer_len > 0) { int rc; rc = ssh_packet_decrypt(session, - ssh_buffer_get_begin(session->in_buffer), + ssh_buffer_get(session->in_buffer), buffer_len); if (rc < 0) { ssh_set_error(session, SSH_FATAL, "Packet decrypt error"); @@ -181,7 +181,7 @@ int ssh_packet_socket_callback1(const void *data, size_t receivedlen, void *user } } #ifdef DEBUG_CRYPTO - ssh_print_hexa("read packet decrypted:", ssh_buffer_get_begin(session->in_buffer), + ssh_print_hexa("read packet decrypted:", ssh_buffer_get(session->in_buffer), ssh_buffer_get_len(session->in_buffer)); #endif SSH_LOG(SSH_LOG_PACKET, "%d bytes padding", padding); @@ -293,7 +293,7 @@ int ssh_packet_send1(ssh_session session) { goto error; } - crc = ssh_crc32((char *)ssh_buffer_get_begin(session->out_buffer) + sizeof(uint32_t), + crc = ssh_crc32((char *)ssh_buffer_get(session->out_buffer) + sizeof(uint32_t), ssh_buffer_get_len(session->out_buffer) - sizeof(uint32_t)); if (ssh_buffer_add_u32(session->out_buffer, ntohl(crc)) < 0) { @@ -301,20 +301,20 @@ int ssh_packet_send1(ssh_session session) { } #ifdef DEBUG_CRYPTO - ssh_print_hexa("Clear packet", ssh_buffer_get_begin(session->out_buffer), + ssh_print_hexa("Clear packet", ssh_buffer_get(session->out_buffer), ssh_buffer_get_len(session->out_buffer)); #endif /* session->out_buffer should have more than sizeof(uint32_t) bytes in it as required for ssh_packet_encrypt */ - ssh_packet_encrypt(session, (unsigned char *)ssh_buffer_get_begin(session->out_buffer) + sizeof(uint32_t), + ssh_packet_encrypt(session, (unsigned char *)ssh_buffer_get(session->out_buffer) + sizeof(uint32_t), ssh_buffer_get_len(session->out_buffer) - sizeof(uint32_t)); #ifdef DEBUG_CRYPTO - ssh_print_hexa("encrypted packet",ssh_buffer_get_begin(session->out_buffer), + ssh_print_hexa("encrypted packet",ssh_buffer_get(session->out_buffer), ssh_buffer_get_len(session->out_buffer)); #endif - rc=ssh_socket_write(session->socket, ssh_buffer_get_begin(session->out_buffer), + rc=ssh_socket_write(session->socket, ssh_buffer_get(session->out_buffer), ssh_buffer_get_len(session->out_buffer)); if(rc== SSH_ERROR) { goto error; diff --git a/src/pki.c b/src/pki.c index ac4a543..d15c32c 100644 --- a/src/pki.c +++ b/src/pki.c @@ -1659,7 +1659,7 @@ ssh_string ssh_pki_do_sign(ssh_session session, } sig = pki_do_sign(privkey, - ssh_buffer_get_begin(buf), + ssh_buffer_get(buf), ssh_buffer_get_len(buf)); ssh_buffer_free(buf); } else { diff --git a/src/pki_container_openssh.c b/src/pki_container_openssh.c index 9653bf0..a3e6654 100644 --- a/src/pki_container_openssh.c +++ b/src/pki_container_openssh.c @@ -543,8 +543,8 @@ static int pki_private_key_encrypt(ssh_buffer privkey_buffer, key_material, key_material + cipher.keysize/8); cipher.encrypt(&cipher, - ssh_buffer_get_begin(privkey_buffer), - ssh_buffer_get_begin(privkey_buffer), + ssh_buffer_get(privkey_buffer), + ssh_buffer_get(privkey_buffer), ssh_buffer_get_len(privkey_buffer)); ssh_cipher_clear(&cipher); BURN_BUFFER(passphrase_buffer, sizeof(passphrase_buffer)); @@ -642,7 +642,7 @@ ssh_string ssh_pki_openssh_privkey_export(const ssh_key privkey, goto error; } memcpy(ssh_string_data(kdf_options), - ssh_buffer_get_begin(kdf_buf), + ssh_buffer_get(kdf_buf), ssh_buffer_get_len(kdf_buf)); ssh_buffer_free(kdf_buf); rc = pki_private_key_encrypt(privkey_buffer, @@ -670,12 +670,12 @@ ssh_string ssh_pki_openssh_privkey_export(const ssh_key privkey, pubkey_s, (uint32_t)ssh_buffer_get_len(privkey_buffer), /* rest of buffer is a string */ - (size_t)ssh_buffer_get_len(privkey_buffer), ssh_buffer_get_begin(privkey_buffer)); + (size_t)ssh_buffer_get_len(privkey_buffer), ssh_buffer_get(privkey_buffer)); if (rc != SSH_OK) { goto error; } - b64 = bin_to_base64(ssh_buffer_get_begin(buffer), + b64 = bin_to_base64(ssh_buffer_get(buffer), ssh_buffer_get_len(buffer)); if (b64 == NULL){ goto error; @@ -712,7 +712,7 @@ ssh_string ssh_pki_openssh_privkey_export(const ssh_key privkey, error: if (privkey_buffer != NULL) { - void *bufptr = ssh_buffer_get_begin(privkey_buffer); + void *bufptr = ssh_buffer_get(privkey_buffer); BURN_BUFFER(bufptr, ssh_buffer_get_len(privkey_buffer)); ssh_buffer_free(privkey_buffer); } diff --git a/src/pki_gcrypt.c b/src/pki_gcrypt.c index bce69c6..16e4833 100644 --- a/src/pki_gcrypt.c +++ b/src/pki_gcrypt.c @@ -152,7 +152,7 @@ static int asn1_check_sequence(ssh_buffer buffer) { size = asn1_get_len(buffer); if ((padding = ssh_buffer_get_len(buffer) - size) > 0) { for (i = ssh_buffer_get_len(buffer) - size, - j = (unsigned char*)ssh_buffer_get_begin(buffer) + size + buffer->pos; + j = (unsigned char*)ssh_buffer_get(buffer) + size; i; i--, j++) { @@ -235,12 +235,12 @@ static int privatekey_decrypt(int algo, int mode, unsigned int key_len, || gcry_cipher_setiv(cipher, iv, iv_len) || (tmp = malloc(ssh_buffer_get_len(data) * sizeof (char))) == NULL || gcry_cipher_decrypt(cipher, tmp, ssh_buffer_get_len(data), - ssh_buffer_get_begin(data), ssh_buffer_get_len(data))) { + ssh_buffer_get(data), ssh_buffer_get_len(data))) { gcry_cipher_close(cipher); return -1; } - memcpy(ssh_buffer_get_begin(data), tmp, ssh_buffer_get_len(data)); + memcpy(ssh_buffer_get(data), tmp, ssh_buffer_get_len(data)); SAFE_FREE(tmp); gcry_cipher_close(cipher); @@ -418,7 +418,7 @@ static ssh_buffer privatekey_string_to_buffer(const char *pkey, int type, return NULL; } - out = base64_to_bin(ssh_buffer_get_begin(buffer)); + out = base64_to_bin(ssh_buffer_get(buffer)); ssh_buffer_free(buffer); if (out == NULL) { SAFE_FREE(iv); -- 2.5.0
[PATCH 00/24] clean up + expose some buffer functions (the ones necessary for writing an ssh-agent). | Fabiano Fidêncio <fidencio@xxxxxxxxxx> |