diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..50f5b2b --- /dev/null +++ b/.drone.yml @@ -0,0 +1,23 @@ +kind: pipeline +name: default + +steps: +- name: build + image: golang:1.17.2 + commands: + - git tag $DRONE_TAG + - bash make.sh + - echo -n "latest,${DRONE_TAG#v}" > .tags + +- name: gitea_release + image: plugins/gitea-release + settings: + api_key: + from_secret: gitea_api_key + base_url: https://kumoly.io + files: dist/* + checksum: + - sha256 + +trigger: + event: tag \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..53c37a1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +dist \ No newline at end of file diff --git a/README.md b/README.md index 7c90842..0c76d32 100644 --- a/README.md +++ b/README.md @@ -10,4 +10,23 @@ key := "key" enc := Encrypt(msg, key) dec, _ := Decrypt(enc, key) fmt.Printf("%s -> %s -> %s\n", msg, enc, dec) +``` + +## Helper cli + +```shell +usage: xorenc [e|d] msg key + +$ xorenc e test secret +BwAQBg== + +$ xorenc d BwAQBg== secret +test +``` + +### Install + +```sh +sudo rm -f /usr/local/bin/xorenc +sudo sh -c "curl -fsSL RELEASE_URL | tar -C /usr/local/bin/ -xz" ``` \ No newline at end of file diff --git a/cmd/xorenc/main.go b/cmd/xorenc/main.go new file mode 100644 index 0000000..1402f1a --- /dev/null +++ b/cmd/xorenc/main.go @@ -0,0 +1,46 @@ +package main + +import ( + "flag" + "fmt" + "os" + "strings" + + "kumoly.io/lib/xorencrypt" +) + +var Version = "0.0.0" +var Build = "alpha" + +var verFlag bool + +func init() { + flag.BoolVar(&verFlag, "v", false, "shoe version") +} + +func main() { + flag.Parse() + if verFlag { + fmt.Printf("%s - %s\n", Version, Build) + return + } + if len(os.Args) < 3 { + fmt.Println("usage: xorencrypt [e|d] msg key") + os.Exit(1) + } + key := "" + if len(os.Args) > 3 { + key = os.Args[3] + } + msg := os.Args[2] + + if strings.HasPrefix(os.Args[1], "e") { + fmt.Println(xorencrypt.Encrypt(msg, key)) + } else { + str, err := xorencrypt.Decrypt(msg, key) + if err != nil { + panic(err) + } + fmt.Println(str) + } +} diff --git a/make.sh b/make.sh new file mode 100644 index 0000000..65fbc7f --- /dev/null +++ b/make.sh @@ -0,0 +1,33 @@ + +VERSION=$(git describe --tags --abbrev=0) +if [ $? -ne 0 ]; then VERSION=$DRONE_TAG; fi +BUILD=$(git rev-parse --short HEAD) +if [ $? -ne 0 ]; then BUILD=${DRONE_COMMIT:0:7}; fi + +PROJ=xorenc +DIST=dist + +LDFLAGS="-ldflags \"-X main.Version=${VERSION} -X main.Build=${BUILD} -w -s\"" +FAILURES="" + +PLATFORMS="darwin/amd64 darwin/arm64" +PLATFORMS="$PLATFORMS windows/amd64" +PLATFORMS="$PLATFORMS linux/amd64" + + +for PLATFORM in $PLATFORMS; do + GOOS=${PLATFORM%/*} + GOARCH=${PLATFORM#*/} + BIN_FILENAME="${PROJ}" + if [[ "${GOOS}" == "windows" ]]; then BIN_FILENAME="${BIN_FILENAME}.exe"; fi + CMD="GOOS=${GOOS} GOARCH=${GOARCH} go build ${LDFLAGS} -o ${DIST}/${BIN_FILENAME} cmd/xorenc/main.go" + echo "${CMD}" + eval $CMD || FAILURES="${FAILURES} ${PLATFORM}" + sh -c "cd ${DIST} && tar -czf ${PROJ}-${VERSION}-${GOOS}-${GOARCH}.tar.gz ${BIN_FILENAME} && rm ${BIN_FILENAME}" +done + +if [[ "${FAILURES}" != "" ]]; then + echo "" + echo "${SCRIPT_NAME} failed on: ${FAILURES}" + exit 1 +fi \ No newline at end of file