mirror of
https://github.com/sbrow/envr.git
synced 2026-06-27 10:38:33 -04:00
style: Removed unused code.
This commit is contained in:
@@ -3,7 +3,6 @@ package main
|
||||
import "core:fmt"
|
||||
import "core:os"
|
||||
import "core:path/filepath"
|
||||
import "core:strings"
|
||||
|
||||
cmd_check :: proc(cmd: ^Command) {
|
||||
feats := check_features()
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package main
|
||||
|
||||
import "core:fmt"
|
||||
|
||||
cmd_deps :: proc(cmd: ^Command) {
|
||||
feats := check_features()
|
||||
|
||||
@@ -22,3 +20,4 @@ cmd_deps :: proc(cmd: ^Command) {
|
||||
|
||||
render_table(headers, rows[:])
|
||||
}
|
||||
|
||||
|
||||
@@ -3,47 +3,47 @@ package main
|
||||
import "core:fmt"
|
||||
import "core:os"
|
||||
import "core:path/filepath"
|
||||
import "core:strings"
|
||||
|
||||
cmd_edit_config :: proc(cmd: ^Command) {
|
||||
editor := os.get_env("EDITOR", context.allocator)
|
||||
if len(editor) == 0 {
|
||||
fmt.println("Error: $EDITOR environment variable is not set")
|
||||
return
|
||||
}
|
||||
editor := os.get_env("EDITOR", context.allocator)
|
||||
if len(editor) == 0 {
|
||||
fmt.println("Error: $EDITOR environment variable is not set")
|
||||
return
|
||||
}
|
||||
|
||||
config_path, join_err := filepath.join([]string{envr_dir(), "config.json"})
|
||||
if join_err != nil {
|
||||
fmt.printf("Error building config path: %v\n", join_err)
|
||||
return
|
||||
}
|
||||
config_path, join_err := filepath.join([]string{envr_dir(), "config.json"})
|
||||
if join_err != nil {
|
||||
fmt.printf("Error building config path: %v\n", join_err)
|
||||
return
|
||||
}
|
||||
|
||||
_, stat_err := os.stat(config_path, context.allocator)
|
||||
if stat_err != nil {
|
||||
fmt.printf("Config file does not exist at %s. Run 'envr init' first.\n", config_path)
|
||||
return
|
||||
}
|
||||
_, stat_err := os.stat(config_path, context.allocator)
|
||||
if stat_err != nil {
|
||||
fmt.printf("Config file does not exist at %s. Run 'envr init' first.\n", config_path)
|
||||
return
|
||||
}
|
||||
|
||||
args := []string{editor, config_path}
|
||||
desc := os.Process_Desc{
|
||||
command = args,
|
||||
stdin = os.stdin,
|
||||
stdout = os.stdout,
|
||||
stderr = os.stderr,
|
||||
}
|
||||
args := []string{editor, config_path}
|
||||
desc := os.Process_Desc {
|
||||
command = args,
|
||||
stdin = os.stdin,
|
||||
stdout = os.stdout,
|
||||
stderr = os.stderr,
|
||||
}
|
||||
|
||||
p, start_err := os.process_start(desc)
|
||||
if start_err != nil {
|
||||
fmt.printf("Error running editor: %v\n", start_err)
|
||||
return
|
||||
}
|
||||
p, start_err := os.process_start(desc)
|
||||
if start_err != nil {
|
||||
fmt.printf("Error running editor: %v\n", start_err)
|
||||
return
|
||||
}
|
||||
|
||||
state, wait_err := os.process_wait(p)
|
||||
if wait_err != nil {
|
||||
fmt.printf("Error waiting for editor: %v\n", wait_err)
|
||||
return
|
||||
}
|
||||
if state.exit_code != 0 {
|
||||
os.exit(int(state.exit_code))
|
||||
}
|
||||
state, wait_err := os.process_wait(p)
|
||||
if wait_err != nil {
|
||||
fmt.printf("Error waiting for editor: %v\n", wait_err)
|
||||
return
|
||||
}
|
||||
if state.exit_code != 0 {
|
||||
os.exit(int(state.exit_code))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
41
crypto.odin
41
crypto.odin
@@ -6,7 +6,11 @@ import "core:mem"
|
||||
MAGIC :: "ENVR"
|
||||
MAGIC_BYTES := [4]u8{u8('E'), u8('N'), u8('V'), u8('R')}
|
||||
|
||||
RECIPIENT_ENTRY_SIZE :: CRYPTO_BOX_PUBLICKEY_BYTES + CRYPTO_BOX_NONCE_BYTES + CRYPTO_SECRETBOX_KEY_BYTES + CRYPTO_BOX_MAC_BYTES
|
||||
RECIPIENT_ENTRY_SIZE ::
|
||||
CRYPTO_BOX_PUBLICKEY_BYTES +
|
||||
CRYPTO_BOX_NONCE_BYTES +
|
||||
CRYPTO_SECRETBOX_KEY_BYTES +
|
||||
CRYPTO_BOX_MAC_BYTES
|
||||
|
||||
HEADER_SIZE :: 4 + CRYPTO_BOX_PUBLICKEY_BYTES + CRYPTO_SECRETBOX_NONCE_BYTES + 4
|
||||
|
||||
@@ -108,7 +112,13 @@ encrypt :: proc(plaintext: []u8, keys: []SshKeyPair) -> (ciphertext: []u8, ok: b
|
||||
if len(plaintext) > 0 {
|
||||
pt_ptr = &plaintext[0]
|
||||
}
|
||||
rc := crypto_secretbox_easy(&secret_ct[0], pt_ptr, u64(len(plaintext)), &main_nonce[0], &sym_key[0])
|
||||
rc := crypto_secretbox_easy(
|
||||
&secret_ct[0],
|
||||
pt_ptr,
|
||||
u64(len(plaintext)),
|
||||
&main_nonce[0],
|
||||
&sym_key[0],
|
||||
)
|
||||
if rc != 0 {
|
||||
fmt.println("Error: symmetric encryption failed")
|
||||
delete(secret_ct)
|
||||
@@ -166,7 +176,11 @@ encrypt :: proc(plaintext: []u8, keys: []SshKeyPair) -> (ciphertext: []u8, ok: b
|
||||
pos += CRYPTO_BOX_PUBLICKEY_BYTES
|
||||
mem.copy(&ciphertext[pos], &entries[i].Nonce[0], CRYPTO_BOX_NONCE_BYTES)
|
||||
pos += CRYPTO_BOX_NONCE_BYTES
|
||||
mem.copy(&ciphertext[pos], &entries[i].EncryptedKey[0], CRYPTO_SECRETBOX_KEY_BYTES + CRYPTO_BOX_MAC_BYTES)
|
||||
mem.copy(
|
||||
&ciphertext[pos],
|
||||
&entries[i].EncryptedKey[0],
|
||||
CRYPTO_SECRETBOX_KEY_BYTES + CRYPTO_BOX_MAC_BYTES,
|
||||
)
|
||||
pos += CRYPTO_SECRETBOX_KEY_BYTES + CRYPTO_BOX_MAC_BYTES
|
||||
}
|
||||
|
||||
@@ -209,8 +223,11 @@ decrypt :: proc(ciphertext: []u8, keys: []SshKeyPair) -> (plaintext: []u8, ok: b
|
||||
}
|
||||
offset += CRYPTO_SECRETBOX_NONCE_BYTES
|
||||
|
||||
num_recipients := u32(ciphertext[offset]) << 24 | u32(ciphertext[offset + 1]) << 16 |
|
||||
u32(ciphertext[offset + 2]) << 8 | u32(ciphertext[offset + 3])
|
||||
num_recipients :=
|
||||
u32(ciphertext[offset]) << 24 |
|
||||
u32(ciphertext[offset + 1]) << 16 |
|
||||
u32(ciphertext[offset + 2]) << 8 |
|
||||
u32(ciphertext[offset + 3])
|
||||
offset += 4
|
||||
|
||||
recipients_end := offset + int(num_recipients) * RECIPIENT_ENTRY_SIZE
|
||||
@@ -233,7 +250,7 @@ decrypt :: proc(ciphertext: []u8, keys: []SshKeyPair) -> (plaintext: []u8, ok: b
|
||||
matched_pi := 0
|
||||
for pi in 0 ..< len(x25519_pairs) {
|
||||
scan_offset := offset
|
||||
for ri in 0 ..< int(num_recipients) {
|
||||
for _ in 0 ..< int(num_recipients) {
|
||||
for i in 0 ..< CRYPTO_BOX_PUBLICKEY_BYTES {
|
||||
enc_pub[i] = ciphertext[scan_offset + i]
|
||||
}
|
||||
@@ -247,7 +264,8 @@ decrypt :: proc(ciphertext: []u8, keys: []SshKeyPair) -> (plaintext: []u8, ok: b
|
||||
}
|
||||
}
|
||||
if !match {
|
||||
scan_offset += CRYPTO_BOX_NONCE_BYTES + CRYPTO_SECRETBOX_KEY_BYTES + CRYPTO_BOX_MAC_BYTES
|
||||
scan_offset +=
|
||||
CRYPTO_BOX_NONCE_BYTES + CRYPTO_SECRETBOX_KEY_BYTES + CRYPTO_BOX_MAC_BYTES
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -301,7 +319,13 @@ decrypt :: proc(ciphertext: []u8, keys: []SshKeyPair) -> (plaintext: []u8, ok: b
|
||||
if len(plaintext) > 0 {
|
||||
pt_ptr = &plaintext[0]
|
||||
}
|
||||
rc = crypto_secretbox_open_easy(pt_ptr, &ct_data[0], u64(len(ct_data)), &main_nonce[0], &sym_key[0])
|
||||
rc = crypto_secretbox_open_easy(
|
||||
pt_ptr,
|
||||
&ct_data[0],
|
||||
u64(len(ct_data)),
|
||||
&main_nonce[0],
|
||||
&sym_key[0],
|
||||
)
|
||||
if rc != 0 {
|
||||
fmt.println("Error: symmetric decryption failed")
|
||||
delete(plaintext)
|
||||
@@ -311,3 +335,4 @@ decrypt :: proc(ciphertext: []u8, keys: []SshKeyPair) -> (plaintext: []u8, ok: b
|
||||
ok = true
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
2
db.odin
2
db.odin
@@ -1,6 +1,5 @@
|
||||
package main
|
||||
|
||||
import "core:c"
|
||||
import "core:crypto/hash"
|
||||
import "core:encoding/hex"
|
||||
import "core:encoding/json"
|
||||
@@ -513,7 +512,6 @@ env_file_backup :: proc(f: ^EnvFile) -> bool {
|
||||
|
||||
env_file_sync :: proc(f: ^EnvFile, dir: SyncDirection, d: ^Db) -> (SyncFlag, string) {
|
||||
result: SyncFlag = {}
|
||||
err_msg: string
|
||||
|
||||
_, stat_err := os.stat(f.Dir, context.allocator)
|
||||
if stat_err != nil {
|
||||
|
||||
@@ -35,7 +35,6 @@ test_encrypt_decrypt_sqlite_roundtrip :: proc(t: ^testing.T) {
|
||||
defer {
|
||||
delete(cfg.Keys)
|
||||
}
|
||||
key := cfg.Keys[0]
|
||||
|
||||
db_path := fixture_db_path()
|
||||
sqlite_data, read_err := os.read_entire_file_from_path(db_path, context.allocator)
|
||||
@@ -319,7 +318,7 @@ test_config_load_with_fixture_key :: proc(t: ^testing.T) {
|
||||
testing.expectf(t, len(key.Private) > 0, "private key path should not be empty")
|
||||
testing.expectf(t, len(key.Public) > 0, "public key path should not be empty")
|
||||
|
||||
priv_kp, priv_ok := parse_ssh_private_key(key.Private)
|
||||
_, priv_ok := parse_ssh_private_key(key.Private)
|
||||
testing.expect(t, priv_ok, "should parse private key using config paths")
|
||||
if !priv_ok {
|
||||
fmt.printf(" private key path was: '%s'\n", key.Private)
|
||||
|
||||
@@ -19,7 +19,7 @@ CRYPTO_SIGN_SECRETKEY_BYTES :: 64
|
||||
@(default_calling_convention = "c")
|
||||
foreign libsodium {
|
||||
sodium_init :: proc() -> c.int ---
|
||||
crypto_box_keypair :: proc(pk: [^]u8, sk: [^]u8) -> c.int ---
|
||||
// crypto_box_keypair :: proc(pk: [^]u8, sk: [^]u8) -> c.int ---
|
||||
crypto_box_easy :: proc(ciphertext: [^]u8, plaintext: [^]u8, mlen: c.ulong, nonce: [^]u8, pk: [^]u8, sk: [^]u8) -> c.int ---
|
||||
crypto_box_open_easy :: proc(plaintext: [^]u8, ciphertext: [^]u8, clen: c.ulong, nonce: [^]u8, pk: [^]u8, sk: [^]u8) -> c.int ---
|
||||
crypto_secretbox_easy :: proc(ciphertext: [^]u8, plaintext: [^]u8, mlen: c.ulong, nonce: [^]u8, key: [^]u8) -> c.int ---
|
||||
@@ -28,3 +28,4 @@ foreign libsodium {
|
||||
crypto_sign_ed25519_sk_to_curve25519 :: proc(curve25519_sk: [^]u8, ed25519_sk: [^]u8) -> c.int ---
|
||||
randombytes_buf :: proc(buf: [^]u8, size: c.ulong) ---
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package main
|
||||
|
||||
import "core:fmt"
|
||||
import "core:os"
|
||||
import "core:strings"
|
||||
import "core:testing"
|
||||
|
||||
TEST_KEY_DIR :: "/tmp/envr-test-keys"
|
||||
@@ -49,7 +47,11 @@ test_private_key_pub_matches_public_key :: proc(t: ^testing.T) {
|
||||
testing.expect(
|
||||
t,
|
||||
pub_from_pub == kp.Public,
|
||||
fmt.tprintf("public key mismatch:\n from .pub: %v\n from priv: %v", pub_from_pub, kp.Public),
|
||||
fmt.tprintf(
|
||||
"public key mismatch:\n from .pub: %v\n from priv: %v",
|
||||
pub_from_pub,
|
||||
kp.Public,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -67,3 +69,4 @@ test_read_wire_string :: proc(t: ^testing.T) {
|
||||
testing.expect(t, ok2, "expected second read to succeed")
|
||||
testing.expect(t, s2 == "", "expected empty string")
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package main
|
||||
|
||||
import "core:encoding/json"
|
||||
import "core:fmt"
|
||||
import "core:io"
|
||||
import "core:strings"
|
||||
import "core:testing"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user