From 6b0b478590d617a80408ce77a792e3decc7f75aa Mon Sep 17 00:00:00 2001 From: Armin Preiml Date: Tue, 29 Nov 2022 13:49:58 +0100 Subject: [PATCH] make newed25519key allocate and return a pointer It fits better, since there is only key_free, which only accepts a pointer to finish keys and clear their contents. --- format/ssh/+test/rawkey.ha | 8 +++++--- format/ssh/ed25519.ha | 6 +++--- format/ssh/key.ha | 4 ++-- net/ssh/agent/proto.ha | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/format/ssh/+test/rawkey.ha b/format/ssh/+test/rawkey.ha index ec53c6a..b008207 100644 --- a/format/ssh/+test/rawkey.ha +++ b/format/ssh/+test/rawkey.ha @@ -7,15 +7,17 @@ use io; const sshkey = decodesshprivate(&reader)!; defer sshprivkey_finish(&sshkey); const private = decodeprivate(&sshkey)!; + defer key_free(private); let private = private: *ed25519key; - let copy = new_ed25519key(); + let copy = newed25519key(); + defer key_free(copy); let pubbuf = bufio::dynamic(io::mode::RDWR); defer io::close(&pubbuf)!; key_encoderawpub(private, &pubbuf)!; io::seek(&pubbuf, 0, io::whence::SET)!; - key_decoderawpub(©, &pubbuf)!; + key_decoderawpub(copy, &pubbuf)!; assert(bytes::equal(private.pubkey, copy.pubkey)); @@ -23,7 +25,7 @@ use io; defer io::close(&privbuf)!; key_encoderawpriv(private, &privbuf)!; io::seek(&privbuf, 0, io::whence::SET)!; - key_decoderawpriv(©, &privbuf)!; + key_decoderawpriv(copy, &privbuf)!; assert(bytes::equal(private.privkey, copy.privkey)); }; diff --git a/format/ssh/ed25519.ha b/format/ssh/ed25519.ha index d123e9b..85fa86f 100644 --- a/format/ssh/ed25519.ha +++ b/format/ssh/ed25519.ha @@ -24,11 +24,11 @@ const ed25519_vtable: key_vtable = key_vtable { ... }; -export fn new_ed25519key() ed25519key = { - return ed25519key { +export fn newed25519key() *ed25519key = { + return alloc(ed25519key { vtable = &ed25519_vtable, ... - }; + }); }; fn ed25519_decodepub(key: *key, buf: io::handle) (void | error) = { diff --git a/format/ssh/key.ha b/format/ssh/key.ha index 7222ba3..5cd5743 100644 --- a/format/ssh/key.ha +++ b/format/ssh/key.ha @@ -59,7 +59,7 @@ export fn decodeprivate(src: *sshprivkey) (*key | error) = { let key: *key = switch (keytype) { case "ssh-ed25519" => - yield alloc(new_ed25519key()); + yield newed25519key(); case => return badcipher; }; @@ -75,7 +75,7 @@ export fn decodepublic(src: io::handle) (*key | error) = { let key: *key = switch (keytype) { case "ssh-ed25519" => - yield alloc(new_ed25519key()); + yield newed25519key(); case => return badcipher; }; diff --git a/net/ssh/agent/proto.ha b/net/ssh/agent/proto.ha index 42547e7..27747be 100644 --- a/net/ssh/agent/proto.ha +++ b/net/ssh/agent/proto.ha @@ -77,7 +77,7 @@ fn parse_add_identity(src: io::handle) (add_identity | invalid) = { // TODO: Support more key types const key = switch (keytype) { case "ssh-ed25519" => - let key = alloc(ssh::new_ed25519key()); + let key = ssh::newed25519key(); const npub = readu32(src)?; if (npub != len(key.pubkey)) { return invalid; -- 2.45.2