{"action":"created","comment":{"url":"https://api.github.com/repos/manastech/crystal/pulls/comments/42841986","id":42841986,"diff_hunk":"@@ -0,0 +1,88 @@\n+require \"../lib_crypto\"\n+require \"./digest_base\"\n+\n+module OpenSSL\n+  class Digest\n+    class DigestError < OpenSSL::Error; end\n+\n+    include DigestBase\n+\n+    getter name\n+\n+    def initialize(@name, @ctx : LibCrypto::EVP_MD_CTX)\n+      raise DigestError.new(\"Invalid EVP_MD_CTX\") unless @ctx\n+    end\n+\n+    protected def self.create_evp_mt_ctx(name)\n+      md = LibCrypto.evp_get_digestbyname(name)\n+      unless md\n+        oid = LibCrypto.obj_txt2obj(name, 0)\n+        md = LibCrypto.evp_get_digestbyname(LibCrypto.obj_nid2sn(LibCrypto.obj_obj2nid(oid)))\n+        LibCrypto.asn1_object_free(oid)\n+      end\n+      unless md\n+        raise \"Unsupported digest algoritm: #{name}\"\n+      end\n+      ctx = LibCrypto.evp_md_ctx_create\n+      unless ctx\n+        raise OpenSSL::Digest::DigestError.new \"Digest initialization failed.\"\n+      end\n+      if LibCrypto.evp_digestinit_ex(ctx, md, nil) != 1\n+        raise OpenSSL::Digest::DigestError.new \"Digest initialization failed.\"\n+      end\n+      ctx\n+    end\n+\n+    def self.new(name)\n+      new(name, create_evp_mt_ctx(name))\n+    end\n+\n+    def finalize\n+      LibCrypto.evp_md_ctx_destroy(self)\n+    end\n+\n+    def clone\n+      ctx = LibCrypto.evp_md_ctx_create\n+      if LibCrypto.evp_md_ctx_copy(ctx, @ctx) == 0\n+        LibCrypto.evp_md_ctx_destroy(ctx)\n+        raise DigestError.new(\"Unable to clone digest\")\n+      end\n+      Digest.new(@name, ctx)\n+    end\n+\n+    def reset\n+      if LibCrypto.evp_digestinit_ex(self, to_unsafe_md, nil) != 1\n+        raise DigestError.new \"Digest initialization failed.\"\n+      end\n+      self\n+    end\n+\n+    def update(data : String | Slice)\n+      LibCrypto.evp_digestupdate(self, data, data.size)\n+      self\n+    end\n+\n+    protected def finish\n+      size = digest_size\n+      data = Slice(UInt8).new(size)\n+      LibCrypto.evp_digestfinal_ex(@ctx, data, nil)\n+      data","path":"src/openssl/digest/digest.cr","position":69,"original_position":69,"commit_id":"13e34c0f246fd971d2025855fa5d69fc3d44e069","original_commit_id":"13e34c0f246fd971d2025855fa5d69fc3d44e069","user":{"login":"ysbaddaden","id":47380,"avatar_url":"https://avatars.githubusercontent.com/u/47380?v=3","gravatar_id":"","url":"https://api.github.com/users/ysbaddaden","html_url":"https://github.com/ysbaddaden","followers_url":"https://api.github.com/users/ysbaddaden/followers","following_url":"https://api.github.com/users/ysbaddaden/following{/other_user}","gists_url":"https://api.github.com/users/ysbaddaden/gists{/gist_id}","starred_url":"https://api.github.com/users/ysbaddaden/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ysbaddaden/subscriptions","organizations_url":"https://api.github.com/users/ysbaddaden/orgs","repos_url":"https://api.github.com/users/ysbaddaden/repos","events_url":"https://api.github.com/users/ysbaddaden/events{/privacy}","received_events_url":"https://api.github.com/users/ysbaddaden/received_events","type":"User","site_admin":false},"body":"This should be faster:\r\n\r\n```crystal\r\nptr = Pointer(UInt8).new(size)\r\nLibCrypto.evp_digestfinal_ex(@ctx, ptr, nil)\r\nptr.to_slice(size)\r\n```","created_at":"2015-10-23T08:13:14Z","updated_at":"2015-10-23T08:13:14Z","html_url":"https://github.com/manastech/crystal/pull/1806#discussion_r42841986","pull_request_url":"https://api.github.com/repos/manastech/crystal/pulls/1806","_links":{"self":{"href":"https://api.github.com/repos/manastech/crystal/pulls/comments/42841986"},"html":{"href":"https://github.com/manastech/crystal/pull/1806#discussion_r42841986"},"pull_request":{"href":"https://api.github.com/repos/manastech/crystal/pulls/1806"}}},"pull_request":{"url":"https://api.github.com/repos/manastech/crystal/pulls/1806","id":48464666,"html_url":"https://github.com/manastech/crystal/pull/1806","diff_url":"https://github.com/manastech/crystal/pull/1806.diff","patch_url":"https://github.com/manastech/crystal/pull/1806.patch","issue_url":"https://api.github.com/repos/manastech/crystal/issues/1806","number":1806,"state":"open","locked":false,"title":"added OpenSSL::Digest","user":{"login":"benoist","id":7202,"avatar_url":"https://avatars.githubusercontent.com/u/7202?v=3","gravatar_id":"","url":"https://api.github.com/users/benoist","html_url":"https://github.com/benoist","followers_url":"https://api.github.com/users/benoist/followers","following_url":"https://api.github.com/users/benoist/following{/other_user}","gists_url":"https://api.github.com/users/benoist/gists{/gist_id}","starred_url":"https://api.github.com/users/benoist/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benoist/subscriptions","organizations_url":"https://api.github.com/users/benoist/orgs","repos_url":"https://api.github.com/users/benoist/repos","events_url":"https://api.github.com/users/benoist/events{/privacy}","received_events_url":"https://api.github.com/users/benoist/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-10-22T14:30:45Z","updated_at":"2015-10-23T08:13:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6a16045734ebba57b69292279c44433e2e871e65","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/manastech/crystal/pulls/1806/commits","review_comments_url":"https://api.github.com/repos/manastech/crystal/pulls/1806/comments","review_comment_url":"https://api.github.com/repos/manastech/crystal/pulls/comments{/number}","comments_url":"https://api.github.com/repos/manastech/crystal/issues/1806/comments","statuses_url":"https://api.github.com/repos/manastech/crystal/statuses/13e34c0f246fd971d2025855fa5d69fc3d44e069","head":{"label":"benoist:feature/openssl-digest","ref":"feature/openssl-digest","sha":"13e34c0f246fd971d2025855fa5d69fc3d44e069","user":{"login":"benoist","id":7202,"avatar_url":"https://avatars.githubusercontent.com/u/7202?v=3","gravatar_id":"","url":"https://api.github.com/users/benoist","html_url":"https://github.com/benoist","followers_url":"https://api.github.com/users/benoist/followers","following_url":"https://api.github.com/users/benoist/following{/other_user}","gists_url":"https://api.github.com/users/benoist/gists{/gist_id}","starred_url":"https://api.github.com/users/benoist/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benoist/subscriptions","organizations_url":"https://api.github.com/users/benoist/orgs","repos_url":"https://api.github.com/users/benoist/repos","events_url":"https://api.github.com/users/benoist/events{/privacy}","received_events_url":"https://api.github.com/users/benoist/received_events","type":"User","site_admin":false},"repo":{"id":38000730,"name":"crystal","full_name":"benoist/crystal","owner":{"login":"benoist","id":7202,"avatar_url":"https://avatars.githubusercontent.com/u/7202?v=3","gravatar_id":"","url":"https://api.github.com/users/benoist","html_url":"https://github.com/benoist","followers_url":"https://api.github.com/users/benoist/followers","following_url":"https://api.github.com/users/benoist/following{/other_user}","gists_url":"https://api.github.com/users/benoist/gists{/gist_id}","starred_url":"https://api.github.com/users/benoist/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benoist/subscriptions","organizations_url":"https://api.github.com/users/benoist/orgs","repos_url":"https://api.github.com/users/benoist/repos","events_url":"https://api.github.com/users/benoist/events{/privacy}","received_events_url":"https://api.github.com/users/benoist/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/benoist/crystal","description":"The Crystal Programming Language","fork":true,"url":"https://api.github.com/repos/benoist/crystal","forks_url":"https://api.github.com/repos/benoist/crystal/forks","keys_url":"https://api.github.com/repos/benoist/crystal/keys{/key_id}","collaborators_url":"https://api.github.com/repos/benoist/crystal/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/benoist/crystal/teams","hooks_url":"https://api.github.com/repos/benoist/crystal/hooks","issue_events_url":"https://api.github.com/repos/benoist/crystal/issues/events{/number}","events_url":"https://api.github.com/repos/benoist/crystal/events","assignees_url":"https://api.github.com/repos/benoist/crystal/assignees{/user}","branches_url":"https://api.github.com/repos/benoist/crystal/branches{/branch}","tags_url":"https://api.github.com/repos/benoist/crystal/tags","blobs_url":"https://api.github.com/repos/benoist/crystal/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/benoist/crystal/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/benoist/crystal/git/refs{/sha}","trees_url":"https://api.github.com/repos/benoist/crystal/git/trees{/sha}","statuses_url":"https://api.github.com/repos/benoist/crystal/statuses/{sha}","languages_url":"https://api.github.com/repos/benoist/crystal/languages","stargazers_url":"https://api.github.com/repos/benoist/crystal/stargazers","contributors_url":"https://api.github.com/repos/benoist/crystal/contributors","subscribers_url":"https://api.github.com/repos/benoist/crystal/subscribers","subscription_url":"https://api.github.com/repos/benoist/crystal/subscription","commits_url":"https://api.github.com/repos/benoist/crystal/commits{/sha}","git_commits_url":"https://api.github.com/repos/benoist/crystal/git/commits{/sha}","comments_url":"https://api.github.com/repos/benoist/crystal/comments{/number}","issue_comment_url":"https://api.github.com/repos/benoist/crystal/issues/comments{/number}","contents_url":"https://api.github.com/repos/benoist/crystal/contents/{+path}","compare_url":"https://api.github.com/repos/benoist/crystal/compare/{base}...{head}","merges_url":"https://api.github.com/repos/benoist/crystal/merges","archive_url":"https://api.github.com/repos/benoist/crystal/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/benoist/crystal/downloads","issues_url":"https://api.github.com/repos/benoist/crystal/issues{/number}","pulls_url":"https://api.github.com/repos/benoist/crystal/pulls{/number}","milestones_url":"https://api.github.com/repos/benoist/crystal/milestones{/number}","notifications_url":"https://api.github.com/repos/benoist/crystal/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/benoist/crystal/labels{/name}","releases_url":"https://api.github.com/repos/benoist/crystal/releases{/id}","created_at":"2015-06-24T17:44:20Z","updated_at":"2015-06-24T17:44:21Z","pushed_at":"2015-10-22T14:29:37Z","git_url":"git://github.com/benoist/crystal.git","ssh_url":"git@github.com:benoist/crystal.git","clone_url":"https://github.com/benoist/crystal.git","svn_url":"https://github.com/benoist/crystal","homepage":"http://crystal-lang.org","size":30567,"stargazers_count":0,"watchers_count":0,"language":"Crystal","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"manastech:master","ref":"master","sha":"5a5db54ce1a003009ac3f95e8bc2f3bb55313653","user":{"login":"manastech","id":1354950,"avatar_url":"https://avatars.githubusercontent.com/u/1354950?v=3","gravatar_id":"","url":"https://api.github.com/users/manastech","html_url":"https://github.com/manastech","followers_url":"https://api.github.com/users/manastech/followers","following_url":"https://api.github.com/users/manastech/following{/other_user}","gists_url":"https://api.github.com/users/manastech/gists{/gist_id}","starred_url":"https://api.github.com/users/manastech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/manastech/subscriptions","organizations_url":"https://api.github.com/users/manastech/orgs","repos_url":"https://api.github.com/users/manastech/repos","events_url":"https://api.github.com/users/manastech/events{/privacy}","received_events_url":"https://api.github.com/users/manastech/received_events","type":"Organization","site_admin":false},"repo":{"id":6887813,"name":"crystal","full_name":"manastech/crystal","owner":{"login":"manastech","id":1354950,"avatar_url":"https://avatars.githubusercontent.com/u/1354950?v=3","gravatar_id":"","url":"https://api.github.com/users/manastech","html_url":"https://github.com/manastech","followers_url":"https://api.github.com/users/manastech/followers","following_url":"https://api.github.com/users/manastech/following{/other_user}","gists_url":"https://api.github.com/users/manastech/gists{/gist_id}","starred_url":"https://api.github.com/users/manastech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/manastech/subscriptions","organizations_url":"https://api.github.com/users/manastech/orgs","repos_url":"https://api.github.com/users/manastech/repos","events_url":"https://api.github.com/users/manastech/events{/privacy}","received_events_url":"https://api.github.com/users/manastech/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/manastech/crystal","description":"The Crystal Programming Language","fork":false,"url":"https://api.github.com/repos/manastech/crystal","forks_url":"https://api.github.com/repos/manastech/crystal/forks","keys_url":"https://api.github.com/repos/manastech/crystal/keys{/key_id}","collaborators_url":"https://api.github.com/repos/manastech/crystal/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/manastech/crystal/teams","hooks_url":"https://api.github.com/repos/manastech/crystal/hooks","issue_events_url":"https://api.github.com/repos/manastech/crystal/issues/events{/number}","events_url":"https://api.github.com/repos/manastech/crystal/events","assignees_url":"https://api.github.com/repos/manastech/crystal/assignees{/user}","branches_url":"https://api.github.com/repos/manastech/crystal/branches{/branch}","tags_url":"https://api.github.com/repos/manastech/crystal/tags","blobs_url":"https://api.github.com/repos/manastech/crystal/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/manastech/crystal/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/manastech/crystal/git/refs{/sha}","trees_url":"https://api.github.com/repos/manastech/crystal/git/trees{/sha}","statuses_url":"https://api.github.com/repos/manastech/crystal/statuses/{sha}","languages_url":"https://api.github.com/repos/manastech/crystal/languages","stargazers_url":"https://api.github.com/repos/manastech/crystal/stargazers","contributors_url":"https://api.github.com/repos/manastech/crystal/contributors","subscribers_url":"https://api.github.com/repos/manastech/crystal/subscribers","subscription_url":"https://api.github.com/repos/manastech/crystal/subscription","commits_url":"https://api.github.com/repos/manastech/crystal/commits{/sha}","git_commits_url":"https://api.github.com/repos/manastech/crystal/git/commits{/sha}","comments_url":"https://api.github.com/repos/manastech/crystal/comments{/number}","issue_comment_url":"https://api.github.com/repos/manastech/crystal/issues/comments{/number}","contents_url":"https://api.github.com/repos/manastech/crystal/contents/{+path}","compare_url":"https://api.github.com/repos/manastech/crystal/compare/{base}...{head}","merges_url":"https://api.github.com/repos/manastech/crystal/merges","archive_url":"https://api.github.com/repos/manastech/crystal/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/manastech/crystal/downloads","issues_url":"https://api.github.com/repos/manastech/crystal/issues{/number}","pulls_url":"https://api.github.com/repos/manastech/crystal/pulls{/number}","milestones_url":"https://api.github.com/repos/manastech/crystal/milestones{/number}","notifications_url":"https://api.github.com/repos/manastech/crystal/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/manastech/crystal/labels{/name}","releases_url":"https://api.github.com/repos/manastech/crystal/releases{/id}","created_at":"2012-11-27T17:32:32Z","updated_at":"2015-10-23T02:46:28Z","pushed_at":"2015-10-23T06:37:48Z","git_url":"git://github.com/manastech/crystal.git","ssh_url":"git@github.com:manastech/crystal.git","clone_url":"https://github.com/manastech/crystal.git","svn_url":"https://github.com/manastech/crystal","homepage":"http://crystal-lang.org","size":48422,"stargazers_count":3565,"watchers_count":3565,"language":"Crystal","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":274,"mirror_url":null,"open_issues_count":241,"forks":274,"open_issues":241,"watchers":3565,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/manastech/crystal/pulls/1806"},"html":{"href":"https://github.com/manastech/crystal/pull/1806"},"issue":{"href":"https://api.github.com/repos/manastech/crystal/issues/1806"},"comments":{"href":"https://api.github.com/repos/manastech/crystal/issues/1806/comments"},"review_comments":{"href":"https://api.github.com/repos/manastech/crystal/pulls/1806/comments"},"review_comment":{"href":"https://api.github.com/repos/manastech/crystal/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/manastech/crystal/pulls/1806/commits"},"statuses":{"href":"https://api.github.com/repos/manastech/crystal/statuses/13e34c0f246fd971d2025855fa5d69fc3d44e069"}}}}