Browse Source

variable should not use ALL_CAPS

for-closed-social
Gibheer 8 years ago
parent
commit
2f27ee2232
2 changed files with 7 additions and 7 deletions
  1. +4
    -4
      models/ssh_key.go
  2. +3
    -3
      models/ssh_key_test.go

+ 4
- 4
models/ssh_key.go View File

@ -36,8 +36,8 @@ const (
) )
var ( var (
sshOpLocker = sync.Mutex{}
SSH_UNKNOWN_KEY_TYPE = fmt.Errorf("unknown key type")
sshOpLocker = sync.Mutex{}
SSHUnknownKeyType = fmt.Errorf("unknown key type")
) )
type KeyType int type KeyType int
@ -186,7 +186,7 @@ func SSHKeyGenParsePublicKey(key string) (string, int, error) {
return "", 0, fmt.Errorf("public key check failed with error '%s': %s", err, stderr) return "", 0, fmt.Errorf("public key check failed with error '%s': %s", err, stderr)
} }
if strings.HasSuffix(stdout, "is not a public key file.") { if strings.HasSuffix(stdout, "is not a public key file.") {
return "", 0, SSH_UNKNOWN_KEY_TYPE
return "", 0, SSHUnknownKeyType
} }
fields := strings.Split(stdout, " ") fields := strings.Split(stdout, " ")
if len(fields) < 4 { if len(fields) < 4 {
@ -216,7 +216,7 @@ func SSHNativeParsePublicKey(keyLine string) (string, int, error) {
pkey, err := ssh.ParsePublicKey(raw) pkey, err := ssh.ParsePublicKey(raw)
if err != nil { if err != nil {
if strings.HasPrefix(err.Error(), "ssh: unknown key algorithm") { if strings.HasPrefix(err.Error(), "ssh: unknown key algorithm") {
return "", 0, SSH_UNKNOWN_KEY_TYPE
return "", 0, SSHUnknownKeyType
} }
return "", 0, err return "", 0, err
} }

+ 3
- 3
models/ssh_key_test.go View File

@ -21,7 +21,7 @@ func TestSSHKeyVerification(t *testing.T) {
for name, pubkey := range keys { for name, pubkey := range keys {
keyTypeN, lengthN, errN := SSHNativeParsePublicKey(pubkey) keyTypeN, lengthN, errN := SSHNativeParsePublicKey(pubkey)
if errN != nil { if errN != nil {
if errN != SSH_UNKNOWN_KEY_TYPE {
if errN != SSHUnknownKeyType {
t.Errorf("error parsing public key '%s': %s", name, errN) t.Errorf("error parsing public key '%s': %s", name, errN)
continue continue
} }
@ -31,8 +31,8 @@ func TestSSHKeyVerification(t *testing.T) {
t.Errorf("error parsing public key '%s': %s", name, errK) t.Errorf("error parsing public key '%s': %s", name, errK)
continue continue
} }
// we know that ed25519 is currently not supported by native and returns SSH_UNKNOWN_KEY_TYPE
if (keyTypeN != keyTypeK || lengthN != lengthK) && errN != SSH_UNKNOWN_KEY_TYPE {
// we know that ed25519 is currently not supported by native and returns SSHUnknownKeyType
if (keyTypeN != keyTypeK || lengthN != lengthK) && errN != SSHUnknownKeyType {
t.Errorf("key mismatch for '%s': native: %s(%d), ssh-keygen: %s(%d)", name, keyTypeN, lengthN, keyTypeK, lengthK) t.Errorf("key mismatch for '%s': native: %s(%d), ssh-keygen: %s(%d)", name, keyTypeN, lengthN, keyTypeK, lengthK)
} }
} }

Loading…
Cancel
Save