| 1 | package sshsig_testscip-go gomod github.com/42wim/sshsig . `github.com/42wim/sshsig_test`/ |
| 2 | |
| 3 | import ( |
| 4 | "bytesscip-go gomod github.com/golang/go/src go1.23.0 bytes/" |
| 5 | "fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/" |
| 6 | "netscip-go gomod github.com/golang/go/src go1.23.0 net/" |
| 7 | "osscip-go gomod github.com/golang/go/src go1.23.0 os/" |
| 8 | |
| 9 | "github.com/42wim/sshsigscip-go gomod github.com/42wim/sshsig . `github.com/42wim/sshsig`/" |
| 10 | "golang.org/x/crypto/ssh/agentscip-go gomod golang.org/x/crypto v0.37.0 `golang.org/x/crypto/ssh/agent`/" |
| 11 | ) |
| 12 | |
| 13 | func ExampleSignWithAgentscip-go gomod github.com/42wim/sshsig . `github.com/42wim/sshsig_test`/ExampleSignWithAgent().() { |
| 14 | // This example will panic when you don't have a ssh-agent running. |
| 15 | conn, err := netscip-go gomod github.com/golang/go/src go1.23.0 net/.Dialscip-go gomod github.com/golang/go/src go1.23.0 net/Dial().("unix", osscip-go gomod github.com/golang/go/src go1.23.0 os/.Getenvscip-go gomod github.com/golang/go/src go1.23.0 os/Getenv().("SSH_AUTH_SOCK")) |
| 16 | if err != nil { |
| 17 | panic(err) |
| 18 | } |
| 19 | |
| 20 | ag := agentscip-go gomod golang.org/x/crypto v0.37.0 `golang.org/x/crypto/ssh/agent`/.NewClientscip-go gomod golang.org/x/crypto v0.37.0 `golang.org/x/crypto/ssh/agent`/NewClient().(conn) |
| 21 | |
| 22 | // This public key must match in your agent (use `ssh-add -L` to get the public key) |
| 23 | pubkey := []byte(`ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAo3D7CGN01tTYY/dLKXEv8RxRyxa32c51X0uKMhnMab wim@localhost`) |
| 24 | // |
| 25 | data := []byte("hello world") |
| 26 | |
| 27 | res, err := sshsigscip-go gomod github.com/42wim/sshsig . `github.com/42wim/sshsig`/.SignWithAgentscip-go gomod github.com/42wim/sshsig . `github.com/42wim/sshsig`/SignWithAgent().(pubkey, ag, bytesscip-go gomod github.com/golang/go/src go1.23.0 bytes/.NewBufferscip-go gomod github.com/golang/go/src go1.23.0 bytes/NewBuffer().(data), "file") |
| 28 | if err != nil { |
| 29 | panic(err) |
| 30 | } |
| 31 | |
| 32 | fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Printlnscip-go gomod github.com/golang/go/src go1.23.0 fmt/Println().(string(res)) |
| 33 | } |
| 34 | |
| 35 | func ExampleSignscip-go gomod github.com/42wim/sshsig . `github.com/42wim/sshsig_test`/ExampleSign().() { |
| 36 | privkey := []byte(`-----BEGIN OPENSSH PRIVATE KEY----- |
| 37 | b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW |
| 38 | QyNTUxOQAAACCOjP6i4Pm/pYAAmpAMNZ6xrbHl9RW8xdul6kzIWuKMMAAAAIhoQm34aEJt |
| 39 | +AAAAAtzc2gtZWQyNTUxOQAAACCOjP6i4Pm/pYAAmpAMNZ6xrbHl9RW8xdul6kzIWuKMMA |
| 40 | AAAEBfIl93TLj6qHeg37GnPuZ00h8OVv1mzlhy0rhuO4Y0do6M/qLg+b+lgACakAw1nrGt |
| 41 | seX1FbzF26XqTMha4owwAAAAAAECAwQF |
| 42 | -----END OPENSSH PRIVATE KEY-----`) |
| 43 | |
| 44 | data := []byte("hello world") |
| 45 | |
| 46 | res, err := sshsigscip-go gomod github.com/42wim/sshsig . `github.com/42wim/sshsig`/.Signscip-go gomod github.com/42wim/sshsig . `github.com/42wim/sshsig`/Sign().(privkey, bytesscip-go gomod github.com/golang/go/src go1.23.0 bytes/.NewBufferscip-go gomod github.com/golang/go/src go1.23.0 bytes/NewBuffer().(data), "file") |
| 47 | if err != nil { |
| 48 | panic(err) |
| 49 | } |
| 50 | |
| 51 | fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Printlnscip-go gomod github.com/golang/go/src go1.23.0 fmt/Println().(string(res)) |
| 52 | |
| 53 | // Output: |
| 54 | // -----BEGIN SSH SIGNATURE----- |
| 55 | // U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgjoz+ouD5v6WAAJqQDDWesa2x5f |
| 56 | // UVvMXbpepMyFrijDAAAAAEZmlsZQAAAAAAAAAGc2hhNTEyAAAAUwAAAAtzc2gtZWQyNTUx |
| 57 | // OQAAAEBeu9Z+vLxBORysiqEbTzJP0EZKG0/aE5HpTtvimjQS6mHZCAGFg+kimNatBE0Y1j |
| 58 | // gS4pfD73TlML1SyB5lb/YO |
| 59 | // -----END SSH SIGNATURE----- |
| 60 | } |