PublicKey returns the Go's crypto.PublicKey of an ssh.PublicKey.
(key ssh.PublicKey)
| 46 | |
| 47 | // PublicKey returns the Go's crypto.PublicKey of an ssh.PublicKey. |
| 48 | func PublicKey(key ssh.PublicKey) (crypto.PublicKey, error) { |
| 49 | _, in, ok := parseString(key.Marshal()) |
| 50 | if !ok { |
| 51 | return nil, errors.New("public key is invalid") |
| 52 | } |
| 53 | |
| 54 | switch key.Type() { |
| 55 | case ssh.KeyAlgoRSA: |
| 56 | return parseRSA(in) |
| 57 | case ssh.KeyAlgoECDSA256, ssh.KeyAlgoECDSA384, ssh.KeyAlgoECDSA521, ssh.KeyAlgoSKECDSA256: |
| 58 | return parseECDSA(in) |
| 59 | case ssh.KeyAlgoED25519, ssh.KeyAlgoSKED25519: |
| 60 | return parseED25519(in) |
| 61 | case ssh.InsecureKeyAlgoDSA: //nolint:staticcheck // compatibility with older tooling |
| 62 | return parseDSA(in) |
| 63 | default: |
| 64 | return nil, errors.Errorf("public key %s is not supported", key.Type()) |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | func publicKeyTypeAndSize(key ssh.PublicKey) (string, int, error) { |
| 69 | var isCert bool |
nothing calls this directly
no test coverage detected
searching dependent graphs…