1 Commits

Author SHA1 Message Date
spencer f2a98bc782 refactor(ssh.odin): removed offset from parser logic. 2026-06-30 17:11:11 -04:00
3 changed files with 23 additions and 17 deletions
+3 -1
View File
@@ -16,7 +16,9 @@
8. Add tests for untested commands.
9. Audit ssh.odin for places where `#no_bounds_check` would be appropriate.
9. Consider getting rid of color global.
10. `write_flags_table` should never return false.
## Double-check AI output
+7 -3
View File
@@ -206,9 +206,10 @@ write_command_help :: proc(name: string, w: io.Writer) -> bool {
tbl: table.Table
table.init(&tbl, context.temp_allocator, context.temp_allocator)
table.padding(&tbl, 2, 0)
write_flags_table(&tbl, info.flags)
if write_flags_table(&tbl, info.flags) {
fmt.wprintf(w, "\n", flush = false)
write_borderless_table(w, &tbl)
}
table_reset(&tbl)
return true
}
@@ -266,7 +267,8 @@ flag_field_info :: proc(
return
}
write_flags_table :: proc(tbl: ^table.Table, flags: bit_set[Flag_Type]) {
write_flags_table :: proc(tbl: ^table.Table, flags: bit_set[Flag_Type]) -> (has_rows: bool) {
if flags == {} do return false
table.caption(tbl, "Flags:")
for ft in Flag_Type {
if ft not_in flags do continue
@@ -283,6 +285,7 @@ write_flags_table :: proc(tbl: ^table.Table, flags: bit_set[Flag_Type]) {
table.row(tbl, colorize(.Flag, names, tbl.format_allocator), desc)
}
}
return true
}
find_command :: proc(name: string) -> (CommandInfo, bool) {
@@ -362,8 +365,9 @@ at before, restore your backup with:
write_borderless_table(w, &tbl)
table_reset(&tbl)
write_flags_table(&tbl, GLOBAL_FLAGS)
if write_flags_table(&tbl, GLOBAL_FLAGS) {
write_borderless_table(w, &tbl)
}
table_reset(&tbl)
fmt.wprintf(
+10 -10
View File
@@ -35,13 +35,13 @@ parse_ssh_public_key :: proc(pub_path: string) -> (pub: [32]u8, ok: bool) {
return
}
rest := decoded
key_type, type_ok := read_wire_string(&rest)
buf := decoded
key_type, type_ok := read_wire_string(&buf)
if !type_ok || string(key_type) != SSH_ED25519 {
return
}
pk_data, pk_ok := read_wire_string(&rest)
pk_data, pk_ok := read_wire_string(&buf)
if !pk_ok || len(pk_data) != 32 {
return
}
@@ -91,34 +91,34 @@ parse_ssh_private_key :: proc(priv_path: string) -> (kp: Ed25519Keypair, ok: boo
return
}
rest := decoded[len(magic):]
buf := decoded[len(magic):]
ciphername, cipher_ok := read_wire_string(&rest)
ciphername, cipher_ok := read_wire_string(&buf)
if !cipher_ok || string(ciphername) != "none" {
return
}
kdfname, kdf_ok := read_wire_string(&rest)
kdfname, kdf_ok := read_wire_string(&buf)
if !kdf_ok || string(kdfname) != "none" {
return
}
_, opts_ok := read_wire_string(&rest)
_, opts_ok := read_wire_string(&buf)
if !opts_ok {
return
}
num_keys, nkeys_ok := read_wire_u32(&rest)
num_keys, nkeys_ok := read_wire_u32(&buf)
if !nkeys_ok || num_keys != 1 {
return
}
_, pub_blob_ok := read_wire_string(&rest)
_, pub_blob_ok := read_wire_string(&buf)
if !pub_blob_ok {
return
}
priv_blob, priv_blob_ok := read_wire_string(&rest)
priv_blob, priv_blob_ok := read_wire_string(&buf)
if !priv_blob_ok {
return
}