Specify and solidify usage modes

This commit is contained in:
2025-05-08 20:18:31 +00:00
parent 9d7417e26d
commit d324e62474
4 changed files with 32 additions and 5 deletions
+2 -2
View File
@@ -6,9 +6,9 @@ import (
var binPath, _ = os.Executable() // store binary path
// daemonIsOpen checks if the socket/named pipe for the rcw
// IsOpen checks if the socket/named pipe for the rcw
// daemon exists and returns a boolean indicator.
func daemonIsOpen() bool {
func IsOpen() bool {
fileInfo, err := os.Stat(socketPath)
if err != nil {
return false
+2 -2
View File
@@ -9,7 +9,7 @@ import (
// DecryptWithDaemonIfOpen uses the RCW daemon (if one is available) to
// decrypt and return data. If no RCW daemon is accessible, nil is returned.
func DecryptWithDaemonIfOpen(encBytes []byte) []byte {
if daemonIsOpen() {
if IsOpen() {
return getDecFromDaemon(encBytes)
}
return nil
@@ -18,7 +18,7 @@ func DecryptWithDaemonIfOpen(encBytes []byte) []byte {
// EncryptWithDaemonIfOpen uses the RCW daemon (if one is available) to
// encrypt and return data. If no RCW daemon is accessible, nil is returned.
func EncryptWithDaemonIfOpen(decBytes []byte) []byte {
if daemonIsOpen() {
if IsOpen() {
return getEncFromDaemon(decBytes)
}
return nil
+26 -1
View File
@@ -18,6 +18,23 @@ import (
// rcw enc <text> : Encrypts the provided text and outputs the ciphertext to ex-cipher.rcw (attempts to use daemon, falls back to user input for passphrase)
// rcw dec : Decrypts ex-cipher.rcw and outputs the plaintext to stdout (attempts to use daemon, falls back to user input for passphrase)
// Implementation Notes:
// There are two main ways to use the RCW library:
//
// 1. Daemon mode:
// The daemon is started with a passphrase and runs in the background.
// All encryption/decryption occurs in the daemon.
// Avoid using the wrapper.Encrypt/Decrypt functions directly.
// Instead, cache the passphrase with the daemon and use the daemon to encrypt/decrypt data.
//
// 2. Standalone mode:
// The wrapper.Encrypt/Decrypt functions are used directly.
// The passphrase is provided directly to the functions.
//
// It is up to the client to perform the sanity check before encrypting data.
// This means that when using the daemon to cache the passphrase, the client should
// perform the sanity check before activating the daemon.
// TODO Tests:
// Salt (aes+chacha)
// Nonce (aes+chacha)
@@ -26,7 +43,6 @@ import (
// RPC password sharing
// TODO Enhancements:
// Fix sanity check (should be performed when starting the daemon to ensure the correct passphrase is used)
// Standalone cmd:
// Usable as symmetric-only GPG replacement
@@ -61,6 +77,15 @@ func main() {
}
// run decrypter daemon
// rcw <passwd>
if daemon.IsOpen() {
fmt.Println("Daemon already running")
return
}
err := wrappers.RunSanityCheck(sanityFile, []byte(os.Args[1]))
if err != nil {
fmt.Println(err)
return
}
daemon.Start([]byte(os.Args[1]))
case 3:
if os.Args[1] == "init" {
+2
View File
@@ -1,6 +1,7 @@
package wrappers
// Decrypt decrypts the provided byte slice using the provided passphrase.
// Do NOT use directly if using the RCW daemon.
func Decrypt(encBytes []byte, passphrase []byte) ([]byte, error) {
var err error = nil
encBytes, err = decryptCha(encBytes, passphrase)
@@ -15,6 +16,7 @@ func Decrypt(encBytes []byte, passphrase []byte) ([]byte, error) {
}
// Encrypt encrypts the provided byte slice using the provided passphrase.
// Do NOT use directly if using the RCW daemon.
func Encrypt(decBytes []byte, passphrase []byte) []byte {
decBytes = encryptAES(decBytes, passphrase)
decBytes = encryptCha(decBytes, passphrase)