diff options
author | Unknwon <joe2010xtmf@163.com> | 2014-10-11 20:34:48 -0400 |
---|---|---|
committer | Unknwon <joe2010xtmf@163.com> | 2014-10-11 20:34:48 -0400 |
commit | fb839ca0fb998f2dfdd280e959f85a576bb7742b (patch) | |
tree | eda24a72c4b9a4a2c7337a4db38c64efc4c0e292 /models/publickey.go | |
parent | b7b7863364b9dae96a4d4a1a78089742e10c5322 (diff) | |
download | gitea-fb839ca0fb998f2dfdd280e959f85a576bb7742b.tar.gz gitea-fb839ca0fb998f2dfdd280e959f85a576bb7742b.zip |
More debug info
Diffstat (limited to 'models/publickey.go')
-rw-r--r-- | models/publickey.go | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/models/publickey.go b/models/publickey.go index dbfed46cb7..aac5a81aeb 100644 --- a/models/publickey.go +++ b/models/publickey.go @@ -108,7 +108,7 @@ var ( // CheckPublicKeyString checks if the given public key string is recognized by SSH. func CheckPublicKeyString(content string) (bool, error) { if strings.ContainsAny(content, "\n\r") { - return false, errors.New("Only a single line with a single key please") + return false, errors.New("only a single line with a single key please") } // write the key to a fileā¦ @@ -136,19 +136,19 @@ func CheckPublicKeyString(content string) (bool, error) { sshKeygenOutput := strings.Split(stdout, " ") if len(sshKeygenOutput) < 4 { - return false, errors.New("Not enough fields returned by ssh-keygen -l -f") + return false, fmt.Errorf("not enough fields returned by ssh-keygen -l -f: %v", sshKeygenOutput) } // Check if key type and key size match. - keySize, err := com.StrTo(sshKeygenOutput[0]).Int() - if err != nil { - return false, errors.New("Cannot get key size of the given key") + keySize := com.StrTo(sshKeygenOutput[0]).MustInt() + if keySize == 0 { + return false, errors.New("cannot get key size of the given key") } keyType := strings.TrimSpace(sshKeygenOutput[len(sshKeygenOutput)-1]) if minimumKeySize := MinimumKeySize[keyType]; minimumKeySize == 0 { - return false, errors.New("Sorry, unrecognized public key type") + return false, errors.New("sorry, unrecognized public key type") } else if keySize < minimumKeySize { - return false, fmt.Errorf("The minimum accepted size of a public key %s is %d", keyType, minimumKeySize) + return false, fmt.Errorf("the minimum accepted size of a public key %s is %d", keyType, minimumKeySize) } return true, nil @@ -204,7 +204,7 @@ func AddPublicKey(key *PublicKey) (err error) { if err != nil { return errors.New("ssh-keygen -l -f: " + stderr) } else if len(stdout) < 2 { - return errors.New("Not enough output for calculating fingerprint") + return errors.New("not enough output for calculating fingerprint: " + stdout) } key.Fingerprint = strings.Split(stdout, " ")[1] |