{"action":"created","comment":{"url":"https://api.github.com/repos/pyca/cryptography/pulls/comments/33417994","id":33417994,"diff_hunk":"@@ -4,10 +4,69 @@\n \n from __future__ import absolute_import, division, print_function\n \n+import os\n import threading\n \n from cryptography.hazmat.bindings._openssl import ffi, lib\n \n+_osrandom_engine_id = ffi.new(\"const char[]\", b\"osrandom\")\n+_osrandom_engine_name = ffi.new(\"const char[]\", b\"osrandom_engine\")\n+\n+@ffi.callback(\"int (*)(unsigned char *, int)\", error=0)\n+def osrandom_rand_bytes(buf, size):\n+    signed = ffi.cast(\"char*\", buf)\n+    result = os.urandom(size)\n+    signed[0:size] = result\n+    return 1\n+\n+\n+@ffi.callback(\"int (*)(unsigned char *, int)\", error=0)\n+def osrandom_pseudo_rand_bytes(buf, size):\n+    result = osrandom_rand_bytes(buf, size)\n+    if result == 0:\n+        return -1","path":"src/cryptography/hazmat/bindings/openssl/binding.py","position":25,"original_position":24,"commit_id":"eb8059d7bd4abc11a14bdf149812057d505a2685","original_commit_id":"c1d04467fdc58e4f97e7768f77706ac4c8099c42","user":{"login":"alex","id":772,"avatar_url":"https://avatars.githubusercontent.com/u/772?v=3","gravatar_id":"","url":"https://api.github.com/users/alex","html_url":"https://github.com/alex","followers_url":"https://api.github.com/users/alex/followers","following_url":"https://api.github.com/users/alex/following{/other_user}","gists_url":"https://api.github.com/users/alex/gists{/gist_id}","starred_url":"https://api.github.com/users/alex/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alex/subscriptions","organizations_url":"https://api.github.com/users/alex/orgs","repos_url":"https://api.github.com/users/alex/repos","events_url":"https://api.github.com/users/alex/events{/privacy}","received_events_url":"https://api.github.com/users/alex/received_events","type":"User","site_admin":false},"body":"Ugh, I'm reading the documentation for this API. It was clearly designed by somenoe who never actually thought very hard about it: https://www.openssl.org/docs/crypto/RAND_bytes.html .\r\n\r\nI think maybe we should jsut change them both to be the same, and have `error=-1`?","created_at":"2015-06-28T01:40:54Z","updated_at":"2015-06-28T01:40:54Z","html_url":"https://github.com/pyca/cryptography/pull/2073#discussion_r33417994","pull_request_url":"https://api.github.com/repos/pyca/cryptography/pulls/2073","_links":{"self":{"href":"https://api.github.com/repos/pyca/cryptography/pulls/comments/33417994"},"html":{"href":"https://github.com/pyca/cryptography/pull/2073#discussion_r33417994"},"pull_request":{"href":"https://api.github.com/repos/pyca/cryptography/pulls/2073"}}},"pull_request":{"url":"https://api.github.com/repos/pyca/cryptography/pulls/2073","id":38704180,"html_url":"https://github.com/pyca/cryptography/pull/2073","diff_url":"https://github.com/pyca/cryptography/pull/2073.diff","patch_url":"https://github.com/pyca/cryptography/pull/2073.patch","issue_url":"https://api.github.com/repos/pyca/cryptography/issues/2073","number":2073,"state":"open","locked":false,"title":"Replace C implementation of OS Random engine with Python one that just calls os.urandom","user":{"login":"glyph","id":716529,"avatar_url":"https://avatars.githubusercontent.com/u/716529?v=3","gravatar_id":"","url":"https://api.github.com/users/glyph","html_url":"https://github.com/glyph","followers_url":"https://api.github.com/users/glyph/followers","following_url":"https://api.github.com/users/glyph/following{/other_user}","gists_url":"https://api.github.com/users/glyph/gists{/gist_id}","starred_url":"https://api.github.com/users/glyph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/glyph/subscriptions","organizations_url":"https://api.github.com/users/glyph/orgs","repos_url":"https://api.github.com/users/glyph/repos","events_url":"https://api.github.com/users/glyph/events{/privacy}","received_events_url":"https://api.github.com/users/glyph/received_events","type":"User","site_admin":false},"body":"This is alternate fix for #2007 that moves file descriptor shenanigans (and C code) out of cryptography entirely.  It is intended to supersede #2035 .","created_at":"2015-06-27T05:11:03Z","updated_at":"2015-06-28T01:40:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6a5dd42a971ccfea7589dbcbeba2a50bbc96e746","assignee":null,"milestone":{"url":"https://api.github.com/repos/pyca/cryptography/milestones/11","html_url":"https://github.com/pyca/cryptography/milestones/Tenth%20Release","labels_url":"https://api.github.com/repos/pyca/cryptography/milestones/11/labels","id":1099545,"number":11,"title":"Tenth Release","description":"","creator":{"login":"reaperhulk","id":161495,"avatar_url":"https://avatars.githubusercontent.com/u/161495?v=3","gravatar_id":"","url":"https://api.github.com/users/reaperhulk","html_url":"https://github.com/reaperhulk","followers_url":"https://api.github.com/users/reaperhulk/followers","following_url":"https://api.github.com/users/reaperhulk/following{/other_user}","gists_url":"https://api.github.com/users/reaperhulk/gists{/gist_id}","starred_url":"https://api.github.com/users/reaperhulk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reaperhulk/subscriptions","organizations_url":"https://api.github.com/users/reaperhulk/orgs","repos_url":"https://api.github.com/users/reaperhulk/repos","events_url":"https://api.github.com/users/reaperhulk/events{/privacy}","received_events_url":"https://api.github.com/users/reaperhulk/received_events","type":"User","site_admin":false},"open_issues":10,"closed_issues":80,"state":"open","created_at":"2015-05-07T04:01:32Z","updated_at":"2015-06-27T22:09:38Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/pyca/cryptography/pulls/2073/commits","review_comments_url":"https://api.github.com/repos/pyca/cryptography/pulls/2073/comments","review_comment_url":"https://api.github.com/repos/pyca/cryptography/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pyca/cryptography/issues/2073/comments","statuses_url":"https://api.github.com/repos/pyca/cryptography/statuses/eb8059d7bd4abc11a14bdf149812057d505a2685","head":{"label":"glyph:no-c-random","ref":"no-c-random","sha":"eb8059d7bd4abc11a14bdf149812057d505a2685","user":{"login":"glyph","id":716529,"avatar_url":"https://avatars.githubusercontent.com/u/716529?v=3","gravatar_id":"","url":"https://api.github.com/users/glyph","html_url":"https://github.com/glyph","followers_url":"https://api.github.com/users/glyph/followers","following_url":"https://api.github.com/users/glyph/following{/other_user}","gists_url":"https://api.github.com/users/glyph/gists{/gist_id}","starred_url":"https://api.github.com/users/glyph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/glyph/subscriptions","organizations_url":"https://api.github.com/users/glyph/orgs","repos_url":"https://api.github.com/users/glyph/repos","events_url":"https://api.github.com/users/glyph/events{/privacy}","received_events_url":"https://api.github.com/users/glyph/received_events","type":"User","site_admin":false},"repo":{"id":15723154,"name":"cryptography","full_name":"glyph/cryptography","owner":{"login":"glyph","id":716529,"avatar_url":"https://avatars.githubusercontent.com/u/716529?v=3","gravatar_id":"","url":"https://api.github.com/users/glyph","html_url":"https://github.com/glyph","followers_url":"https://api.github.com/users/glyph/followers","following_url":"https://api.github.com/users/glyph/following{/other_user}","gists_url":"https://api.github.com/users/glyph/gists{/gist_id}","starred_url":"https://api.github.com/users/glyph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/glyph/subscriptions","organizations_url":"https://api.github.com/users/glyph/orgs","repos_url":"https://api.github.com/users/glyph/repos","events_url":"https://api.github.com/users/glyph/events{/privacy}","received_events_url":"https://api.github.com/users/glyph/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/glyph/cryptography","description":"cryptography is a package designed to expose cryptographic primitives and recipes to Python developers.","fork":true,"url":"https://api.github.com/repos/glyph/cryptography","forks_url":"https://api.github.com/repos/glyph/cryptography/forks","keys_url":"https://api.github.com/repos/glyph/cryptography/keys{/key_id}","collaborators_url":"https://api.github.com/repos/glyph/cryptography/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/glyph/cryptography/teams","hooks_url":"https://api.github.com/repos/glyph/cryptography/hooks","issue_events_url":"https://api.github.com/repos/glyph/cryptography/issues/events{/number}","events_url":"https://api.github.com/repos/glyph/cryptography/events","assignees_url":"https://api.github.com/repos/glyph/cryptography/assignees{/user}","branches_url":"https://api.github.com/repos/glyph/cryptography/branches{/branch}","tags_url":"https://api.github.com/repos/glyph/cryptography/tags","blobs_url":"https://api.github.com/repos/glyph/cryptography/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/glyph/cryptography/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/glyph/cryptography/git/refs{/sha}","trees_url":"https://api.github.com/repos/glyph/cryptography/git/trees{/sha}","statuses_url":"https://api.github.com/repos/glyph/cryptography/statuses/{sha}","languages_url":"https://api.github.com/repos/glyph/cryptography/languages","stargazers_url":"https://api.github.com/repos/glyph/cryptography/stargazers","contributors_url":"https://api.github.com/repos/glyph/cryptography/contributors","subscribers_url":"https://api.github.com/repos/glyph/cryptography/subscribers","subscription_url":"https://api.github.com/repos/glyph/cryptography/subscription","commits_url":"https://api.github.com/repos/glyph/cryptography/commits{/sha}","git_commits_url":"https://api.github.com/repos/glyph/cryptography/git/commits{/sha}","comments_url":"https://api.github.com/repos/glyph/cryptography/comments{/number}","issue_comment_url":"https://api.github.com/repos/glyph/cryptography/issues/comments{/number}","contents_url":"https://api.github.com/repos/glyph/cryptography/contents/{+path}","compare_url":"https://api.github.com/repos/glyph/cryptography/compare/{base}...{head}","merges_url":"https://api.github.com/repos/glyph/cryptography/merges","archive_url":"https://api.github.com/repos/glyph/cryptography/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/glyph/cryptography/downloads","issues_url":"https://api.github.com/repos/glyph/cryptography/issues{/number}","pulls_url":"https://api.github.com/repos/glyph/cryptography/pulls{/number}","milestones_url":"https://api.github.com/repos/glyph/cryptography/milestones{/number}","notifications_url":"https://api.github.com/repos/glyph/cryptography/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/glyph/cryptography/labels{/name}","releases_url":"https://api.github.com/repos/glyph/cryptography/releases{/id}","created_at":"2014-01-08T02:24:17Z","updated_at":"2014-01-09T17:29:36Z","pushed_at":"2015-06-28T01:38:14Z","git_url":"git://github.com/glyph/cryptography.git","ssh_url":"git@github.com:glyph/cryptography.git","clone_url":"https://github.com/glyph/cryptography.git","svn_url":"https://github.com/glyph/cryptography","homepage":"https://cryptography.io/","size":29947,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"pyca:master","ref":"master","sha":"7d85341b2143015756d44c278453c285e1518fbf","user":{"login":"pyca","id":5615737,"avatar_url":"https://avatars.githubusercontent.com/u/5615737?v=3","gravatar_id":"","url":"https://api.github.com/users/pyca","html_url":"https://github.com/pyca","followers_url":"https://api.github.com/users/pyca/followers","following_url":"https://api.github.com/users/pyca/following{/other_user}","gists_url":"https://api.github.com/users/pyca/gists{/gist_id}","starred_url":"https://api.github.com/users/pyca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pyca/subscriptions","organizations_url":"https://api.github.com/users/pyca/orgs","repos_url":"https://api.github.com/users/pyca/repos","events_url":"https://api.github.com/users/pyca/events{/privacy}","received_events_url":"https://api.github.com/users/pyca/received_events","type":"Organization","site_admin":false},"repo":{"id":11939484,"name":"cryptography","full_name":"pyca/cryptography","owner":{"login":"pyca","id":5615737,"avatar_url":"https://avatars.githubusercontent.com/u/5615737?v=3","gravatar_id":"","url":"https://api.github.com/users/pyca","html_url":"https://github.com/pyca","followers_url":"https://api.github.com/users/pyca/followers","following_url":"https://api.github.com/users/pyca/following{/other_user}","gists_url":"https://api.github.com/users/pyca/gists{/gist_id}","starred_url":"https://api.github.com/users/pyca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pyca/subscriptions","organizations_url":"https://api.github.com/users/pyca/orgs","repos_url":"https://api.github.com/users/pyca/repos","events_url":"https://api.github.com/users/pyca/events{/privacy}","received_events_url":"https://api.github.com/users/pyca/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pyca/cryptography","description":"cryptography is a package designed to expose cryptographic primitives and recipes to Python developers.","fork":false,"url":"https://api.github.com/repos/pyca/cryptography","forks_url":"https://api.github.com/repos/pyca/cryptography/forks","keys_url":"https://api.github.com/repos/pyca/cryptography/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pyca/cryptography/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pyca/cryptography/teams","hooks_url":"https://api.github.com/repos/pyca/cryptography/hooks","issue_events_url":"https://api.github.com/repos/pyca/cryptography/issues/events{/number}","events_url":"https://api.github.com/repos/pyca/cryptography/events","assignees_url":"https://api.github.com/repos/pyca/cryptography/assignees{/user}","branches_url":"https://api.github.com/repos/pyca/cryptography/branches{/branch}","tags_url":"https://api.github.com/repos/pyca/cryptography/tags","blobs_url":"https://api.github.com/repos/pyca/cryptography/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pyca/cryptography/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pyca/cryptography/git/refs{/sha}","trees_url":"https://api.github.com/repos/pyca/cryptography/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pyca/cryptography/statuses/{sha}","languages_url":"https://api.github.com/repos/pyca/cryptography/languages","stargazers_url":"https://api.github.com/repos/pyca/cryptography/stargazers","contributors_url":"https://api.github.com/repos/pyca/cryptography/contributors","subscribers_url":"https://api.github.com/repos/pyca/cryptography/subscribers","subscription_url":"https://api.github.com/repos/pyca/cryptography/subscription","commits_url":"https://api.github.com/repos/pyca/cryptography/commits{/sha}","git_commits_url":"https://api.github.com/repos/pyca/cryptography/git/commits{/sha}","comments_url":"https://api.github.com/repos/pyca/cryptography/comments{/number}","issue_comment_url":"https://api.github.com/repos/pyca/cryptography/issues/comments{/number}","contents_url":"https://api.github.com/repos/pyca/cryptography/contents/{+path}","compare_url":"https://api.github.com/repos/pyca/cryptography/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pyca/cryptography/merges","archive_url":"https://api.github.com/repos/pyca/cryptography/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pyca/cryptography/downloads","issues_url":"https://api.github.com/repos/pyca/cryptography/issues{/number}","pulls_url":"https://api.github.com/repos/pyca/cryptography/pulls{/number}","milestones_url":"https://api.github.com/repos/pyca/cryptography/milestones{/number}","notifications_url":"https://api.github.com/repos/pyca/cryptography/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pyca/cryptography/labels{/name}","releases_url":"https://api.github.com/repos/pyca/cryptography/releases{/id}","created_at":"2013-08-07T02:23:38Z","updated_at":"2015-06-27T00:48:15Z","pushed_at":"2015-06-28T01:38:15Z","git_url":"git://github.com/pyca/cryptography.git","ssh_url":"git@github.com:pyca/cryptography.git","clone_url":"https://github.com/pyca/cryptography.git","svn_url":"https://github.com/pyca/cryptography","homepage":"https://cryptography.io/","size":44186,"stargazers_count":717,"watchers_count":717,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":163,"mirror_url":null,"open_issues_count":86,"forks":163,"open_issues":86,"watchers":717,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pyca/cryptography/pulls/2073"},"html":{"href":"https://github.com/pyca/cryptography/pull/2073"},"issue":{"href":"https://api.github.com/repos/pyca/cryptography/issues/2073"},"comments":{"href":"https://api.github.com/repos/pyca/cryptography/issues/2073/comments"},"review_comments":{"href":"https://api.github.com/repos/pyca/cryptography/pulls/2073/comments"},"review_comment":{"href":"https://api.github.com/repos/pyca/cryptography/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pyca/cryptography/pulls/2073/commits"},"statuses":{"href":"https://api.github.com/repos/pyca/cryptography/statuses/eb8059d7bd4abc11a14bdf149812057d505a2685"}}}}