mirror of
https://github.com/kovidgoyal/kitty.git
synced 2024-09-21 11:39:57 +03:00
Move the command types into a separate package
This commit is contained in:
parent
45540561cc
commit
4432c1a2ea
@ -10,20 +10,12 @@ import (
|
||||
"fmt"
|
||||
"golang.org/x/crypto/curve25519"
|
||||
"kitty/tools/base85"
|
||||
"kitty/tools/utils"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Cmd struct {
|
||||
Cmd string `json:"cmd"`
|
||||
Version [3]int `json:"version"`
|
||||
NoResponse bool `json:"no_response,omitifempty"`
|
||||
Payload map[string]interface{} `json:"payload,omitifempty"`
|
||||
Timestamp int64 `json:"timestamp,omitifempty"`
|
||||
Password string `json:"password,omitifempty"`
|
||||
}
|
||||
|
||||
func curve25519_key_pair() (private_key []byte, public_key []byte, err error) {
|
||||
private_key = make([]byte, 32)
|
||||
_, err = rand.Read(private_key)
|
||||
@ -78,15 +70,7 @@ func encrypt(plaintext []byte, alice_public_key []byte) (iv []byte, tag []byte,
|
||||
return
|
||||
}
|
||||
|
||||
type EncryptedCmd struct {
|
||||
Version [3]int `json:"version"`
|
||||
IV string `json:"iv"`
|
||||
Tag string `json:"tag"`
|
||||
Pubkey string `json:"pubkey"`
|
||||
Encrypted string `json:"encrypted"`
|
||||
}
|
||||
|
||||
func Encrypt_cmd(cmd *Cmd, password string, other_pubkey []byte) (encrypted_cmd EncryptedCmd, err error) {
|
||||
func Encrypt_cmd(cmd *utils.RemoteControlCmd, password string, other_pubkey []byte) (encrypted_cmd utils.EncryptedRemoteControlCmd, err error) {
|
||||
if len(other_pubkey) == 0 {
|
||||
raw := os.Getenv("KITTY_PUBLIC_KEY")
|
||||
if len(raw) == 0 {
|
||||
@ -109,7 +93,7 @@ func Encrypt_cmd(cmd *Cmd, password string, other_pubkey []byte) (encrypted_cmd
|
||||
return
|
||||
}
|
||||
iv, tag, ciphertext, pubkey, err := encrypt(plaintext, other_pubkey)
|
||||
encrypted_cmd = EncryptedCmd{
|
||||
encrypted_cmd = utils.EncryptedRemoteControlCmd{
|
||||
Version: cmd.Version, IV: b85_encode(iv), Tag: b85_encode(tag), Pubkey: b85_encode(pubkey), Encrypted: b85_encode(ciphertext)}
|
||||
return
|
||||
}
|
||||
|
18
tools/utils/types.go
Normal file
18
tools/utils/types.go
Normal file
@ -0,0 +1,18 @@
|
||||
package utils
|
||||
|
||||
type RemoteControlCmd struct {
|
||||
Cmd string `json:"cmd"`
|
||||
Version [3]int `json:"version"`
|
||||
NoResponse bool `json:"no_response,omitifempty"`
|
||||
Payload map[string]interface{} `json:"payload,omitifempty"`
|
||||
Timestamp int64 `json:"timestamp,omitifempty"`
|
||||
Password string `json:"password,omitifempty"`
|
||||
}
|
||||
|
||||
type EncryptedRemoteControlCmd struct {
|
||||
Version [3]int `json:"version"`
|
||||
IV string `json:"iv"`
|
||||
Tag string `json:"tag"`
|
||||
Pubkey string `json:"pubkey"`
|
||||
Encrypted string `json:"encrypted"`
|
||||
}
|
Loading…
Reference in New Issue
Block a user