-
Notifications
You must be signed in to change notification settings - Fork 846
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor main to use Cobra command line framework and package restruc…
…ture Reorganized the Go package structure, moving the main package to 'cmd'. Upgraded the flag library to Cobra for better management of CLI commands. This included moving the X25519 key generation from a flag to its own standalone Cobra command, which improves user interaction and code modularity. This structural change will benefit future additions and code maintainability.
- Loading branch information
1 parent
edf0230
commit 1641b63
Showing
20 changed files
with
157 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
main/main | ||
main/XrayR | ||
main/XrayR* | ||
main/mytest | ||
main/access.logo | ||
main/error.log | ||
api/chooseparser.go.bak | ||
common/Inboundbuilder/.lego/ | ||
common/legocmd/.lego/ | ||
.vscode/launch.json | ||
main/.lego | ||
main/cert | ||
main/config.yml | ||
./vscode | ||
.idea/* | ||
.DS_Store | ||
*.bak | ||
go.work* | ||
.idea | ||
*.iml | ||
out | ||
gen | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
*.test | ||
*.out | ||
go.work | ||
main | ||
XrayR | ||
XrayR* | ||
access.log | ||
error.log | ||
.lego | ||
cert | ||
config.yml |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
version = "0.9.1" | ||
codename = "XrayR" | ||
intro = "A Xray backend that supports many panels" | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(&cobra.Command{ | ||
Use: "version", | ||
Short: "Print current version of XrayR", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
showVersion() | ||
}, | ||
}) | ||
} | ||
|
||
func showVersion() { | ||
fmt.Printf("%s %s (%s) \n", codename, version, intro) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package cmd | ||
|
||
import ( | ||
"crypto/rand" | ||
"encoding/base64" | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
"golang.org/x/crypto/curve25519" | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(&cobra.Command{ | ||
Use: "x25519", | ||
Short: "Generate key pair for x25519 key exchange", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if err := x25519(); err != nil { | ||
fmt.Println(err) | ||
} | ||
}, | ||
}) | ||
} | ||
|
||
func x25519() error { | ||
var publicKey []byte | ||
privateKey := make([]byte, curve25519.ScalarSize) | ||
if _, err := rand.Read(privateKey); err != nil { | ||
return err | ||
} | ||
|
||
// Modify random bytes using algorithm described at: | ||
// https://cr.yp.to/ecdh.html. | ||
privateKey[0] &= 248 | ||
privateKey[31] &= 127 | ||
privateKey[31] |= 64 | ||
|
||
publicKey, err := curve25519.X25519(privateKey, curve25519.Basepoint) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
output := fmt.Sprintf("Private key: %v\nPublic key: %v", | ||
base64.RawURLEncoding.EncodeToString(privateKey), | ||
base64.RawURLEncoding.EncodeToString(publicKey)) | ||
fmt.Println(output) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,2 @@ | ||
// Package common contains common utilities that are shared among other packages. | ||
package common | ||
|
||
import ( | ||
"crypto/rand" | ||
"encoding/base64" | ||
"fmt" | ||
|
||
"golang.org/x/crypto/curve25519" | ||
) | ||
|
||
func X25519() { | ||
var publicKey []byte | ||
privateKey := make([]byte, curve25519.ScalarSize) | ||
if _, err := rand.Read(privateKey); err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
|
||
// Modify random bytes using algorithm described at: | ||
// https://cr.yp.to/ecdh.html. | ||
privateKey[0] &= 248 | ||
privateKey[31] &= 127 | ||
privateKey[31] |= 64 | ||
|
||
publicKey, err := curve25519.X25519(privateKey, curve25519.Basepoint) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
|
||
output := fmt.Sprintf("Private key: %v\nPublic key: %v", | ||
base64.RawURLEncoding.EncodeToString(privateKey), | ||
base64.RawURLEncoding.EncodeToString(publicKey)) | ||
fmt.Println(output) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/XrayR-project/XrayR/cmd" | ||
) | ||
|
||
func main() { | ||
if err := cmd.Execute(); err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters