1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00

New marshalling function put_datapl().

Just like put_data(), but takes a ptrlen rather than separate ptr and
len arguments, so it saves a bit of repetition at call sites. I
probably should have written this ages ago, but better late than
never; I've also converted every call site I can find that needed it.
This commit is contained in:
Simon Tatham 2019-01-01 19:00:19 +00:00
parent 4397016a51
commit c02031ffd6
10 changed files with 24 additions and 17 deletions

View File

@ -905,7 +905,7 @@ static bool openssh_pem_write(
seq = strbuf_new();
for (i = 0; i < nnumbers; i++) {
put_ber_id_len(seq, 2, numbers[i].len, 0);
put_data(seq, numbers[i].ptr, numbers[i].len);
put_datapl(seq, numbers[i]);
}
put_ber_id_len(outblob, 16, seq->len, ASN1_CONSTRUCTED);
put_data(outblob, seq->s, seq->len);

View File

@ -10,6 +10,11 @@ void BinarySink_put_data(BinarySink *bs, const void *data, size_t len)
bs->write(bs, data, len);
}
void BinarySink_put_datapl(BinarySink *bs, ptrlen pl)
{
BinarySink_put_data(bs, pl.ptr, pl.len);
}
void BinarySink_put_padding(BinarySink *bs, size_t len, unsigned char padbyte)
{
char buf[16];

View File

@ -128,6 +128,8 @@ struct BinarySink {
* rest of these macros. */
#define put_data(bs, val, len) \
BinarySink_put_data(BinarySink_UPCAST(bs), val, len)
#define put_datapl(bs, pl) \
BinarySink_put_datapl(BinarySink_UPCAST(bs), pl)
/*
* The underlying real C functions that implement most of those
@ -140,6 +142,7 @@ struct BinarySink {
* declaration(s) of their other parameter type(s) are in scope.
*/
void BinarySink_put_data(BinarySink *, const void *data, size_t len);
void BinarySink_put_datapl(BinarySink *, ptrlen);
void BinarySink_put_padding(BinarySink *, size_t len, unsigned char padbyte);
void BinarySink_put_byte(BinarySink *, unsigned char);
void BinarySink_put_bool(BinarySink *, bool);

View File

@ -269,7 +269,7 @@ void pageant_handle_msg(BinarySink *bs,
MD5Init(&md5c);
for (i = 0; i < 32; i++)
put_byte(&md5c, mp_get_byte(response, 31 - i));
put_data(&md5c, session_id.ptr, session_id.len);
put_datapl(&md5c, session_id);
MD5Final(response_md5, &md5c);
put_byte(bs, SSH1_AGENT_RSA_RESPONSE);
@ -1388,7 +1388,7 @@ int pageant_enum_keys(pageant_key_enum_fn_t callback, void *callback_ctx,
fingerprint = ssh2_fingerprint_blob(pubblob.ptr, pubblob.len);
cbkey.blob = strbuf_new();
put_data(cbkey.blob, pubblob.ptr, pubblob.len);
put_datapl(cbkey.blob, pubblob);
cbkey.ssh_version = 2;
cbkey.comment = mkstr(comment);

View File

@ -1133,14 +1133,13 @@ static void scp_sink_coroutine(ScpSink *scp)
ptrlen leafname = make_ptrlen(
p, scp->command->len - (p - scp->command->s));
scp->filename_sb->len = 0;
put_data(scp->filename_sb, scp->head->destpath.ptr,
scp->head->destpath.len);
put_datapl(scp->filename_sb, scp->head->destpath);
if (scp->head->isdir) {
if (scp->filename_sb->len > 0 &&
scp->filename_sb->s[scp->filename_sb->len-1]
!= '/')
put_byte(scp->filename_sb, '/');
put_data(scp->filename_sb, leafname.ptr, leafname.len);
put_datapl(scp->filename_sb, leafname);
}
scp->filename = ptrlen_from_strbuf(scp->filename_sb);

View File

@ -107,7 +107,7 @@ static void ssh2_userauth_server_add_session_id(
struct ssh2_userauth_server_state *s, strbuf *sigdata)
{
if (s->ppl.remote_bugs & BUG_SSH2_PK_SESSIONID) {
put_data(sigdata, s->session_id.ptr, s->session_id.len);
put_datapl(sigdata, s->session_id);
} else {
put_stringpl(sigdata, s->session_id);
}

View File

@ -570,7 +570,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
* Save the methods string for use in error messages.
*/
s->last_methods_string->len = 0;
put_data(s->last_methods_string, methods.ptr, methods.len);
put_datapl(s->last_methods_string, methods);
/*
* Scan it for method identifiers we know about.
@ -1557,7 +1557,7 @@ static void ssh2_userauth_add_session_id(
struct ssh2_userauth_state *s, strbuf *sigdata)
{
if (s->ppl.remote_bugs & BUG_SSH2_PK_SESSIONID) {
put_data(sigdata, s->session_id.ptr, s->session_id.len);
put_datapl(sigdata, s->session_id);
} else {
put_stringpl(sigdata, s->session_id);
}
@ -1643,7 +1643,7 @@ static void ssh2_userauth_add_sigblob(
put_data(substr, sigblob.ptr, sig_prefix_len);
put_uint32(substr, mod_mp.len);
put_padding(substr, mod_mp.len - sig_mp.len, 0);
put_data(substr, sig_mp.ptr, sig_mp.len);
put_datapl(substr, sig_mp);
put_stringsb(pkt, substr);
return;
}

View File

@ -773,8 +773,8 @@ static void eddsa_openssh_blob(ssh_key *key, BinarySink *bs)
/* Encode the private key as the concatenation of the
* little-endian key integer and the public key again */
put_uint32(bs, priv.len + pub.len);
put_data(bs, priv.ptr, priv.len);
put_data(bs, pub.ptr, pub.len);
put_datapl(bs, priv);
put_datapl(bs, pub);
strbuf_free(pub_sb);
strbuf_free(priv_sb);
@ -828,7 +828,7 @@ static mp_int *ecdsa_signing_exponent_from_data(
/* Hash the data being signed. */
unsigned char hash[MAX_HASH_LEN];
ssh_hash *h = ssh_hash_new(extra->hash);
put_data(h, data.ptr, data.len);
put_datapl(h, data);
ssh_hash_final(h, hash);
/*
@ -921,9 +921,9 @@ static mp_int *eddsa_signing_exponent_from_data(
/* Hash (r || public key || message) */
unsigned char hash[MAX_HASH_LEN];
ssh_hash *h = ssh_hash_new(extra->hash);
put_data(h, r_encoded.ptr, r_encoded.len);
put_datapl(h, r_encoded);
put_epoint(h, ek->publicKey, ek->curve, true); /* omit string header */
put_data(h, data.ptr, data.len);
put_datapl(h, data);
ssh_hash_final(h, hash);
/* Convert to an integer */

View File

@ -592,7 +592,7 @@ static unsigned char *rsa_pkcs1_signature_string(
memcpy(bytes + 2 + padding, asn1_prefix, asn1_prefix_size);
ssh_hash *h = ssh_hash_new(halg);
put_data(h, data.ptr, data.len);
put_datapl(h, data);
ssh_hash_final(h, bytes + 2 + padding + asn1_prefix_size);
return bytes;

View File

@ -454,7 +454,7 @@ void BinarySink_put_stringpl_xauth(BinarySink *bs, ptrlen pl)
{
assert((pl.len >> 16) == 0);
put_uint16(bs, pl.len);
put_data(bs, pl.ptr, pl.len);
put_datapl(bs, pl);
}
#define put_stringpl_xauth(bs, ptrlen) \
BinarySink_put_stringpl_xauth(BinarySink_UPCAST(bs),ptrlen)