From c95515af0ecb1b214699c1f2f7f3405186fac802 Mon Sep 17 00:00:00 2001 From: Sudhi Herle Date: Thu, 9 Mar 2023 17:20:50 +0000 Subject: [PATCH] Update dependencies; move go version to 1.20 * update build script to use a diff go-root * update tests.sh to use diff go-root * move pflag to opencoff/pflag * use common lib to parse string size.. --- build | 97 +++++++++++++++++++++++++++++++++++--------------------- crypt.go | 9 ++++-- go.mod | 10 +++--- go.sum | 17 +++++----- tests.sh | 10 +++++- 5 files changed, 89 insertions(+), 54 deletions(-) diff --git a/build b/build index 8889ecd..8e208d0 100755 --- a/build +++ b/build @@ -29,9 +29,8 @@ Static=0 Dryrun=0 Prodver="" Verbose=0 - -hostos=$(go env GOHOSTOS) || exit 1 -hostcpu=$(go env GOHOSTARCH) || exit 1 +GoRoot=$HOME/go +Go=$GoRoot/bin/go die() { echo "$Z: $@" 1>&2 @@ -50,35 +49,6 @@ case $BASH_VERSION in esac -# build a tool that runs on the host - if needed. -hosttool() { - local tool=$1 - local bindir=$2 - local src=$3 - - local p=$(type -P $tool) - if [ -n "$p" ]; then - echo $p - return 0 - fi - - # from here - we want this dir to find all build artifacts - PATH=$PATH:$bindir - export PATH - - p=$bindir/$tool - if [ -x $p ]; then - echo $p - return 0 - fi - - # build it and stash it in the hostdir - echo "Building tool $tool from $src .." - $e go get -d $src || exit 1 - $e go build -o $p $src || exit 1 - echo $p - return 0 -} usage() { @@ -112,6 +82,8 @@ Options: -t, --test Run "go test" on modules named on the command line [False] -v, --verbose Build verbosely (adds "-v" to go tooling) [False] --vet Run "go vet" on modules named on the command line [False] + --mod Run "go mod ..." [False] + --go-root=G Use Go in GOROOT 'G' [$GoRoot] -x Run in debug/trace mode [False] --print-arch Print the target architecture and exit EOF @@ -120,7 +92,6 @@ EOF } host=`uname|tr '[A-Z]' '[a-z]'` -export GO15VENDOREXPERIMENT=1 declare -A oses declare -A cpus @@ -181,6 +152,7 @@ do --arch=*) Arch=$ac_optarg ;; + -a|--arch) ac_prev=Arch ;; @@ -188,6 +160,7 @@ do --version=*) Prodver=$ac_optarg ;; + --test|-t) Tool=test ;; @@ -196,9 +169,14 @@ do Tool=vet ;; + --mod) + Tool=mod + ;; + -V|--version) ac_prev=Prodver ;; + -v|--verbose) Verbose=1 ;; @@ -215,6 +193,10 @@ do set -x ;; + --go-root=*) + GoRoot=$ac_optarg + ;; + --print-arch) Printarch=1 ;; @@ -230,10 +212,46 @@ do ;; esac done + [ $Dryrun -gt 0 ] && e=echo # let every error abort set -e +Go=$GoRoot/bin/go + +# build a tool that runs on the host - if needed. +hosttool() { + local tool=$1 + local bindir=$2 + local src=$3 + + local p=$(type -P $tool) + if [ -n "$p" ]; then + echo $p + return 0 + fi + + # from here - we want this dir to find all build artifacts + PATH=$PATH:$bindir + export PATH + + p=$bindir/$tool + if [ -x $p ]; then + echo $p + return 0 + fi + + # build it and stash it in the hostdir + echo "Building tool $tool from $src .." + $e $Go get -d $src || exit 1 + $e $Go build -o $p $src || exit 1 + echo $p + return 0 +} + + +hostos=$($Go env GOHOSTOS) || exit 1 +hostcpu=$($Go env GOHOSTARCH) || exit 1 # This fragment can't be in a function - since it exports several vars if [ -n "$Arch" ]; then @@ -322,7 +340,7 @@ if [ -n "$Protobufs" ]; then slick=$Hostbindir/protoc-gen-gogoslick slicksrc=github.com/gogo/protobuf/protoc-gen-gogoslick for pc in protoc protoc-c; do - pc=`which $pc` + pc=$(type -p $pc) [ -n "$pc" ] && break done @@ -359,12 +377,17 @@ vflag="" case $Tool in test) set -- $args - $e go test $vflag "$@" + $e $Go test $vflag "$@" ;; vet) set -- $args - $e go vet $vflag "$@" + $e $Go vet $vflag "$@" + ;; + + mod) + set -- $args + $e $Go mod $vflag "$@" ;; *) # Default is to build programs @@ -386,7 +409,7 @@ case $Tool in dir=$p fi echo " $dir: $out .. " - $e eval go build $vflag -o $Bindir/$out $isuffix "$ldflags" ./$dir || exit 1 + $e eval $Go build $vflag -o $Bindir/$out $isuffix "$ldflags" ./$dir || exit 1 done ;; esac diff --git a/crypt.go b/crypt.go index 8335960..d6122f3 100644 --- a/crypt.go +++ b/crypt.go @@ -35,7 +35,8 @@ func encrypt(args []string) { var outfile string var keyfile string - var envpw string + var szstr string = "128k" + var envpw string var nopw, force bool var blksize uint64 @@ -43,7 +44,7 @@ func encrypt(args []string) { fs.StringVarP(&keyfile, "sign", "s", "", "Sign using private key `S`") fs.BoolVarP(&nopw, "no-password", "", false, "Don't ask for passphrase to decrypt the private key") fs.StringVarP(&envpw, "env-password", "E", "", "Use passphrase from environment variable `E`") - fs.SizeVarP(&blksize, "block-size", "B", 128*1024, "Use `S` as the encryption block size") + fs.StringVarP(&szstr, "block-size", "B", szstr, "Use `S` as the encryption block size") fs.BoolVarP(&force, "overwrite", "", false, "Overwrite the output file if it exists") err := fs.Parse(args) @@ -51,6 +52,10 @@ func encrypt(args []string) { Die("%s", err) } + if blksize, err = utils.ParseSize(szstr); err != nil { + Die("%s", err) + } + var pws, infile string var sk *sign.PrivateKey diff --git a/go.mod b/go.mod index 61ec962..baa9046 100644 --- a/go.mod +++ b/go.mod @@ -1,17 +1,17 @@ module github.com/opencoff/sigtool -go 1.18 +go 1.20 require ( github.com/dchest/bcrypt_pbkdf v0.0.0-20150205184540-83f37f9c154a github.com/gogo/protobuf v1.3.2 github.com/opencoff/go-utils v0.4.1 - github.com/opencoff/pflag v0.5.0 - golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd + github.com/opencoff/pflag v1.0.6-sh1 + golang.org/x/crypto v0.7.0 gopkg.in/yaml.v2 v2.4.0 ) require ( - golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect - golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 // indirect + golang.org/x/sys v0.6.0 // indirect + golang.org/x/term v0.6.0 // indirect ) diff --git a/go.sum b/go.sum index eec97f1..349aa00 100644 --- a/go.sum +++ b/go.sum @@ -6,16 +6,16 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/opencoff/go-utils v0.4.1 h1:Ke4Q1Tl2GKMI+dwleuPNHH713ngRiNMOFIkymncHqXg= github.com/opencoff/go-utils v0.4.1/go.mod h1:c+7QUAiCCHcNH6OGvsZ0fviG7cgse8Y3ucg+xy7sGXM= -github.com/opencoff/pflag v0.5.0 h1:kK3cSTlGj0fHby/PoFzHkf+Jx3PdiACJwzYDWEWlEKQ= -github.com/opencoff/pflag v0.5.0/go.mod h1:mTLzGGUGda1Av3d34iAJlh0JIlRxmFZtmc6qoWPspK0= +github.com/opencoff/pflag v1.0.6-sh1 h1:6RO8GgnpH928yu6earGDD01FnFT//bDJ1hCovcVVqY4= +github.com/opencoff/pflag v1.0.6-sh1/go.mod h1:2bXtpAD/5h/2LarkbsRwiUxqnvB1nZBzn9Xjad1P41A= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190618222545-ea8f1a30c443/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd h1:XcWmESyNjXJMLahc3mqVQJcgSTDxFxhETVlfk9uGc38= -golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A= +golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= @@ -28,11 +28,10 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw= +golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/tests.sh b/tests.sh index 4184a46..42b9464 100755 --- a/tests.sh +++ b/tests.sh @@ -3,7 +3,15 @@ # simple round-trip tests to verify the tool -arch=`./build --print-arch` +# Use cmdline flag to get go-root + +GoRoot=$HOME/go + +if [ -n "$1" ]; then + GoRoot=$1 +fi + +arch=`./build --go-root=$GoRoot --print-arch` bin=./bin/$arch/sigtool Z=`basename $0`