{"action":"created","comment":{"url":"https://api.github.com/repos/odeke-em/drive/pulls/comments/63464667","id":63464667,"diff_hunk":"@@ -0,0 +1,102 @@\n+// Copyright 2016 Google Inc.\n+//\n+// Licensed under the Apache License, Version 2.0 (the \"License\");\n+// you may not use this file except in compliance with the License.\n+// You may obtain a copy of the License at\n+//\n+// http://www.apache.org/licenses/LICENSE-2.0\n+//\n+// Unless required by applicable law or agreed to in writing, software\n+// distributed under the License is distributed on an \"AS IS\" BASIS,\n+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+// See the License for the specific language governing permissions and\n+// limitations under the License.\n+\n+// Package dcrypto provides end to end encryption for drive.\n+\n+package dcrypto\n+\n+import (\n+\t\"bytes\"\n+\t\"encoding/binary\"\n+\t\"fmt\"\n+\t\"io\"\n+\n+\t\"github.com/odeke-em/drive/src/dcrypto/v1\"\n+)\n+\n+// Version is the version of the en/decryption library used.\n+type Version uint32\n+\n+// Decrypter is a function that creates a decrypter.\n+type Decrypter func(io.Reader, []byte) (io.ReadCloser, error)\n+\n+// Encrypter is a function that creates a encrypter.\n+type Encrypter func(io.Reader, []byte) (io.Reader, error)\n+\n+// These are the different versions of the en/decryption library.\n+const (\n+\tV1 Version = iota\n+)\n+\n+// PreferedVersion is the prefered version of encryption.\n+const PreferedVersion = V1\n+\n+var encrypters map[Version]Encrypter\n+var decrypters map[Version]Decrypter\n+\n+func init() {\n+\tdecrypters = map[Version]Decrypter{\n+\t\tV1: v1.NewDecryptReader,\n+\t}\n+\n+\tencrypters = map[Version]Encrypter{\n+\t\tV1: v1.NewEncryptReader,\n+\t}\n+}\n+\n+// NewEncrypter returns an Encrypter using the PreferedVersion.\n+func NewEncrypter(r io.Reader, password []byte) (io.Reader, error) {\n+\tv, err := writeVersion(PreferedVersion)\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\ter, err := encrypters[PreferedVersion](r, password)\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\treturn io.MultiReader(bytes.NewBuffer(v), er), nil\n+}\n+\n+// NewDecrypter returns a Decrypter based on the version used to encrypt.\n+func NewDecrypter(r io.Reader, password []byte) (io.ReadCloser, error) {\n+\tversion, err := readVersion(r)\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\td, ok := decrypters[version]\n+\tif !ok {","path":"src/dcrypto/dcrypto.go","position":78,"original_position":78,"commit_id":"c39bdf27425c2237acb21136239f4bbda45ccfe9","original_commit_id":"c39bdf27425c2237acb21136239f4bbda45ccfe9","user":{"login":"odeke-em","id":4898263,"avatar_url":"https://avatars.githubusercontent.com/u/4898263?v=3","gravatar_id":"","url":"https://api.github.com/users/odeke-em","html_url":"https://github.com/odeke-em","followers_url":"https://api.github.com/users/odeke-em/followers","following_url":"https://api.github.com/users/odeke-em/following{/other_user}","gists_url":"https://api.github.com/users/odeke-em/gists{/gist_id}","starred_url":"https://api.github.com/users/odeke-em/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odeke-em/subscriptions","organizations_url":"https://api.github.com/users/odeke-em/orgs","repos_url":"https://api.github.com/users/odeke-em/repos","events_url":"https://api.github.com/users/odeke-em/events{/privacy}","received_events_url":"https://api.github.com/users/odeke-em/received_events","type":"User","site_admin":false},"body":"Yap, just like you did here to first look up the decrypter by version, do that too above in looking up the encrypter.","created_at":"2016-05-17T05:00:27Z","updated_at":"2016-05-17T05:00:27Z","html_url":"https://github.com/odeke-em/drive/pull/645#discussion_r63464667","pull_request_url":"https://api.github.com/repos/odeke-em/drive/pulls/645","_links":{"self":{"href":"https://api.github.com/repos/odeke-em/drive/pulls/comments/63464667"},"html":{"href":"https://github.com/odeke-em/drive/pull/645#discussion_r63464667"},"pull_request":{"href":"https://api.github.com/repos/odeke-em/drive/pulls/645"}}},"pull_request":{"url":"https://api.github.com/repos/odeke-em/drive/pulls/645","id":70143310,"html_url":"https://github.com/odeke-em/drive/pull/645","diff_url":"https://github.com/odeke-em/drive/pull/645.diff","patch_url":"https://github.com/odeke-em/drive/pull/645.patch","issue_url":"https://api.github.com/repos/odeke-em/drive/issues/645","number":645,"state":"open","locked":false,"title":"Create an end to end encryption library","user":{"login":"sselph","id":8129878,"avatar_url":"https://avatars.githubusercontent.com/u/8129878?v=3","gravatar_id":"","url":"https://api.github.com/users/sselph","html_url":"https://github.com/sselph","followers_url":"https://api.github.com/users/sselph/followers","following_url":"https://api.github.com/users/sselph/following{/other_user}","gists_url":"https://api.github.com/users/sselph/gists{/gist_id}","starred_url":"https://api.github.com/users/sselph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sselph/subscriptions","organizations_url":"https://api.github.com/users/sselph/orgs","repos_url":"https://api.github.com/users/sselph/repos","events_url":"https://api.github.com/users/sselph/events{/privacy}","received_events_url":"https://api.github.com/users/sselph/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-05-16T02:32:38Z","updated_at":"2016-05-17T05:00:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"41a2e0857b017f39a69867dbc811bfebee638fd2","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/odeke-em/drive/pulls/645/commits","review_comments_url":"https://api.github.com/repos/odeke-em/drive/pulls/645/comments","review_comment_url":"https://api.github.com/repos/odeke-em/drive/pulls/comments{/number}","comments_url":"https://api.github.com/repos/odeke-em/drive/issues/645/comments","statuses_url":"https://api.github.com/repos/odeke-em/drive/statuses/c39bdf27425c2237acb21136239f4bbda45ccfe9","head":{"label":"sselph:master","ref":"master","sha":"c39bdf27425c2237acb21136239f4bbda45ccfe9","user":{"login":"sselph","id":8129878,"avatar_url":"https://avatars.githubusercontent.com/u/8129878?v=3","gravatar_id":"","url":"https://api.github.com/users/sselph","html_url":"https://github.com/sselph","followers_url":"https://api.github.com/users/sselph/followers","following_url":"https://api.github.com/users/sselph/following{/other_user}","gists_url":"https://api.github.com/users/sselph/gists{/gist_id}","starred_url":"https://api.github.com/users/sselph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sselph/subscriptions","organizations_url":"https://api.github.com/users/sselph/orgs","repos_url":"https://api.github.com/users/sselph/repos","events_url":"https://api.github.com/users/sselph/events{/privacy}","received_events_url":"https://api.github.com/users/sselph/received_events","type":"User","site_admin":false},"repo":{"id":58142708,"name":"drive","full_name":"sselph/drive","owner":{"login":"sselph","id":8129878,"avatar_url":"https://avatars.githubusercontent.com/u/8129878?v=3","gravatar_id":"","url":"https://api.github.com/users/sselph","html_url":"https://github.com/sselph","followers_url":"https://api.github.com/users/sselph/followers","following_url":"https://api.github.com/users/sselph/following{/other_user}","gists_url":"https://api.github.com/users/sselph/gists{/gist_id}","starred_url":"https://api.github.com/users/sselph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sselph/subscriptions","organizations_url":"https://api.github.com/users/sselph/orgs","repos_url":"https://api.github.com/users/sselph/repos","events_url":"https://api.github.com/users/sselph/events{/privacy}","received_events_url":"https://api.github.com/users/sselph/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/sselph/drive","description":"Google Drive client for the commandline","fork":true,"url":"https://api.github.com/repos/sselph/drive","forks_url":"https://api.github.com/repos/sselph/drive/forks","keys_url":"https://api.github.com/repos/sselph/drive/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sselph/drive/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sselph/drive/teams","hooks_url":"https://api.github.com/repos/sselph/drive/hooks","issue_events_url":"https://api.github.com/repos/sselph/drive/issues/events{/number}","events_url":"https://api.github.com/repos/sselph/drive/events","assignees_url":"https://api.github.com/repos/sselph/drive/assignees{/user}","branches_url":"https://api.github.com/repos/sselph/drive/branches{/branch}","tags_url":"https://api.github.com/repos/sselph/drive/tags","blobs_url":"https://api.github.com/repos/sselph/drive/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sselph/drive/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sselph/drive/git/refs{/sha}","trees_url":"https://api.github.com/repos/sselph/drive/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sselph/drive/statuses/{sha}","languages_url":"https://api.github.com/repos/sselph/drive/languages","stargazers_url":"https://api.github.com/repos/sselph/drive/stargazers","contributors_url":"https://api.github.com/repos/sselph/drive/contributors","subscribers_url":"https://api.github.com/repos/sselph/drive/subscribers","subscription_url":"https://api.github.com/repos/sselph/drive/subscription","commits_url":"https://api.github.com/repos/sselph/drive/commits{/sha}","git_commits_url":"https://api.github.com/repos/sselph/drive/git/commits{/sha}","comments_url":"https://api.github.com/repos/sselph/drive/comments{/number}","issue_comment_url":"https://api.github.com/repos/sselph/drive/issues/comments{/number}","contents_url":"https://api.github.com/repos/sselph/drive/contents/{+path}","compare_url":"https://api.github.com/repos/sselph/drive/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sselph/drive/merges","archive_url":"https://api.github.com/repos/sselph/drive/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sselph/drive/downloads","issues_url":"https://api.github.com/repos/sselph/drive/issues{/number}","pulls_url":"https://api.github.com/repos/sselph/drive/pulls{/number}","milestones_url":"https://api.github.com/repos/sselph/drive/milestones{/number}","notifications_url":"https://api.github.com/repos/sselph/drive/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sselph/drive/labels{/name}","releases_url":"https://api.github.com/repos/sselph/drive/releases{/id}","deployments_url":"https://api.github.com/repos/sselph/drive/deployments","created_at":"2016-05-05T15:51:40Z","updated_at":"2016-05-05T15:51:41Z","pushed_at":"2016-05-17T00:59:30Z","git_url":"git://github.com/sselph/drive.git","ssh_url":"git@github.com:sselph/drive.git","clone_url":"https://github.com/sselph/drive.git","svn_url":"https://github.com/sselph/drive","homepage":"","size":4417,"stargazers_count":0,"watchers_count":0,"language":"Go","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":"odeke-em:master","ref":"master","sha":"f411a4a957fddc964da7bebd435e11c40e397021","user":{"login":"odeke-em","id":4898263,"avatar_url":"https://avatars.githubusercontent.com/u/4898263?v=3","gravatar_id":"","url":"https://api.github.com/users/odeke-em","html_url":"https://github.com/odeke-em","followers_url":"https://api.github.com/users/odeke-em/followers","following_url":"https://api.github.com/users/odeke-em/following{/other_user}","gists_url":"https://api.github.com/users/odeke-em/gists{/gist_id}","starred_url":"https://api.github.com/users/odeke-em/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odeke-em/subscriptions","organizations_url":"https://api.github.com/users/odeke-em/orgs","repos_url":"https://api.github.com/users/odeke-em/repos","events_url":"https://api.github.com/users/odeke-em/events{/privacy}","received_events_url":"https://api.github.com/users/odeke-em/received_events","type":"User","site_admin":false},"repo":{"id":26109545,"name":"drive","full_name":"odeke-em/drive","owner":{"login":"odeke-em","id":4898263,"avatar_url":"https://avatars.githubusercontent.com/u/4898263?v=3","gravatar_id":"","url":"https://api.github.com/users/odeke-em","html_url":"https://github.com/odeke-em","followers_url":"https://api.github.com/users/odeke-em/followers","following_url":"https://api.github.com/users/odeke-em/following{/other_user}","gists_url":"https://api.github.com/users/odeke-em/gists{/gist_id}","starred_url":"https://api.github.com/users/odeke-em/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odeke-em/subscriptions","organizations_url":"https://api.github.com/users/odeke-em/orgs","repos_url":"https://api.github.com/users/odeke-em/repos","events_url":"https://api.github.com/users/odeke-em/events{/privacy}","received_events_url":"https://api.github.com/users/odeke-em/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/odeke-em/drive","description":"Google Drive client for the commandline","fork":true,"url":"https://api.github.com/repos/odeke-em/drive","forks_url":"https://api.github.com/repos/odeke-em/drive/forks","keys_url":"https://api.github.com/repos/odeke-em/drive/keys{/key_id}","collaborators_url":"https://api.github.com/repos/odeke-em/drive/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/odeke-em/drive/teams","hooks_url":"https://api.github.com/repos/odeke-em/drive/hooks","issue_events_url":"https://api.github.com/repos/odeke-em/drive/issues/events{/number}","events_url":"https://api.github.com/repos/odeke-em/drive/events","assignees_url":"https://api.github.com/repos/odeke-em/drive/assignees{/user}","branches_url":"https://api.github.com/repos/odeke-em/drive/branches{/branch}","tags_url":"https://api.github.com/repos/odeke-em/drive/tags","blobs_url":"https://api.github.com/repos/odeke-em/drive/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/odeke-em/drive/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/odeke-em/drive/git/refs{/sha}","trees_url":"https://api.github.com/repos/odeke-em/drive/git/trees{/sha}","statuses_url":"https://api.github.com/repos/odeke-em/drive/statuses/{sha}","languages_url":"https://api.github.com/repos/odeke-em/drive/languages","stargazers_url":"https://api.github.com/repos/odeke-em/drive/stargazers","contributors_url":"https://api.github.com/repos/odeke-em/drive/contributors","subscribers_url":"https://api.github.com/repos/odeke-em/drive/subscribers","subscription_url":"https://api.github.com/repos/odeke-em/drive/subscription","commits_url":"https://api.github.com/repos/odeke-em/drive/commits{/sha}","git_commits_url":"https://api.github.com/repos/odeke-em/drive/git/commits{/sha}","comments_url":"https://api.github.com/repos/odeke-em/drive/comments{/number}","issue_comment_url":"https://api.github.com/repos/odeke-em/drive/issues/comments{/number}","contents_url":"https://api.github.com/repos/odeke-em/drive/contents/{+path}","compare_url":"https://api.github.com/repos/odeke-em/drive/compare/{base}...{head}","merges_url":"https://api.github.com/repos/odeke-em/drive/merges","archive_url":"https://api.github.com/repos/odeke-em/drive/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/odeke-em/drive/downloads","issues_url":"https://api.github.com/repos/odeke-em/drive/issues{/number}","pulls_url":"https://api.github.com/repos/odeke-em/drive/pulls{/number}","milestones_url":"https://api.github.com/repos/odeke-em/drive/milestones{/number}","notifications_url":"https://api.github.com/repos/odeke-em/drive/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/odeke-em/drive/labels{/name}","releases_url":"https://api.github.com/repos/odeke-em/drive/releases{/id}","deployments_url":"https://api.github.com/repos/odeke-em/drive/deployments","created_at":"2014-11-03T08:18:11Z","updated_at":"2016-05-16T18:14:54Z","pushed_at":"2016-05-17T00:59:30Z","git_url":"git://github.com/odeke-em/drive.git","ssh_url":"git@github.com:odeke-em/drive.git","clone_url":"https://github.com/odeke-em/drive.git","svn_url":"https://github.com/odeke-em/drive","homepage":"","size":5103,"stargazers_count":2034,"watchers_count":2034,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":165,"mirror_url":null,"open_issues_count":71,"forks":165,"open_issues":71,"watchers":2034,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/odeke-em/drive/pulls/645"},"html":{"href":"https://github.com/odeke-em/drive/pull/645"},"issue":{"href":"https://api.github.com/repos/odeke-em/drive/issues/645"},"comments":{"href":"https://api.github.com/repos/odeke-em/drive/issues/645/comments"},"review_comments":{"href":"https://api.github.com/repos/odeke-em/drive/pulls/645/comments"},"review_comment":{"href":"https://api.github.com/repos/odeke-em/drive/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/odeke-em/drive/pulls/645/commits"},"statuses":{"href":"https://api.github.com/repos/odeke-em/drive/statuses/c39bdf27425c2237acb21136239f4bbda45ccfe9"}}}}