packer-cn/helper/communicator/sshkey/algorithm_enumer.go
Adrien Delorme b24911661f
add sshkey package and ssh-keygen comand (#10101)
* add sshkey.Generate function that returns an sshkey.Pair to be used with openssh.
* add cmd/ssh-keygen/main.go for testing purposes
* add a test calling ssh.ParsePrivateKey & ssh.ParseAuthorizedKey (which is very
   similar to what openssh would do to read a keypair)

The wrapping of the keys should be handled by crypto/x509.MarshalPKCS8PrivateKey 
& x/crypto/ssh.NewPublicKey which does not work for ed25519 and dsa. 
x509.MarshalPKCS8PrivateKey marshals ed25519 keys but the keys did not work with openssh. 
x509.MarshalPKCS8PrivateKey does not handle dsa keys.
So I had to 'wrap' those manually by reading the code of the openssh package.
Note that ssh.NewPublicKey works with any keytype. I should probably do a PR to ssh to have a NewPrivateKey & Marshalling funcs
2020-10-19 10:24:34 +02:00

53 lines
1.3 KiB
Go

// Code generated by "enumer -type Algorithm -transform snake"; DO NOT EDIT.
//
package sshkey
import (
"fmt"
)
const _AlgorithmName = "rsadsaecdsaed25519"
var _AlgorithmIndex = [...]uint8{0, 3, 6, 11, 18}
func (i Algorithm) String() string {
if i < 0 || i >= Algorithm(len(_AlgorithmIndex)-1) {
return fmt.Sprintf("Algorithm(%d)", i)
}
return _AlgorithmName[_AlgorithmIndex[i]:_AlgorithmIndex[i+1]]
}
var _AlgorithmValues = []Algorithm{0, 1, 2, 3}
var _AlgorithmNameToValueMap = map[string]Algorithm{
_AlgorithmName[0:3]: 0,
_AlgorithmName[3:6]: 1,
_AlgorithmName[6:11]: 2,
_AlgorithmName[11:18]: 3,
}
// AlgorithmString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func AlgorithmString(s string) (Algorithm, error) {
if val, ok := _AlgorithmNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to Algorithm values", s)
}
// AlgorithmValues returns all values of the enum
func AlgorithmValues() []Algorithm {
return _AlgorithmValues
}
// IsAAlgorithm returns "true" if the value is listed in the enum definition. "false" otherwise
func (i Algorithm) IsAAlgorithm() bool {
for _, v := range _AlgorithmValues {
if i == v {
return true
}
}
return false
}