| 1 | package controlscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/ |
| 2 | |
| 3 | import ( |
| 4 | "stringsscip-go gomod github.com/golang/go/src go1.15 strings/" |
| 5 | |
| 6 | "github.com/cretz/bine/torutilscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil`/" |
| 7 | ) |
| 8 | |
| 9 | // ProtocolInfo is the protocol info result of Conn.ProtocolInfo. |
| 10 | type ProtocolInfoscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/ProtocolInfo# struct { |
| 11 | AuthMethodsscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/ProtocolInfo#AuthMethods. []string |
| 12 | CookieFilescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/ProtocolInfo#CookieFile. string |
| 13 | TorVersionscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/ProtocolInfo#TorVersion. string |
| 14 | RawResponsescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/ProtocolInfo#RawResponse. *Responsescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/Response# |
| 15 | } |
| 16 | |
| 17 | // HasAuthMethod checks if ProtocolInfo contains the requested auth method. |
| 18 | func (p *ProtocolInfoscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/ProtocolInfo#) HasAuthMethodscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/ProtocolInfo#HasAuthMethod().(authMethod string) bool { |
| 19 | for _, m := range p.AuthMethodsscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/ProtocolInfo#AuthMethods. { |
| 20 | if m == authMethod { |
| 21 | return true |
| 22 | } |
| 23 | } |
| 24 | return false |
| 25 | } |
| 26 | |
| 27 | // ProtocolInfo invokes PROTOCOLINFO on first invocation and returns a cached |
| 28 | // result on all others. |
| 29 | func (c *Connscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/Conn#) ProtocolInfoscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/Conn#ProtocolInfo().() (*ProtocolInfoscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/ProtocolInfo#, error) { |
| 30 | var err error |
| 31 | if c.protocolInfoscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/Conn#protocolInfo. == nil { |
| 32 | c.protocolInfoscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/Conn#protocolInfo., err = c.sendProtocolInfoscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/Conn#sendProtocolInfo().() |
| 33 | } |
| 34 | return c.protocolInfoscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/Conn#protocolInfo., err |
| 35 | } |
| 36 | |
| 37 | func (c *Connscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/Conn#) sendProtocolInfoscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/Conn#sendProtocolInfo().() (*ProtocolInfoscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/ProtocolInfo#, error) { |
| 38 | resp, err := c.SendRequestscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/Conn#SendRequest().("PROTOCOLINFO") |
| 39 | if err != nil { |
| 40 | return nil, err |
| 41 | } |
| 42 | // Check data vals |
| 43 | ret := &ProtocolInfoscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/ProtocolInfo#{RawResponsescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/ProtocolInfo#RawResponse.: resp} |
| 44 | for _, piece := range resp.Datascip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/Response#Data. { |
| 45 | key, val, ok := torutilscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil`/.PartitionStringscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil`/PartitionString().(piece, ' ') |
| 46 | if !ok { |
| 47 | continue |
| 48 | } |
| 49 | switch key { |
| 50 | case "PROTOCOLINFO": |
| 51 | if val != "1" { |
| 52 | return nil, c.protoErrscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/Conn#protoErr().("Invalid PIVERSION: %v", val) |
| 53 | } |
| 54 | case "AUTH": |
| 55 | methods, cookieFile, _ := torutilscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil`/.PartitionStringscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil`/PartitionString().(val, ' ') |
| 56 | if !stringsscip-go gomod github.com/golang/go/src go1.15 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.15 strings/HasPrefix().(methods, "METHODS=") { |
| 57 | continue |
| 58 | } |
| 59 | if cookieFile != "" { |
| 60 | if !stringsscip-go gomod github.com/golang/go/src go1.15 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.15 strings/HasPrefix().(cookieFile, "COOKIEFILE=") { |
| 61 | continue |
| 62 | } |
| 63 | if ret.CookieFilescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/ProtocolInfo#CookieFile., err = torutilscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil`/.UnescapeSimpleQuotedStringscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil`/UnescapeSimpleQuotedString().(cookieFile[11:]); err != nil { |
| 64 | continue |
| 65 | } |
| 66 | } |
| 67 | ret.AuthMethodsscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/ProtocolInfo#AuthMethods. = stringsscip-go gomod github.com/golang/go/src go1.15 strings/.Splitscip-go gomod github.com/golang/go/src go1.15 strings/Split().(methods[8:], ",") |
| 68 | case "VERSION": |
| 69 | torVersion, _, _ := torutilscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil`/.PartitionStringscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil`/PartitionString().(val, ' ') |
| 70 | if stringsscip-go gomod github.com/golang/go/src go1.15 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.15 strings/HasPrefix().(torVersion, "Tor=") { |
| 71 | ret.TorVersionscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/control`/ProtocolInfo#TorVersion., err = torutilscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil`/.UnescapeSimpleQuotedStringscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil`/UnescapeSimpleQuotedString().(torVersion[4:]) |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | return ret, nil |
| 76 | } |