URI: 
       tStyle fixes. - tordam - A library for peer discovery inside the Tor network
  HTML git clone https://git.parazyd.org/tordam
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit 7a8b2ca208e22bd2c99b47af8eec7b96e1bda418
   DIR parent 2b43a7b2ad6b6652dd63df16dc33816fa02ca617
  HTML Author: parazyd <parazyd@dyne.org>
       Date:   Wed, 13 Dec 2017 03:36:48 +0100
       
       Style fixes.
       
       Diffstat:
         M cmd/dam-client/main.go              |       5 ++---
         M cmd/dam-dir/main.go                 |       6 +++---
         M pkg/damlib/crypto_rsa.go            |      23 +++++++----------------
         M pkg/damlib/tor.go                   |       3 +--
         M pkg/damlib/validate.go              |      17 +++++++----------
       
       5 files changed, 20 insertions(+), 34 deletions(-)
       ---
   DIR diff --git a/cmd/dam-client/main.go b/cmd/dam-client/main.go
       t@@ -185,12 +185,11 @@ func main() {
                }
                wg.Wait()
        
       -        if ann > 0 {
       -                log.Printf("Successfully authenticated with %d nodes.\n", ann)
       -        } else {
       +        if ann < 1 {
                        cmd.Process.Kill()
                        log.Fatalln("No successful authentications. Exiting.")
                }
       +        log.Printf("Successfully authenticated with %d nodes.\n", ann)
        
                err = cmd.Wait() // Hidden service Python daemon
                lib.CheckError(err)
   DIR diff --git a/cmd/dam-dir/main.go b/cmd/dam-dir/main.go
       t@@ -65,8 +65,7 @@ func handlePost(rw http.ResponseWriter, request *http.Request) {
                }
        
                decoder := json.NewDecoder(request.Body)
       -        err := decoder.Decode(&n)
       -        if err != nil {
       +        if err := decoder.Decode(&n); err != nil {
                        log.Println("Failed decoding request:", err)
                        return
                }
       t@@ -142,8 +141,9 @@ func handlePost(rw http.ResponseWriter, request *http.Request) {
                }
        }
        
       +// handleElse is a noop for anything that isn't /announce. We don't care about
       +// other requests (yet).
        func handleElse(rw http.ResponseWriter, request *http.Request) {
       -        // noop for anything that isn't /announce.
                return
        }
        
   DIR diff --git a/pkg/damlib/crypto_rsa.go b/pkg/damlib/crypto_rsa.go
       t@@ -49,12 +49,10 @@ func SavePubRsa(filename string, pubkey rsa.PublicKey) error {
                        Type:  "RSA PUBLIC KEY",
                        Bytes: asn1Bytes,
                }
       -        err = pem.Encode(outfile, pemkey)
       -        if err != nil {
       +        if err = pem.Encode(outfile, pemkey); err != nil {
                        return err
                }
       -        err = outfile.Chmod(0400)
       -        if err != nil {
       +        if err = outfile.Chmod(0400); err != nil {
                        return err
                }
                return nil
       t@@ -74,12 +72,10 @@ func SavePrivRsa(filename string, privkey *rsa.PrivateKey) error {
                        Type:  "RSA PRIVATE KEY",
                        Bytes: x509.MarshalPKCS1PrivateKey(privkey),
                }
       -        err = pem.Encode(outfile, pemkey)
       -        if err != nil {
       +        if err = pem.Encode(outfile, pemkey); err != nil {
                        return err
                }
       -        err = outfile.Chmod(0400)
       -        if err != nil {
       +        if err = outfile.Chmod(0400); err != nil {
                        return err
                }
                return nil
       t@@ -151,12 +147,9 @@ func DecryptMsgRsa(message []byte, privkey *rsa.PrivateKey) ([]byte, error) {
        func VerifyMsgRsa(message []byte, signature []byte, pubkey *rsa.PublicKey) (bool, error) {
                log.Println("Verifying message signature")
                hashed := sha512.Sum512(message)
       -        err := rsa.VerifyPKCS1v15(pubkey, crypto.SHA512, hashed[:], signature)
       -        if err != nil {
       -                log.Println("Signature invalid")
       +        if err := rsa.VerifyPKCS1v15(pubkey, crypto.SHA512, hashed[:], signature); err != nil {
                        return false, err
                }
       -        log.Println("Signature valid")
                return true, nil
        }
        
       t@@ -169,8 +162,7 @@ func OnionFromPubkeyRsa(pubkey rsa.PublicKey) ([]byte, error) {
                        return nil, err
                }
                hashed := sha1.New()
       -        _, err = hashed.Write(asn1Bytes)
       -        if err != nil {
       +        if _, err = hashed.Write(asn1Bytes); err != nil {
                        return nil, err
                }
                encoded := strings.ToLower(base32.StdEncoding.EncodeToString(hashed.Sum(nil)))[:16]
       t@@ -185,8 +177,7 @@ func ParsePubkeyRsa(pubkey []byte) (*rsa.PublicKey, error) {
                var pub rsa.PublicKey
                var ret *rsa.PublicKey
                block, _ := pem.Decode(pubkey)
       -        _, err := asn1.Unmarshal(block.Bytes, &pub)
       -        if err != nil {
       +        if _, err := asn1.Unmarshal(block.Bytes, &pub); err != nil {
                        return nil, err
                }
                ret = &pub
   DIR diff --git a/pkg/damlib/tor.go b/pkg/damlib/tor.go
       t@@ -22,8 +22,7 @@ func FetchHSPubkey(addr string) string {
                err := cmd.Start()
                CheckError(err)
        
       -        err = cmd.Wait()
       -        if err != nil {
       +        if err = cmd.Wait(); err != nil {
                        log.Println("Could not fetch descriptor:", err)
                        return ""
                }
   DIR diff --git a/pkg/damlib/validate.go b/pkg/damlib/validate.go
       t@@ -31,6 +31,7 @@ func sanityCheck(req map[string]string, handshake int) (bool, string) {
                if _, err := base64.StdEncoding.DecodeString(req["signature"]); err != nil {
                        return false, err.Error()
                }
       +
                // TODO: When a node wants to promote itself from something it already was,
                // what to do?
                switch req["nodetype"] {
       t@@ -69,8 +70,7 @@ func sanityCheck(req map[string]string, handshake int) (bool, string) {
        // On any failure, the function will return false, and produce an according
        // string which is to be considered as an error message.
        func ValidateFirstHandshake(req map[string]string) (bool, string) {
       -        sane, what := sanityCheck(req, 1)
       -        if !(sane) {
       +        if sane, what := sanityCheck(req, 1); !(sane) {
                        return false, what
                }
        
       t@@ -114,8 +114,7 @@ func ValidateFirstHandshake(req map[string]string) (bool, string) {
                sig := []byte(decSig)
                pubkey, err := ParsePubkeyRsa([]byte(pub)) // pubkey is their public key in *rsa.PublicKey type
                CheckError(err)
       -        val, _ := VerifyMsgRsa(msg, sig, pubkey)
       -        if val != true {
       +        if val, _ := VerifyMsgRsa(msg, sig, pubkey); !(val) {
                        log.Println("crypto/rsa: verification failure")
                        return false, "Signature verification failure."
                }
       t@@ -170,8 +169,7 @@ func ValidateFirstHandshake(req map[string]string) (bool, string) {
        // will return false, and an according string which is to be considered an error
        // message.
        func ValidateSecondHandshake(req map[string]string) (bool, string) {
       -        sane, what := sanityCheck(req, 2)
       -        if !(sane) {
       +        if sane, what := sanityCheck(req, 2); !(sane) {
                        return false, what
                }
        
       t@@ -198,7 +196,7 @@ func ValidateSecondHandshake(req map[string]string) (bool, string) {
                CheckError(err)
        
                if !(localSec == req["secret"] && localSec == req["message"]) {
       -                log.Println("Secrets don't match.")
       +                log.Printf("%s: Secrets don't match.\n", req["address"])
                        return false, "Secrets don't match."
                }
        
       t@@ -208,9 +206,8 @@ func ValidateSecondHandshake(req map[string]string) (bool, string) {
                sig := []byte(decSig)
                pubkey, err := ParsePubkeyRsa([]byte(pub)) // pubkey is their public key in *rsa.PublicKey type
                CheckError(err)
       -        val, _ := VerifyMsgRsa(msg, sig, pubkey)
       -        if val != true {
       -                log.Println("crypto/rsa: verification failure")
       +        if val, _ := VerifyMsgRsa(msg, sig, pubkey); !(val) {
       +                log.Printf("%s: Signature verification failure\n", req["address"])
                        return false, "Signature verification failure."
                }