update hash function

This commit is contained in:
Sajad Parra 2021-12-29 18:07:48 +05:30
parent 5115c8b58c
commit 8799379e50

View File

@ -169,7 +169,7 @@ func (c *Client) firstTimeInitializeClient() error {
} }
if _, ok := request.Event.InternalEvent["stop-at-first-match"]; ok { if _, ok := request.Event.InternalEvent["stop-at-first-match"]; ok {
gotItem := c.matchedTemplates.Get(hash(request.Event.InternalEvent["template-id"].(string) + request.Event.InternalEvent["host"].(string))) gotItem := c.matchedTemplates.Get(hash(request.Event.InternalEvent["template-id"].(string), request.Event.InternalEvent["host"].(string)))
if gotItem != nil { if gotItem != nil {
return return
} }
@ -205,7 +205,7 @@ func (c *Client) processInteractionForRequest(interaction *server.Interaction, d
if writer.WriteResult(data.Event, c.options.Output, c.options.Progress, c.options.IssuesClient) { if writer.WriteResult(data.Event, c.options.Output, c.options.Progress, c.options.IssuesClient) {
c.matched = true c.matched = true
if _, ok := data.Event.InternalEvent["stop-at-first-match"]; ok { if _, ok := data.Event.InternalEvent["stop-at-first-match"]; ok {
c.matchedTemplates.Set(hash(data.Event.InternalEvent["template-id"].(string)+data.Event.InternalEvent["host"].(string)), true, defaultInteractionDuration) c.matchedTemplates.Set(hash(data.Event.InternalEvent["template-id"].(string), data.Event.InternalEvent["host"].(string)), true, defaultInteractionDuration)
} }
} }
return true return true
@ -342,8 +342,9 @@ func debugPrintInteraction(interaction *server.Interaction) {
fmt.Fprint(os.Stderr, builder.String()) fmt.Fprint(os.Stderr, builder.String())
} }
func hash(s string) string { func hash(templateID, host string) string {
h := sha1.New() h := sha1.New()
h.Write([]byte(s)) h.Write([]byte(templateID))
h.Write([]byte(host))
return hex.EncodeToString(h.Sum(nil)) return hex.EncodeToString(h.Sum(nil))
} }