~apreiml/hare-ssh

6b0b478590d617a80408ce77a792e3decc7f75aa — Armin Preiml 1 year, 7 months ago 5fde138
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.
4 files changed, 11 insertions(+), 9 deletions(-)

M format/ssh/+test/rawkey.ha
M format/ssh/ed25519.ha
M format/ssh/key.ha
M net/ssh/agent/proto.ha
M format/ssh/+test/rawkey.ha => format/ssh/+test/rawkey.ha +5 -3
@@ 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(&copy, &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(&copy, &privbuf)!;
	key_decoderawpriv(copy, &privbuf)!;

	assert(bytes::equal(private.privkey, copy.privkey));
};

M format/ssh/ed25519.ha => format/ssh/ed25519.ha +3 -3
@@ 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) = {

M format/ssh/key.ha => format/ssh/key.ha +2 -2
@@ 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;
	};

M net/ssh/agent/proto.ha => net/ssh/agent/proto.ha +1 -1
@@ 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;