MCPcopy
hub / github.com/openpubkey/opkssh / Run

Method Run

commands/inspect.go:41–70  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

39}
40
41func (i *InspectCmd) Run() error {
42 // Check if the input is a file path
43 if _, err := os.Stat(i.KeyOrCert); err == nil {
44 // It's a file, read its contents
45 data, err := os.ReadFile(i.KeyOrCert)
46 if err != nil {
47 return fmt.Errorf("error reading input file: %v", err)
48 }
49 i.KeyOrCert = string(data)
50 }
51
52 // Trim whitespace and newlines
53 i.KeyOrCert = strings.TrimSpace(i.KeyOrCert)
54
55 // Parse the SSH key or certificate
56 pubKey, _, _, _, err := ssh.ParseAuthorizedKey([]byte(i.KeyOrCert))
57 if err != nil {
58 return fmt.Errorf("failed to parse SSH key: %v", err)
59 }
60
61 // Check if it's a certificate
62 if cert, ok := pubKey.(*ssh.Certificate); ok {
63 i.inspectCertificate(cert)
64 } else {
65 // It's a regular public key
66 i.inspectPublicKey(pubKey)
67 }
68
69 return nil
70}
71
72func (i *InspectCmd) inspectCertificate(cert *ssh.Certificate) {
73 i.printf("--- SSH Certificate Information ---\n")

Callers 4

runFunction · 0.95
TestInspectSSHCertFunction · 0.95
TestInspectKeyFunction · 0.95
loginMethod · 0.95

Calls 4

inspectCertificateMethod · 0.95
inspectPublicKeyMethod · 0.95
StatMethod · 0.65
ReadFileMethod · 0.65

Tested by 2

TestInspectSSHCertFunction · 0.76
TestInspectKeyFunction · 0.76