{"action":"created","comment":{"url":"https://api.github.com/repos/pyca/cryptography/pulls/comments/32581057","id":32581057,"diff_hunk":"@@ -56,6 +56,99 @@\n                                        [\"code\", \"lib\", \"func\", \"reason\"])\n \n \n+def _encode_asn1_int(backend, x):\n+    \"\"\"\n+    Converts a python integer to a ASN1_INTEGER. The returned ASN1_INTEGER will\n+    not be garbage collected (to support adding them to structs that take\n+    ownership of the object). Be sure to register it for GC if it will be\n+    discarded after use.\n+\n+    \"\"\"\n+    # Convert Python integer to OpenSSL \"bignum\" in case value exceeds\n+    # machine's native integer limits (note: `int_to_bn` doesn't automatically\n+    # GC).\n+    i = backend._int_to_bn(x)\n+    i = backend._ffi.gc(i, backend._lib.BN_free)\n+\n+    # Wrap in a ASN.1 integer.  Don't GC -- as documented.\n+    i = backend._lib.BN_to_ASN1_INTEGER(i, backend._ffi.NULL)\n+    assert i != backend._ffi.NULL\n+    return i\n+\n+\n+def _encode_asn1_str(backend, x, n):\n+    \"\"\"\n+    Create an ASN1_OCTET_STRING from a Python byte string.\n+    \"\"\"\n+    s = backend._lib.ASN1_OCTET_STRING_new()\n+    s = backend._ffi.gc(s, backend._lib.ASN1_OCTET_STRING_free)\n+    backend._lib.ASN1_OCTET_STRING_set(s, x, n)\n+    return s\n+\n+\n+def _encode_name(backend, attributes):\n+    subject = backend._lib.X509_NAME_new()\n+    subject = backend._ffi.gc(subject, backend._lib.X509_NAME_free)\n+    for attribute in attributes:\n+        value = attribute.value\n+        if isinstance(value, six.text_type):\n+            value = value.encode('ascii')\n+        obj = _txt2obj(backend, attribute.oid.dotted_string)\n+        res = backend._lib.X509_NAME_add_entry_by_OBJ(\n+            subject,\n+            obj,\n+            backend._lib.MBSTRING_ASC,\n+            value,\n+            -1, -1, 0,\n+        )\n+        assert res == 1\n+    return subject\n+\n+\n+def _txt2obj(backend, name):\n+    \"\"\"\n+    Converts a Python string with an ASN.1 object ID in dotted form to a\n+    ASN1_OBJECT.\n+    \"\"\"\n+    if isinstance(name, six.text_type):\n+        name = name.encode('ascii')\n+    obj = backend._lib.OBJ_txt2obj(name, 1)\n+    assert obj != backend._ffi.NULL\n+    obj = backend._ffi.gc(obj, backend._lib.ASN1_OBJECT_free)\n+    return obj\n+\n+\n+def _encode_basic_constraints(backend, ca=False, pathlen=0, critical=False):\n+    obj = _txt2obj(backend, x509.OID_BASIC_CONSTRAINTS.dotted_string)\n+    assert obj is not None\n+    constraints = backend._lib.BASIC_CONSTRAINTS_new()\n+    constraints.ca = 255 if ca else 0\n+    if ca:\n+        constraints.pathlen = _encode_asn1_int(backend, pathlen)\n+\n+    # Fetch the encoded payload.\n+    pp = backend._ffi.new('unsigned char**')","path":"src/cryptography/hazmat/backends/openssl/backend.py","position":84,"original_position":84,"commit_id":"91cfdc6e910c10da054370155e8559150d758091","original_commit_id":"91cfdc6e910c10da054370155e8559150d758091","user":{"login":"sigmavirus24","id":240830,"avatar_url":"https://avatars.githubusercontent.com/u/240830?v=3","gravatar_id":"","url":"https://api.github.com/users/sigmavirus24","html_url":"https://github.com/sigmavirus24","followers_url":"https://api.github.com/users/sigmavirus24/followers","following_url":"https://api.github.com/users/sigmavirus24/following{/other_user}","gists_url":"https://api.github.com/users/sigmavirus24/gists{/gist_id}","starred_url":"https://api.github.com/users/sigmavirus24/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sigmavirus24/subscriptions","organizations_url":"https://api.github.com/users/sigmavirus24/orgs","repos_url":"https://api.github.com/users/sigmavirus24/repos","events_url":"https://api.github.com/users/sigmavirus24/events{/privacy}","received_events_url":"https://api.github.com/users/sigmavirus24/received_events","type":"User","site_admin":false},"body":"Fixed in 9d90171","created_at":"2015-06-16T23:03:18Z","updated_at":"2015-06-16T23:03:18Z","html_url":"https://github.com/pyca/cryptography/pull/1927#discussion_r32581057","pull_request_url":"https://api.github.com/repos/pyca/cryptography/pulls/1927","_links":{"self":{"href":"https://api.github.com/repos/pyca/cryptography/pulls/comments/32581057"},"html":{"href":"https://github.com/pyca/cryptography/pull/1927#discussion_r32581057"},"pull_request":{"href":"https://api.github.com/repos/pyca/cryptography/pulls/1927"}}},"pull_request":{"url":"https://api.github.com/repos/pyca/cryptography/pulls/1927","id":35189419,"html_url":"https://github.com/pyca/cryptography/pull/1927","diff_url":"https://github.com/pyca/cryptography/pull/1927.diff","patch_url":"https://github.com/pyca/cryptography/pull/1927.patch","issue_url":"https://api.github.com/repos/pyca/cryptography/issues/1927","number":1927,"state":"open","locked":false,"title":"Adds CSR builder.","user":{"login":"AndreLouisCaron","id":135974,"avatar_url":"https://avatars.githubusercontent.com/u/135974?v=3","gravatar_id":"","url":"https://api.github.com/users/AndreLouisCaron","html_url":"https://github.com/AndreLouisCaron","followers_url":"https://api.github.com/users/AndreLouisCaron/followers","following_url":"https://api.github.com/users/AndreLouisCaron/following{/other_user}","gists_url":"https://api.github.com/users/AndreLouisCaron/gists{/gist_id}","starred_url":"https://api.github.com/users/AndreLouisCaron/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndreLouisCaron/subscriptions","organizations_url":"https://api.github.com/users/AndreLouisCaron/orgs","repos_url":"https://api.github.com/users/AndreLouisCaron/repos","events_url":"https://api.github.com/users/AndreLouisCaron/events{/privacy}","received_events_url":"https://api.github.com/users/AndreLouisCaron/received_events","type":"User","site_admin":false},"body":"This is a stripped down and rebased version of pull request #1914 with only the CSR builder.","created_at":"2015-05-12T03:00:39Z","updated_at":"2015-06-16T23:03:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"45e388d4673069a416cfe5e88ce1ba8fbda34eb8","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":19,"closed_issues":46,"state":"open","created_at":"2015-05-07T04:01:32Z","updated_at":"2015-06-13T11:31:03Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/pyca/cryptography/pulls/1927/commits","review_comments_url":"https://api.github.com/repos/pyca/cryptography/pulls/1927/comments","review_comment_url":"https://api.github.com/repos/pyca/cryptography/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pyca/cryptography/issues/1927/comments","statuses_url":"https://api.github.com/repos/pyca/cryptography/statuses/91cfdc6e910c10da054370155e8559150d758091","head":{"label":"AndreLouisCaron:csr-builder","ref":"csr-builder","sha":"91cfdc6e910c10da054370155e8559150d758091","user":{"login":"AndreLouisCaron","id":135974,"avatar_url":"https://avatars.githubusercontent.com/u/135974?v=3","gravatar_id":"","url":"https://api.github.com/users/AndreLouisCaron","html_url":"https://github.com/AndreLouisCaron","followers_url":"https://api.github.com/users/AndreLouisCaron/followers","following_url":"https://api.github.com/users/AndreLouisCaron/following{/other_user}","gists_url":"https://api.github.com/users/AndreLouisCaron/gists{/gist_id}","starred_url":"https://api.github.com/users/AndreLouisCaron/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndreLouisCaron/subscriptions","organizations_url":"https://api.github.com/users/AndreLouisCaron/orgs","repos_url":"https://api.github.com/users/AndreLouisCaron/repos","events_url":"https://api.github.com/users/AndreLouisCaron/events{/privacy}","received_events_url":"https://api.github.com/users/AndreLouisCaron/received_events","type":"User","site_admin":false},"repo":{"id":35314809,"name":"cryptography","full_name":"AndreLouisCaron/cryptography","owner":{"login":"AndreLouisCaron","id":135974,"avatar_url":"https://avatars.githubusercontent.com/u/135974?v=3","gravatar_id":"","url":"https://api.github.com/users/AndreLouisCaron","html_url":"https://github.com/AndreLouisCaron","followers_url":"https://api.github.com/users/AndreLouisCaron/followers","following_url":"https://api.github.com/users/AndreLouisCaron/following{/other_user}","gists_url":"https://api.github.com/users/AndreLouisCaron/gists{/gist_id}","starred_url":"https://api.github.com/users/AndreLouisCaron/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndreLouisCaron/subscriptions","organizations_url":"https://api.github.com/users/AndreLouisCaron/orgs","repos_url":"https://api.github.com/users/AndreLouisCaron/repos","events_url":"https://api.github.com/users/AndreLouisCaron/events{/privacy}","received_events_url":"https://api.github.com/users/AndreLouisCaron/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/AndreLouisCaron/cryptography","description":"cryptography is a package designed to expose cryptographic primitives and recipes to Python developers.","fork":true,"url":"https://api.github.com/repos/AndreLouisCaron/cryptography","forks_url":"https://api.github.com/repos/AndreLouisCaron/cryptography/forks","keys_url":"https://api.github.com/repos/AndreLouisCaron/cryptography/keys{/key_id}","collaborators_url":"https://api.github.com/repos/AndreLouisCaron/cryptography/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/AndreLouisCaron/cryptography/teams","hooks_url":"https://api.github.com/repos/AndreLouisCaron/cryptography/hooks","issue_events_url":"https://api.github.com/repos/AndreLouisCaron/cryptography/issues/events{/number}","events_url":"https://api.github.com/repos/AndreLouisCaron/cryptography/events","assignees_url":"https://api.github.com/repos/AndreLouisCaron/cryptography/assignees{/user}","branches_url":"https://api.github.com/repos/AndreLouisCaron/cryptography/branches{/branch}","tags_url":"https://api.github.com/repos/AndreLouisCaron/cryptography/tags","blobs_url":"https://api.github.com/repos/AndreLouisCaron/cryptography/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/AndreLouisCaron/cryptography/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/AndreLouisCaron/cryptography/git/refs{/sha}","trees_url":"https://api.github.com/repos/AndreLouisCaron/cryptography/git/trees{/sha}","statuses_url":"https://api.github.com/repos/AndreLouisCaron/cryptography/statuses/{sha}","languages_url":"https://api.github.com/repos/AndreLouisCaron/cryptography/languages","stargazers_url":"https://api.github.com/repos/AndreLouisCaron/cryptography/stargazers","contributors_url":"https://api.github.com/repos/AndreLouisCaron/cryptography/contributors","subscribers_url":"https://api.github.com/repos/AndreLouisCaron/cryptography/subscribers","subscription_url":"https://api.github.com/repos/AndreLouisCaron/cryptography/subscription","commits_url":"https://api.github.com/repos/AndreLouisCaron/cryptography/commits{/sha}","git_commits_url":"https://api.github.com/repos/AndreLouisCaron/cryptography/git/commits{/sha}","comments_url":"https://api.github.com/repos/AndreLouisCaron/cryptography/comments{/number}","issue_comment_url":"https://api.github.com/repos/AndreLouisCaron/cryptography/issues/comments{/number}","contents_url":"https://api.github.com/repos/AndreLouisCaron/cryptography/contents/{+path}","compare_url":"https://api.github.com/repos/AndreLouisCaron/cryptography/compare/{base}...{head}","merges_url":"https://api.github.com/repos/AndreLouisCaron/cryptography/merges","archive_url":"https://api.github.com/repos/AndreLouisCaron/cryptography/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/AndreLouisCaron/cryptography/downloads","issues_url":"https://api.github.com/repos/AndreLouisCaron/cryptography/issues{/number}","pulls_url":"https://api.github.com/repos/AndreLouisCaron/cryptography/pulls{/number}","milestones_url":"https://api.github.com/repos/AndreLouisCaron/cryptography/milestones{/number}","notifications_url":"https://api.github.com/repos/AndreLouisCaron/cryptography/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/AndreLouisCaron/cryptography/labels{/name}","releases_url":"https://api.github.com/repos/AndreLouisCaron/cryptography/releases{/id}","created_at":"2015-05-09T04:20:57Z","updated_at":"2015-05-09T04:21:04Z","pushed_at":"2015-06-16T22:57:17Z","git_url":"git://github.com/AndreLouisCaron/cryptography.git","ssh_url":"git@github.com:AndreLouisCaron/cryptography.git","clone_url":"https://github.com/AndreLouisCaron/cryptography.git","svn_url":"https://github.com/AndreLouisCaron/cryptography","homepage":"https://cryptography.io/","size":30293,"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":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"pyca:master","ref":"master","sha":"d1596063a47cafa0ffe9bfe696d95035a13f084b","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-16T03:43:59Z","pushed_at":"2015-06-16T03:02:48Z","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":43472,"stargazers_count":711,"watchers_count":711,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":161,"mirror_url":null,"open_issues_count":98,"forks":161,"open_issues":98,"watchers":711,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pyca/cryptography/pulls/1927"},"html":{"href":"https://github.com/pyca/cryptography/pull/1927"},"issue":{"href":"https://api.github.com/repos/pyca/cryptography/issues/1927"},"comments":{"href":"https://api.github.com/repos/pyca/cryptography/issues/1927/comments"},"review_comments":{"href":"https://api.github.com/repos/pyca/cryptography/pulls/1927/comments"},"review_comment":{"href":"https://api.github.com/repos/pyca/cryptography/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pyca/cryptography/pulls/1927/commits"},"statuses":{"href":"https://api.github.com/repos/pyca/cryptography/statuses/91cfdc6e910c10da054370155e8559150d758091"}}}}