navid/veins / commit
d3f1ee1d51ef
Navid M <navidmomtahen@gmail.com> · 2026-11-26
parents: a01b6805cc14
Browse files at this commit · Download source
--- a/veins/src/auth/credentials.sx+++ b/veins/src/auth/credentials.sx@@ -311,6 +311,26 @@ return none } return some bytes.Bytes.slice(host, 0, last as usize)+}++/// True when `name` refers to a usable local key file.+pub fn local_key_exists(name: bytes.Bytes) bool = trust {+ if name.len == 0 {+ return false+ }+ if bytes.Bytes.starts_with(name, bytes.bytes(c"ed25519:", 8)) {+ return false+ }+ val key_opt = keys.load(name)+ match key_opt {+ some k => {+ keys.free_key(k)+ return true+ }+ none => {+ return false+ }+ } } /// Resolve the key for a native URL: host:port, then host, then default.--- a/veins/src/cli/clone_cmd.sx+++ b/veins/src/cli/clone_cmd.sx@@ -117,6 +117,11 @@ policy = bytes.Bytes.dup(bytes.Bytes.slice(av, 7, av.len)) } elif bytes.Bytes.starts_with(av, bytes.bytes(c"-key:", 5)) { key_name = bytes.Bytes.dup(bytes.Bytes.slice(av, 5, av.len))+ if bytes.Bytes.starts_with(key_name, bytes.bytes(c"ed25519:", 8)) {+ cmsg.error_prefix()+ stdio.eprint("-key: expects a local key name, not a public key\n", {})+ return 1+ } key_explicit = true } elif bytes.Bytes.starts_with(av, bytes.bytes(c"-pin:", 5)) { tls_pin = bytes.Bytes.dup(bytes.Bytes.slice(av, 5, av.len))--- a/veins/src/cli/fetch_cmd.sx+++ b/veins/src/cli/fetch_cmd.sx@@ -80,6 +80,11 @@ val av: bytes.Bytes = bytes.from_cstr(a) if bytes.Bytes.starts_with(av, bytes.bytes(c"-key:", 5)) { explicit_key = bytes.Bytes.dup(bytes.Bytes.slice(av, 5, av.len))+ if bytes.Bytes.starts_with(explicit_key, bytes.bytes(c"ed25519:", 8)) {+ cmsg.error_prefix()+ stdio.eprint("-key: expects a local key name, not a public key\n", {})+ return 1+ } } elif av.len > 0 && bytes.Bytes.at(av, 0) == 45 { cmsg.error_prefix() stdio.eprint("unknown flag: {s}\n", {str.from_cstr(a)})@@ -128,13 +133,19 @@ } else { match key_name { some k => {- key = k+ if credentials.local_key_exists(k) {+ key = k+ } else {+ bytes.free_owned(k)+ } } none => {- val fallback = credentials.key_for_url(url)- if fallback is some ck {- key = ck- }+ }+ }+ if key.ptr == none {+ val fallback = credentials.key_for_url(url)+ if fallback is some ck {+ key = ck } } }--- a/veins/src/cli/push_cmd.sx+++ b/veins/src/cli/push_cmd.sx@@ -53,6 +53,11 @@ val av: bytes.Bytes = bytes.from_cstr(a) if bytes.Bytes.starts_with(av, bytes.bytes(c"-key:", 5)) { explicit_key = bytes.Bytes.dup(bytes.Bytes.slice(av, 5, av.len))+ if bytes.Bytes.starts_with(explicit_key, bytes.bytes(c"ed25519:", 8)) {+ cmsg.error_prefix()+ stdio.eprint("-key: expects a local key name, not a public key\n", {})+ return 1+ } } elif av.len > 0 && bytes.Bytes.at(av, 0) == 45 { cmsg.error_prefix() stdio.eprint("unknown flag: {s}\n", {str.from_cstr(a)})@@ -108,13 +113,19 @@ } else { match key_name { some k => {- key = k+ if credentials.local_key_exists(k) {+ key = k+ } else {+ bytes.free_owned(k)+ } } none => {- val fallback = credentials.key_for_url(url)- if fallback is some ck {- key = ck- }+ }+ }+ if key.ptr == none {+ val fallback = credentials.key_for_url(url)+ if fallback is some ck {+ key = ck } } }--- a/veins/src/cli/whoami_cmd.sx+++ b/veins/src/cli/whoami_cmd.sx@@ -66,7 +66,11 @@ } val kn = remote_config.key_name_of(repo, remote) if kn is some k {- key = k+ if credentials.local_key_exists(k) {+ key = k+ } else {+ bytes.free_owned(k)+ } } val pn = remote_config.tls_pin_of(repo, remote) if pn is some pv {