Skip to content

Commit 2081b4e

Browse files
committed
remove croc gen
1 parent 9e02fa7 commit 2081b4e

File tree

1 file changed

+3
-76
lines changed

1 file changed

+3
-76
lines changed

main.go

+3-76
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@ package main
33
import (
44
"errors"
55
"fmt"
6-
"io/ioutil"
7-
"math/rand"
86
"os"
9-
"path"
107
"strings"
118
"time"
129

13-
homedir "github.com/mitchellh/go-homedir"
1410
croc "github.com/schollz/croc/src"
1511
"github.com/urfave/cli"
1612
)
@@ -33,7 +29,7 @@ func main() {
3329
app.UsageText = "croc allows any two computers to directly and securely transfer files"
3430
// app.ArgsUsage = "[args and such]"
3531
app.Commands = []cli.Command{
36-
cli.Command{
32+
{
3733
Name: "send",
3834
Usage: "send a file",
3935
Description: "send a file over the relay",
@@ -47,34 +43,7 @@ func main() {
4743
return send(c)
4844
},
4945
},
50-
cli.Command{
51-
Name: "gen",
52-
Usage: "generate a permanent key",
53-
Description: "generates a permanent key that is used each time",
54-
HelpName: "croc gen",
55-
ArgsUsage: "[key]",
56-
Flags: []cli.Flag{
57-
cli.BoolFlag{Name: "new", Usage: "overwrite key if it exists"},
58-
},
59-
Action: func(c *cli.Context) error {
60-
homedir, err := homedir.Dir()
61-
if err != nil {
62-
return err
63-
}
64-
if codePhrase == "" || c.Bool("new") {
65-
codePhrase = randStringBytesMaskImprSrc(50)
66-
if c.Args().First() != "" {
67-
codePhrase = c.Args().First()
68-
}
69-
os.MkdirAll(path.Join(homedir, ".config", "croc"), 0644)
70-
err = ioutil.WriteFile(path.Join(homedir, ".config", "croc", "key"), []byte(codePhrase), 0644)
71-
}
72-
fmt.Printf("your permanent key: %s\n", codePhrase)
73-
fmt.Println("use -new if you want to regenerate your key")
74-
return err
75-
},
76-
},
77-
cli.Command{
46+
{
7847
Name: "receive",
7948
Usage: "receive a file",
8049
Description: "receve a file over the relay",
@@ -83,7 +52,7 @@ func main() {
8352
return receive(c)
8453
},
8554
},
86-
cli.Command{
55+
{
8756
Name: "relay",
8857
Usage: "start a croc relay",
8958
Description: "the croc relay will handle websocket and TCP connections",
@@ -125,20 +94,6 @@ func main() {
12594
cr.Stdout = c.GlobalBool("stdout")
12695
cr.LocalOnly = c.GlobalBool("local")
12796
cr.NoLocal = c.GlobalBool("no-local")
128-
129-
// check if permanent code phrase is here
130-
homedir, err := homedir.Dir()
131-
if err != nil {
132-
return err
133-
}
134-
keyFile := path.Join(homedir, ".config", "croc", "key")
135-
if _, err := os.Stat(keyFile); err == nil {
136-
codePhraseBytes, err := ioutil.ReadFile(keyFile)
137-
if err == nil {
138-
codePhrase = string(codePhraseBytes)
139-
}
140-
}
141-
14297
return nil
14398
}
14499

@@ -183,31 +138,3 @@ func relay(c *cli.Context) error {
183138
cr.CurveType = c.String("curve")
184139
return cr.Relay()
185140
}
186-
187-
// needed for croc gen
188-
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
189-
const (
190-
letterIdxBits = 6 // 6 bits to represent a letter index
191-
letterIdxMask = 1<<letterIdxBits - 1 // All 1-bits, as many as letterIdxBits
192-
letterIdxMax = 63 / letterIdxBits // # of letter indices fitting in 63 bits
193-
)
194-
195-
var src = rand.NewSource(time.Now().UnixNano())
196-
197-
func randStringBytesMaskImprSrc(n int) string {
198-
b := make([]byte, n)
199-
// A src.Int63() generates 63 random bits, enough for letterIdxMax characters!
200-
for i, cache, remain := n-1, src.Int63(), letterIdxMax; i >= 0; {
201-
if remain == 0 {
202-
cache, remain = src.Int63(), letterIdxMax
203-
}
204-
if idx := int(cache & letterIdxMask); idx < len(letterBytes) {
205-
b[i] = letterBytes[idx]
206-
i--
207-
}
208-
cache >>= letterIdxBits
209-
remain--
210-
}
211-
212-
return string(b)
213-
}

0 commit comments

Comments
 (0)