{"action":"created","comment":{"url":"https://api.github.com/repos/dotnet/corefx/pulls/comments/57098206","id":57098206,"diff_hunk":"@@ -0,0 +1,270 @@\n+﻿// Licensed to the .NET Foundation under one or more agreements.\n+// The .NET Foundation licenses this file to you under the MIT license.\n+// See the LICENSE file in the project root for more information.\n+\n+using Microsoft.Win32.SafeHandles;\n+\n+namespace System.Security.Cryptography\n+{\n+    public sealed partial class ECDsaOpenSsl : ECDsa\n+    {\n+        /// <summary>\n+        ///         ImportParameters will replace the existing key that ECDsaOpenSsl is working with by creating a\n+        ///         new CngKey. If the parameters structure contains only Q,\n+        ///         then only a public key will be imported. If the parameters also contains D, \n+        ///         then a full key pair will be imported. If the parameters do not specify Q,\n+        ///         a then a full key pair will be created.\n+        ///         The Curve value is required to specify what other values are imported.\n+        /// </summary>\n+        /// <exception cref=\"CryptographicException\">\n+        ///     if <paramref name=\"parameters\" /> is not a valid ECDsa key or is missing values.\n+        /// </exception>\n+        public override void ImportParameters(ECParameters parameters)\n+        {\n+            bool includePrivate;\n+            if (parameters.D == null && IsPublicKeyDefined(parameters))\n+            {\n+                includePrivate = false;\n+            }\n+            else\n+            {\n+                includePrivate = true;\n+            }\n+\n+            SafeEcKeyHandle key;\n+            if (parameters.Curve is ECPrimeCurve)\n+            {\n+                ECPrimeCurve curve = (ECPrimeCurve)parameters.Curve;\n+\n+                if (!ValidateExplicitCurve(curve))\n+                    throw new CryptographicException(SR.Argument_InvalidValue);// Cryptography_InvalidECPrimeCurveParameters);\n+\n+                key = ImportPrimeCurveParameters(parameters, curve, includePrivate);\n+            }\n+            else if (parameters.Curve is ECCharacteristic2Curve)\n+            {\n+                ECCharacteristic2Curve curve = (ECCharacteristic2Curve)parameters.Curve;\n+                //TODO if (!ValidateExplicitCurve(curve, cbKey))\n+                //    throw new CryptographicException(SR.Argument_InvalidValue);// Cryptography_InvalidECPrimeCurveParameters);\n+                key = ImportCharacteristic2CurveParameters(parameters, curve, includePrivate);\n+            }\n+            else if (parameters.Curve is ECNamedCurve)\n+            {\n+                ECNamedCurve curve = (ECNamedCurve)parameters.Curve;\n+\n+                if (!ValidateNamedCurve(curve))\n+                    throw new CryptographicException(SR.Argument_InvalidValue);// Cryptography_InvalidECNamedCurveParameters);\n+\n+                key = ImportNamedCurveParameters(parameters, curve, includePrivate);\n+            }\n+            else\n+            {\n+                throw new NotSupportedException();\n+            }\n+\n+            SetKey(key);\n+        }\n+\n+        /// <summary>\n+        ///     Exports the key used by the ECC object into an ECParameters object.\n+        /// </summary>\n+        public override ECParameters ExportExplicitCurveParameters(bool includePrivateParameters)\n+        {\n+            // todo char2 curve\n+            SafeEcKeyHandle currentKey = _key.Value;\n+\n+            ECParameters ecparams = ExportExplicitCurveParameters(currentKey, includePrivateParameters);\n+            return ecparams;\n+        }\n+\n+        /// <summary>\n+        ///     Exports the key used by the ECC object into an ECParameters object.\n+        /// </summary>\n+        public override ECParameters ExportNamedCurveParameters(bool includePrivateParameters)\n+        {\n+            SafeEcKeyHandle currentKey = _key.Value;\n+\n+            ECParameters ecparams = ExportNamedCurveParameters(currentKey, includePrivateParameters);\n+            string keyOidValueName = Interop.Crypto.EcKeyGetOidValueCurveName(currentKey);\n+            string keyOidFriendlyName = Interop.Crypto.EcKeyGetOidFriendyCurveName(keyOidValueName);\n+\n+            ecparams.Curve = new ECNamedCurve(new Oid(keyOidValueName, keyOidFriendlyName));\n+            return ecparams;\n+        }\n+\n+        private static ECParameters ExportNamedCurveParameters(SafeEcKeyHandle key, bool includePrivate)\n+        {\n+            // It's entirely possible that this line will cause the key to be generated in the first place.\n+            CheckInvalidKey(key);\n+\n+            ECParameters parameters = new ECParameters();\n+\n+            Interop.Crypto.GetECKeyParameters(key, includePrivate, out parameters.Q.X, out parameters.Q.Y, out parameters.D);\n+\n+            bool hasPrivateKey = (parameters.D != null);\n+            if (hasPrivateKey != includePrivate) // || !HasConsistentPrivateKey(rsaParameters))\n+            {\n+                throw new CryptographicException(SR.Cryptography_CSP_NoPrivateKey);\n+            }\n+\n+            return parameters;\n+        }\n+\n+        private static ECParameters ExportExplicitCurveParameters(SafeEcKeyHandle key, bool includePrivate)\n+        {\n+            // It's entirely possible that this line will cause the key to be generated in the first place.\n+            CheckInvalidKey(key);\n+\n+            ECCurveType curveType = Interop.Crypto.EcKeyGetCurveType(key);\n+            if (curveType == ECCurveType.Unspecified)\n+            {\n+                throw new PlatformNotSupportedException();","path":"src/System.Security.Cryptography.OpenSsl/src/System/Security/Cryptography/ECDsaOpenSsl.ImportExport.cs","position":121,"original_position":121,"commit_id":"7615fc2841e5d63483515f32a14c42982a3ce160","original_commit_id":"7615fc2841e5d63483515f32a14c42982a3ce160","user":{"login":"bartonjs","id":10642668,"avatar_url":"https://avatars.githubusercontent.com/u/10642668?v=3","gravatar_id":"","url":"https://api.github.com/users/bartonjs","html_url":"https://github.com/bartonjs","followers_url":"https://api.github.com/users/bartonjs/followers","following_url":"https://api.github.com/users/bartonjs/following{/other_user}","gists_url":"https://api.github.com/users/bartonjs/gists{/gist_id}","starred_url":"https://api.github.com/users/bartonjs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bartonjs/subscriptions","organizations_url":"https://api.github.com/users/bartonjs/orgs","repos_url":"https://api.github.com/users/bartonjs/repos","events_url":"https://api.github.com/users/bartonjs/events{/privacy}","received_events_url":"https://api.github.com/users/bartonjs/received_events","type":"User","site_admin":false},"body":"Resource string","created_at":"2016-03-23T01:36:39Z","updated_at":"2016-03-23T01:36:39Z","html_url":"https://github.com/dotnet/corefx/pull/6789#discussion_r57098206","pull_request_url":"https://api.github.com/repos/dotnet/corefx/pulls/6789","_links":{"self":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/comments/57098206"},"html":{"href":"https://github.com/dotnet/corefx/pull/6789#discussion_r57098206"},"pull_request":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/6789"}}},"pull_request":{"url":"https://api.github.com/repos/dotnet/corefx/pulls/6789","id":62315654,"html_url":"https://github.com/dotnet/corefx/pull/6789","diff_url":"https://github.com/dotnet/corefx/pull/6789.diff","patch_url":"https://github.com/dotnet/corefx/pull/6789.patch","issue_url":"https://api.github.com/repos/dotnet/corefx/issues/6789","number":6789,"state":"open","locked":false,"title":"WIP DONT MERGE Support Elliptical Curve Cryptography named curves and export","user":{"login":"steveharter","id":6986755,"avatar_url":"https://avatars.githubusercontent.com/u/6986755?v=3","gravatar_id":"","url":"https://api.github.com/users/steveharter","html_url":"https://github.com/steveharter","followers_url":"https://api.github.com/users/steveharter/followers","following_url":"https://api.github.com/users/steveharter/following{/other_user}","gists_url":"https://api.github.com/users/steveharter/gists{/gist_id}","starred_url":"https://api.github.com/users/steveharter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/steveharter/subscriptions","organizations_url":"https://api.github.com/users/steveharter/orgs","repos_url":"https://api.github.com/users/steveharter/repos","events_url":"https://api.github.com/users/steveharter/events{/privacy}","received_events_url":"https://api.github.com/users/steveharter/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-03-09T23:39:22Z","updated_at":"2016-03-23T01:36:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"29317e232381a63c92821ec339eefd29d14cf795","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/dotnet/corefx/pulls/6789/commits","review_comments_url":"https://api.github.com/repos/dotnet/corefx/pulls/6789/comments","review_comment_url":"https://api.github.com/repos/dotnet/corefx/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dotnet/corefx/issues/6789/comments","statuses_url":"https://api.github.com/repos/dotnet/corefx/statuses/7615fc2841e5d63483515f32a14c42982a3ce160","head":{"label":"steveharter:Crypto","ref":"Crypto","sha":"7615fc2841e5d63483515f32a14c42982a3ce160","user":{"login":"steveharter","id":6986755,"avatar_url":"https://avatars.githubusercontent.com/u/6986755?v=3","gravatar_id":"","url":"https://api.github.com/users/steveharter","html_url":"https://github.com/steveharter","followers_url":"https://api.github.com/users/steveharter/followers","following_url":"https://api.github.com/users/steveharter/following{/other_user}","gists_url":"https://api.github.com/users/steveharter/gists{/gist_id}","starred_url":"https://api.github.com/users/steveharter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/steveharter/subscriptions","organizations_url":"https://api.github.com/users/steveharter/orgs","repos_url":"https://api.github.com/users/steveharter/repos","events_url":"https://api.github.com/users/steveharter/events{/privacy}","received_events_url":"https://api.github.com/users/steveharter/received_events","type":"User","site_admin":false},"repo":{"id":39029448,"name":"dotnet_corefx","full_name":"steveharter/dotnet_corefx","owner":{"login":"steveharter","id":6986755,"avatar_url":"https://avatars.githubusercontent.com/u/6986755?v=3","gravatar_id":"","url":"https://api.github.com/users/steveharter","html_url":"https://github.com/steveharter","followers_url":"https://api.github.com/users/steveharter/followers","following_url":"https://api.github.com/users/steveharter/following{/other_user}","gists_url":"https://api.github.com/users/steveharter/gists{/gist_id}","starred_url":"https://api.github.com/users/steveharter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/steveharter/subscriptions","organizations_url":"https://api.github.com/users/steveharter/orgs","repos_url":"https://api.github.com/users/steveharter/repos","events_url":"https://api.github.com/users/steveharter/events{/privacy}","received_events_url":"https://api.github.com/users/steveharter/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/steveharter/dotnet_corefx","description":"This repo contains the .NET Core foundational libraries, called CoreFX. It includes classes for collections, file systems, console, XML, async and many others.","fork":true,"url":"https://api.github.com/repos/steveharter/dotnet_corefx","forks_url":"https://api.github.com/repos/steveharter/dotnet_corefx/forks","keys_url":"https://api.github.com/repos/steveharter/dotnet_corefx/keys{/key_id}","collaborators_url":"https://api.github.com/repos/steveharter/dotnet_corefx/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/steveharter/dotnet_corefx/teams","hooks_url":"https://api.github.com/repos/steveharter/dotnet_corefx/hooks","issue_events_url":"https://api.github.com/repos/steveharter/dotnet_corefx/issues/events{/number}","events_url":"https://api.github.com/repos/steveharter/dotnet_corefx/events","assignees_url":"https://api.github.com/repos/steveharter/dotnet_corefx/assignees{/user}","branches_url":"https://api.github.com/repos/steveharter/dotnet_corefx/branches{/branch}","tags_url":"https://api.github.com/repos/steveharter/dotnet_corefx/tags","blobs_url":"https://api.github.com/repos/steveharter/dotnet_corefx/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/steveharter/dotnet_corefx/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/steveharter/dotnet_corefx/git/refs{/sha}","trees_url":"https://api.github.com/repos/steveharter/dotnet_corefx/git/trees{/sha}","statuses_url":"https://api.github.com/repos/steveharter/dotnet_corefx/statuses/{sha}","languages_url":"https://api.github.com/repos/steveharter/dotnet_corefx/languages","stargazers_url":"https://api.github.com/repos/steveharter/dotnet_corefx/stargazers","contributors_url":"https://api.github.com/repos/steveharter/dotnet_corefx/contributors","subscribers_url":"https://api.github.com/repos/steveharter/dotnet_corefx/subscribers","subscription_url":"https://api.github.com/repos/steveharter/dotnet_corefx/subscription","commits_url":"https://api.github.com/repos/steveharter/dotnet_corefx/commits{/sha}","git_commits_url":"https://api.github.com/repos/steveharter/dotnet_corefx/git/commits{/sha}","comments_url":"https://api.github.com/repos/steveharter/dotnet_corefx/comments{/number}","issue_comment_url":"https://api.github.com/repos/steveharter/dotnet_corefx/issues/comments{/number}","contents_url":"https://api.github.com/repos/steveharter/dotnet_corefx/contents/{+path}","compare_url":"https://api.github.com/repos/steveharter/dotnet_corefx/compare/{base}...{head}","merges_url":"https://api.github.com/repos/steveharter/dotnet_corefx/merges","archive_url":"https://api.github.com/repos/steveharter/dotnet_corefx/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/steveharter/dotnet_corefx/downloads","issues_url":"https://api.github.com/repos/steveharter/dotnet_corefx/issues{/number}","pulls_url":"https://api.github.com/repos/steveharter/dotnet_corefx/pulls{/number}","milestones_url":"https://api.github.com/repos/steveharter/dotnet_corefx/milestones{/number}","notifications_url":"https://api.github.com/repos/steveharter/dotnet_corefx/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/steveharter/dotnet_corefx/labels{/name}","releases_url":"https://api.github.com/repos/steveharter/dotnet_corefx/releases{/id}","deployments_url":"https://api.github.com/repos/steveharter/dotnet_corefx/deployments","created_at":"2015-07-13T18:20:31Z","updated_at":"2016-01-13T22:53:29Z","pushed_at":"2016-03-22T21:47:34Z","git_url":"git://github.com/steveharter/dotnet_corefx.git","ssh_url":"git@github.com:steveharter/dotnet_corefx.git","clone_url":"https://github.com/steveharter/dotnet_corefx.git","svn_url":"https://github.com/steveharter/dotnet_corefx","homepage":"http://dotnet.github.io/core/","size":59719,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"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":"dotnet:master","ref":"master","sha":"181e6331d98acbf976ace048c63101feec0f612f","user":{"login":"dotnet","id":9141961,"avatar_url":"https://avatars.githubusercontent.com/u/9141961?v=3","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"repo":{"id":26295345,"name":"corefx","full_name":"dotnet/corefx","owner":{"login":"dotnet","id":9141961,"avatar_url":"https://avatars.githubusercontent.com/u/9141961?v=3","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dotnet/corefx","description":"This repo contains the .NET Core foundational libraries, called CoreFX. It includes classes for collections, file systems, console, XML, async and many others.","fork":false,"url":"https://api.github.com/repos/dotnet/corefx","forks_url":"https://api.github.com/repos/dotnet/corefx/forks","keys_url":"https://api.github.com/repos/dotnet/corefx/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dotnet/corefx/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dotnet/corefx/teams","hooks_url":"https://api.github.com/repos/dotnet/corefx/hooks","issue_events_url":"https://api.github.com/repos/dotnet/corefx/issues/events{/number}","events_url":"https://api.github.com/repos/dotnet/corefx/events","assignees_url":"https://api.github.com/repos/dotnet/corefx/assignees{/user}","branches_url":"https://api.github.com/repos/dotnet/corefx/branches{/branch}","tags_url":"https://api.github.com/repos/dotnet/corefx/tags","blobs_url":"https://api.github.com/repos/dotnet/corefx/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dotnet/corefx/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dotnet/corefx/git/refs{/sha}","trees_url":"https://api.github.com/repos/dotnet/corefx/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dotnet/corefx/statuses/{sha}","languages_url":"https://api.github.com/repos/dotnet/corefx/languages","stargazers_url":"https://api.github.com/repos/dotnet/corefx/stargazers","contributors_url":"https://api.github.com/repos/dotnet/corefx/contributors","subscribers_url":"https://api.github.com/repos/dotnet/corefx/subscribers","subscription_url":"https://api.github.com/repos/dotnet/corefx/subscription","commits_url":"https://api.github.com/repos/dotnet/corefx/commits{/sha}","git_commits_url":"https://api.github.com/repos/dotnet/corefx/git/commits{/sha}","comments_url":"https://api.github.com/repos/dotnet/corefx/comments{/number}","issue_comment_url":"https://api.github.com/repos/dotnet/corefx/issues/comments{/number}","contents_url":"https://api.github.com/repos/dotnet/corefx/contents/{+path}","compare_url":"https://api.github.com/repos/dotnet/corefx/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dotnet/corefx/merges","archive_url":"https://api.github.com/repos/dotnet/corefx/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dotnet/corefx/downloads","issues_url":"https://api.github.com/repos/dotnet/corefx/issues{/number}","pulls_url":"https://api.github.com/repos/dotnet/corefx/pulls{/number}","milestones_url":"https://api.github.com/repos/dotnet/corefx/milestones{/number}","notifications_url":"https://api.github.com/repos/dotnet/corefx/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dotnet/corefx/labels{/name}","releases_url":"https://api.github.com/repos/dotnet/corefx/releases{/id}","deployments_url":"https://api.github.com/repos/dotnet/corefx/deployments","created_at":"2014-11-06T23:42:48Z","updated_at":"2016-03-22T17:45:56Z","pushed_at":"2016-03-23T01:33:36Z","git_url":"git://github.com/dotnet/corefx.git","ssh_url":"git@github.com:dotnet/corefx.git","clone_url":"https://github.com/dotnet/corefx.git","svn_url":"https://github.com/dotnet/corefx","homepage":"http://dotnet.github.io/","size":81936,"stargazers_count":9359,"watchers_count":9359,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2200,"mirror_url":null,"open_issues_count":941,"forks":2200,"open_issues":941,"watchers":9359,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/6789"},"html":{"href":"https://github.com/dotnet/corefx/pull/6789"},"issue":{"href":"https://api.github.com/repos/dotnet/corefx/issues/6789"},"comments":{"href":"https://api.github.com/repos/dotnet/corefx/issues/6789/comments"},"review_comments":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/6789/comments"},"review_comment":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/6789/commits"},"statuses":{"href":"https://api.github.com/repos/dotnet/corefx/statuses/7615fc2841e5d63483515f32a14c42982a3ce160"}}}}