{"action":"created","comment":{"url":"https://api.github.com/repos/crystal-lang/crystal/pulls/comments/127583333","pull_request_review_id":50188452,"id":127583333,"diff_hunk":"@@ -0,0 +1,225 @@\n+require \"crystal/system/random\"\n+\n+# Hasher usable for `def hash(hasher)` should satisfy protocol:\n+# ```\n+# class MyHasher\n+#   # Value should implement commutative `+` for `Hash#hash(hasher)`\n+#   alias Value\n+#\n+#   # must be implemented to mix sizes of collections, and pointers (object_id)\n+#   def raw(v : Int::Primitive)\n+#     # mutate\n+#     nil\n+#   end\n+#\n+#   # must be implemented for Hash#hash\n+#   def raw(v : Value)\n+#     # mutate\n+#     nil\n+#   end\n+#\n+#   def <<(b : Bytes)\n+#     # mutate\n+#     nil\n+#   end\n+#\n+#   def <<(n : Nil)\n+#     # mutate\n+#     nil\n+#   end\n+#\n+#   def <<(v)\n+#     # v.hash will return hasher\n+#     # if hasher is a struct, then it will be copy\n+#     copy_from v.hash(self)\n+#     nil\n+#   end\n+#\n+#   # digest returns hashsum for current state without state mutation\n+#   def digest : Value\n+#   end\n+#\n+#   # should be implemented for `Hash#hash(hasher)`\n+#   def clone\n+#     copy_of_current_state\n+#   end\n+# end\n+# ```\n+\n+class Hash\n+  # Hasher used as standard hasher in `Object#hash`\n+  # It have to provide defense against HashDos, and to be reasonably fast.\n+  #\n+  # To protect against HashDos, it is seeded with secure random, and have\n+  # permutation that hard to forge without knowing seed and seeing hash digest.\n+  struct Hasher","path":"src/hash/hasher.cr","position":55,"original_position":55,"commit_id":"239cd59d658a6ba784422eaeaa7f6384c5fdb4f0","original_commit_id":"ae110ce1fc63d31c41dbd2b69f9edf5b4002afcc","user":{"login":"RX14","id":2788811,"avatar_url":"https://avatars4.githubusercontent.com/u/2788811?v=4","gravatar_id":"","url":"https://api.github.com/users/RX14","html_url":"https://github.com/RX14","followers_url":"https://api.github.com/users/RX14/followers","following_url":"https://api.github.com/users/RX14/following{/other_user}","gists_url":"https://api.github.com/users/RX14/gists{/gist_id}","starred_url":"https://api.github.com/users/RX14/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RX14/subscriptions","organizations_url":"https://api.github.com/users/RX14/orgs","repos_url":"https://api.github.com/users/RX14/repos","events_url":"https://api.github.com/users/RX14/events{/privacy}","received_events_url":"https://api.github.com/users/RX14/received_events","type":"User","site_admin":false},"body":"Well there's probably a llvm rot intrinsic you could bind. ","created_at":"2017-07-15T12:40:49Z","updated_at":"2017-07-15T12:40:50Z","html_url":"https://github.com/crystal-lang/crystal/pull/4675#discussion_r127583333","pull_request_url":"https://api.github.com/repos/crystal-lang/crystal/pulls/4675","_links":{"self":{"href":"https://api.github.com/repos/crystal-lang/crystal/pulls/comments/127583333"},"html":{"href":"https://github.com/crystal-lang/crystal/pull/4675#discussion_r127583333"},"pull_request":{"href":"https://api.github.com/repos/crystal-lang/crystal/pulls/4675"}}},"pull_request":{"url":"https://api.github.com/repos/crystal-lang/crystal/pulls/4675","id":128904919,"html_url":"https://github.com/crystal-lang/crystal/pull/4675","diff_url":"https://github.com/crystal-lang/crystal/pull/4675.diff","patch_url":"https://github.com/crystal-lang/crystal/pull/4675.patch","issue_url":"https://api.github.com/repos/crystal-lang/crystal/issues/4675","number":4675,"state":"open","locked":false,"title":"change computation of hash value.","user":{"login":"funny-falcon","id":249427,"avatar_url":"https://avatars5.githubusercontent.com/u/249427?v=4","gravatar_id":"","url":"https://api.github.com/users/funny-falcon","html_url":"https://github.com/funny-falcon","followers_url":"https://api.github.com/users/funny-falcon/followers","following_url":"https://api.github.com/users/funny-falcon/following{/other_user}","gists_url":"https://api.github.com/users/funny-falcon/gists{/gist_id}","starred_url":"https://api.github.com/users/funny-falcon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/funny-falcon/subscriptions","organizations_url":"https://api.github.com/users/funny-falcon/orgs","repos_url":"https://api.github.com/users/funny-falcon/repos","events_url":"https://api.github.com/users/funny-falcon/events{/privacy}","received_events_url":"https://api.github.com/users/funny-falcon/received_events","type":"User","site_admin":false},"body":"To protect against Hash DoS, change the way hash value is computed.\r\nClass|Struct should define method `def hash(hasher)` and call\r\n`hasher << @ivar` inside.\r\n\r\nAs an option, for speed, and for backward compatibility, `def hash`\r\nstill could be implemented. It will be used for Hash of matched type.\r\n`Thread#hash` and `Signal#hash` is implemented as unseeded cause they are\r\n used before `StdHasher @@seed` is initialized.\r\n\r\nBut it is better to implement `def hash(hasher)`.\r\n\r\nStdHasher is default hasher that uses `hash(hasher)` and it is used as default\r\nseeded hasher. It also implements `unseeded` for `Enums`.\r\n\r\nAlso, number normalization for hashing introduced, ie rule 'equality\r\nforces hash equality' is forced (`a == b` => `a.hash == b.hash`).\r\nNormalization idea is borrowed from Python implementation.\r\n(idea by Akzhan Abdulin @akzhan)\r\n\r\nFixes #4578\r\nPrerequisite for #4557\r\nReplaces #4581","created_at":"2017-07-05T08:12:58Z","updated_at":"2017-07-15T12:40:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"132068c97d2e52e57cb9422232521e9ff8d8e1d1","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/crystal-lang/crystal/pulls/4675/commits","review_comments_url":"https://api.github.com/repos/crystal-lang/crystal/pulls/4675/comments","review_comment_url":"https://api.github.com/repos/crystal-lang/crystal/pulls/comments{/number}","comments_url":"https://api.github.com/repos/crystal-lang/crystal/issues/4675/comments","statuses_url":"https://api.github.com/repos/crystal-lang/crystal/statuses/239cd59d658a6ba784422eaeaa7f6384c5fdb4f0","head":{"label":"funny-falcon:hasher1","ref":"hasher1","sha":"239cd59d658a6ba784422eaeaa7f6384c5fdb4f0","user":{"login":"funny-falcon","id":249427,"avatar_url":"https://avatars5.githubusercontent.com/u/249427?v=4","gravatar_id":"","url":"https://api.github.com/users/funny-falcon","html_url":"https://github.com/funny-falcon","followers_url":"https://api.github.com/users/funny-falcon/followers","following_url":"https://api.github.com/users/funny-falcon/following{/other_user}","gists_url":"https://api.github.com/users/funny-falcon/gists{/gist_id}","starred_url":"https://api.github.com/users/funny-falcon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/funny-falcon/subscriptions","organizations_url":"https://api.github.com/users/funny-falcon/orgs","repos_url":"https://api.github.com/users/funny-falcon/repos","events_url":"https://api.github.com/users/funny-falcon/events{/privacy}","received_events_url":"https://api.github.com/users/funny-falcon/received_events","type":"User","site_admin":false},"repo":{"id":95386987,"name":"crystal","full_name":"funny-falcon/crystal","owner":{"login":"funny-falcon","id":249427,"avatar_url":"https://avatars5.githubusercontent.com/u/249427?v=4","gravatar_id":"","url":"https://api.github.com/users/funny-falcon","html_url":"https://github.com/funny-falcon","followers_url":"https://api.github.com/users/funny-falcon/followers","following_url":"https://api.github.com/users/funny-falcon/following{/other_user}","gists_url":"https://api.github.com/users/funny-falcon/gists{/gist_id}","starred_url":"https://api.github.com/users/funny-falcon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/funny-falcon/subscriptions","organizations_url":"https://api.github.com/users/funny-falcon/orgs","repos_url":"https://api.github.com/users/funny-falcon/repos","events_url":"https://api.github.com/users/funny-falcon/events{/privacy}","received_events_url":"https://api.github.com/users/funny-falcon/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/funny-falcon/crystal","description":"The Crystal Programming Language","fork":true,"url":"https://api.github.com/repos/funny-falcon/crystal","forks_url":"https://api.github.com/repos/funny-falcon/crystal/forks","keys_url":"https://api.github.com/repos/funny-falcon/crystal/keys{/key_id}","collaborators_url":"https://api.github.com/repos/funny-falcon/crystal/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/funny-falcon/crystal/teams","hooks_url":"https://api.github.com/repos/funny-falcon/crystal/hooks","issue_events_url":"https://api.github.com/repos/funny-falcon/crystal/issues/events{/number}","events_url":"https://api.github.com/repos/funny-falcon/crystal/events","assignees_url":"https://api.github.com/repos/funny-falcon/crystal/assignees{/user}","branches_url":"https://api.github.com/repos/funny-falcon/crystal/branches{/branch}","tags_url":"https://api.github.com/repos/funny-falcon/crystal/tags","blobs_url":"https://api.github.com/repos/funny-falcon/crystal/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/funny-falcon/crystal/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/funny-falcon/crystal/git/refs{/sha}","trees_url":"https://api.github.com/repos/funny-falcon/crystal/git/trees{/sha}","statuses_url":"https://api.github.com/repos/funny-falcon/crystal/statuses/{sha}","languages_url":"https://api.github.com/repos/funny-falcon/crystal/languages","stargazers_url":"https://api.github.com/repos/funny-falcon/crystal/stargazers","contributors_url":"https://api.github.com/repos/funny-falcon/crystal/contributors","subscribers_url":"https://api.github.com/repos/funny-falcon/crystal/subscribers","subscription_url":"https://api.github.com/repos/funny-falcon/crystal/subscription","commits_url":"https://api.github.com/repos/funny-falcon/crystal/commits{/sha}","git_commits_url":"https://api.github.com/repos/funny-falcon/crystal/git/commits{/sha}","comments_url":"https://api.github.com/repos/funny-falcon/crystal/comments{/number}","issue_comment_url":"https://api.github.com/repos/funny-falcon/crystal/issues/comments{/number}","contents_url":"https://api.github.com/repos/funny-falcon/crystal/contents/{+path}","compare_url":"https://api.github.com/repos/funny-falcon/crystal/compare/{base}...{head}","merges_url":"https://api.github.com/repos/funny-falcon/crystal/merges","archive_url":"https://api.github.com/repos/funny-falcon/crystal/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/funny-falcon/crystal/downloads","issues_url":"https://api.github.com/repos/funny-falcon/crystal/issues{/number}","pulls_url":"https://api.github.com/repos/funny-falcon/crystal/pulls{/number}","milestones_url":"https://api.github.com/repos/funny-falcon/crystal/milestones{/number}","notifications_url":"https://api.github.com/repos/funny-falcon/crystal/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/funny-falcon/crystal/labels{/name}","releases_url":"https://api.github.com/repos/funny-falcon/crystal/releases{/id}","deployments_url":"https://api.github.com/repos/funny-falcon/crystal/deployments","created_at":"2017-06-25T21:33:47Z","updated_at":"2017-06-25T21:33:52Z","pushed_at":"2017-07-15T12:36:18Z","git_url":"git://github.com/funny-falcon/crystal.git","ssh_url":"git@github.com:funny-falcon/crystal.git","clone_url":"https://github.com/funny-falcon/crystal.git","svn_url":"https://github.com/funny-falcon/crystal","homepage":"https://crystal-lang.org","size":33853,"stargazers_count":0,"watchers_count":0,"language":"Crystal","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"crystal-lang:master","ref":"master","sha":"d24f79ca0fac5b79eaf2b79e15ada088e0eaa661","user":{"login":"crystal-lang","id":6539796,"avatar_url":"https://avatars4.githubusercontent.com/u/6539796?v=4","gravatar_id":"","url":"https://api.github.com/users/crystal-lang","html_url":"https://github.com/crystal-lang","followers_url":"https://api.github.com/users/crystal-lang/followers","following_url":"https://api.github.com/users/crystal-lang/following{/other_user}","gists_url":"https://api.github.com/users/crystal-lang/gists{/gist_id}","starred_url":"https://api.github.com/users/crystal-lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crystal-lang/subscriptions","organizations_url":"https://api.github.com/users/crystal-lang/orgs","repos_url":"https://api.github.com/users/crystal-lang/repos","events_url":"https://api.github.com/users/crystal-lang/events{/privacy}","received_events_url":"https://api.github.com/users/crystal-lang/received_events","type":"Organization","site_admin":false},"repo":{"id":6887813,"name":"crystal","full_name":"crystal-lang/crystal","owner":{"login":"crystal-lang","id":6539796,"avatar_url":"https://avatars4.githubusercontent.com/u/6539796?v=4","gravatar_id":"","url":"https://api.github.com/users/crystal-lang","html_url":"https://github.com/crystal-lang","followers_url":"https://api.github.com/users/crystal-lang/followers","following_url":"https://api.github.com/users/crystal-lang/following{/other_user}","gists_url":"https://api.github.com/users/crystal-lang/gists{/gist_id}","starred_url":"https://api.github.com/users/crystal-lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crystal-lang/subscriptions","organizations_url":"https://api.github.com/users/crystal-lang/orgs","repos_url":"https://api.github.com/users/crystal-lang/repos","events_url":"https://api.github.com/users/crystal-lang/events{/privacy}","received_events_url":"https://api.github.com/users/crystal-lang/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/crystal-lang/crystal","description":"The Crystal Programming Language","fork":false,"url":"https://api.github.com/repos/crystal-lang/crystal","forks_url":"https://api.github.com/repos/crystal-lang/crystal/forks","keys_url":"https://api.github.com/repos/crystal-lang/crystal/keys{/key_id}","collaborators_url":"https://api.github.com/repos/crystal-lang/crystal/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/crystal-lang/crystal/teams","hooks_url":"https://api.github.com/repos/crystal-lang/crystal/hooks","issue_events_url":"https://api.github.com/repos/crystal-lang/crystal/issues/events{/number}","events_url":"https://api.github.com/repos/crystal-lang/crystal/events","assignees_url":"https://api.github.com/repos/crystal-lang/crystal/assignees{/user}","branches_url":"https://api.github.com/repos/crystal-lang/crystal/branches{/branch}","tags_url":"https://api.github.com/repos/crystal-lang/crystal/tags","blobs_url":"https://api.github.com/repos/crystal-lang/crystal/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/crystal-lang/crystal/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/crystal-lang/crystal/git/refs{/sha}","trees_url":"https://api.github.com/repos/crystal-lang/crystal/git/trees{/sha}","statuses_url":"https://api.github.com/repos/crystal-lang/crystal/statuses/{sha}","languages_url":"https://api.github.com/repos/crystal-lang/crystal/languages","stargazers_url":"https://api.github.com/repos/crystal-lang/crystal/stargazers","contributors_url":"https://api.github.com/repos/crystal-lang/crystal/contributors","subscribers_url":"https://api.github.com/repos/crystal-lang/crystal/subscribers","subscription_url":"https://api.github.com/repos/crystal-lang/crystal/subscription","commits_url":"https://api.github.com/repos/crystal-lang/crystal/commits{/sha}","git_commits_url":"https://api.github.com/repos/crystal-lang/crystal/git/commits{/sha}","comments_url":"https://api.github.com/repos/crystal-lang/crystal/comments{/number}","issue_comment_url":"https://api.github.com/repos/crystal-lang/crystal/issues/comments{/number}","contents_url":"https://api.github.com/repos/crystal-lang/crystal/contents/{+path}","compare_url":"https://api.github.com/repos/crystal-lang/crystal/compare/{base}...{head}","merges_url":"https://api.github.com/repos/crystal-lang/crystal/merges","archive_url":"https://api.github.com/repos/crystal-lang/crystal/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/crystal-lang/crystal/downloads","issues_url":"https://api.github.com/repos/crystal-lang/crystal/issues{/number}","pulls_url":"https://api.github.com/repos/crystal-lang/crystal/pulls{/number}","milestones_url":"https://api.github.com/repos/crystal-lang/crystal/milestones{/number}","notifications_url":"https://api.github.com/repos/crystal-lang/crystal/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/crystal-lang/crystal/labels{/name}","releases_url":"https://api.github.com/repos/crystal-lang/crystal/releases{/id}","deployments_url":"https://api.github.com/repos/crystal-lang/crystal/deployments","created_at":"2012-11-27T17:32:32Z","updated_at":"2017-07-15T10:38:13Z","pushed_at":"2017-07-15T12:36:20Z","git_url":"git://github.com/crystal-lang/crystal.git","ssh_url":"git@github.com:crystal-lang/crystal.git","clone_url":"https://github.com/crystal-lang/crystal.git","svn_url":"https://github.com/crystal-lang/crystal","homepage":"https://crystal-lang.org","size":33831,"stargazers_count":8561,"watchers_count":8561,"language":"Crystal","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":682,"mirror_url":null,"open_issues_count":547,"forks":682,"open_issues":547,"watchers":8561,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/crystal-lang/crystal/pulls/4675"},"html":{"href":"https://github.com/crystal-lang/crystal/pull/4675"},"issue":{"href":"https://api.github.com/repos/crystal-lang/crystal/issues/4675"},"comments":{"href":"https://api.github.com/repos/crystal-lang/crystal/issues/4675/comments"},"review_comments":{"href":"https://api.github.com/repos/crystal-lang/crystal/pulls/4675/comments"},"review_comment":{"href":"https://api.github.com/repos/crystal-lang/crystal/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/crystal-lang/crystal/pulls/4675/commits"},"statuses":{"href":"https://api.github.com/repos/crystal-lang/crystal/statuses/239cd59d658a6ba784422eaeaa7f6384c5fdb4f0"}}}}
{"actor":{"display_login":"RX14"}}