mirror of
https://github.com/rwinkhart/rcw.git
synced 2026-09-03 23:57:28 -04:00
Implement sanity check in example program
This commit is contained in:
@@ -2,3 +2,5 @@
|
|||||||
/main.exe
|
/main.exe
|
||||||
/rcw
|
/rcw
|
||||||
/rcw.exe
|
/rcw.exe
|
||||||
|
/ex-cipher.rcw
|
||||||
|
/ex-sanity.rcw
|
||||||
|
|||||||
+17
-2
@@ -11,6 +11,7 @@ import (
|
|||||||
// of RCW before building it into your own application.
|
// of RCW before building it into your own application.
|
||||||
//
|
//
|
||||||
// Usage:
|
// Usage:
|
||||||
|
// rcw init <passwd> : Generates the required sanity check file
|
||||||
// rcw <text> : Runs the rcw daemon to serve the provided text for three minutes
|
// rcw <text> : Runs the rcw daemon to serve the provided text for three minutes
|
||||||
// rcw : Requests the data served by the RCW daemon and outputs it to stdout
|
// rcw : Requests the data served by the RCW daemon and outputs it to stdout
|
||||||
// rcw enc <text> <passwd> : Encrypts the provided text and outputs the ciphertext to encrypted-example.txt
|
// rcw enc <text> <passwd> : Encrypts the provided text and outputs the ciphertext to encrypted-example.txt
|
||||||
@@ -35,8 +36,17 @@ func main() {
|
|||||||
// serve data
|
// serve data
|
||||||
daemon.Start(os.Args[1])
|
daemon.Start(os.Args[1])
|
||||||
case 3:
|
case 3:
|
||||||
|
if os.Args[1] == "init" {
|
||||||
|
// create sanity check file
|
||||||
|
err := wrappers.GenSanityCheck("ex-sanity.rcw", []byte(os.Args[2]))
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// decrypt file
|
// decrypt file
|
||||||
encBytes, _ := os.ReadFile("encrypted-example.txt")
|
encBytes, _ := os.ReadFile("ex-cipher.rcw")
|
||||||
decBytes, err := wrappers.Decrypt(encBytes, []byte(os.Args[2]))
|
decBytes, err := wrappers.Decrypt(encBytes, []byte(os.Args[2]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
@@ -45,8 +55,13 @@ func main() {
|
|||||||
fmt.Println(string(decBytes))
|
fmt.Println(string(decBytes))
|
||||||
case 4:
|
case 4:
|
||||||
// encrypt data (from cli args)
|
// encrypt data (from cli args)
|
||||||
|
err := wrappers.RunSanityCheck("ex-sanity.rcw", []byte(os.Args[3]))
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
encBytes := wrappers.Encrypt([]byte(os.Args[2]), []byte(os.Args[3]))
|
encBytes := wrappers.Encrypt([]byte(os.Args[2]), []byte(os.Args[3]))
|
||||||
os.WriteFile("encrypted-example.txt", encBytes, 0644)
|
os.WriteFile("ex-cipher.rcw", encBytes, 0600)
|
||||||
default:
|
default:
|
||||||
// request served data
|
// request served data
|
||||||
fmt.Println(daemon.Call())
|
fmt.Println(daemon.Call())
|
||||||
|
|||||||
@@ -8,8 +8,9 @@ import (
|
|||||||
// GenSanityCheck creates an encrypted file containing known plaintext
|
// GenSanityCheck creates an encrypted file containing known plaintext
|
||||||
// to later be used for ensuring the user does not encrypt data with
|
// to later be used for ensuring the user does not encrypt data with
|
||||||
// an incorrect passphrase.
|
// an incorrect passphrase.
|
||||||
func GenSanityCheck(path string, passphrase []byte) {
|
func GenSanityCheck(path string, passphrase []byte) error {
|
||||||
os.WriteFile(path, Encrypt([]byte("thx4usin'rcw"), passphrase), 0600)
|
err := os.WriteFile(path, Encrypt([]byte("thx4usin'rcw"), passphrase), 0600)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunSanityCheck should be run before any encryption operation
|
// RunSanityCheck should be run before any encryption operation
|
||||||
|
|||||||
Reference in New Issue
Block a user