{"action":"created","comment":{"url":"https://api.github.com/repos/zetok/tox/pulls/comments/67601168","id":67601168,"diff_hunk":"@@ -234,23 +234,94 @@ pub fn is_encrypted(data: &[u8]) -> bool {\n     data.starts_with(MAGIC_NUMBER)\n }\n \n-/** Try to encrypt given **TES** data with provided passphrase.\n+/**\n+Try to encrypt given **TES** data with provided passphrase.\n \n-    **Note that `passphrase` memory is not being zeroed after it has been\n-    used**. Code that provides `passphrase` should take care of zeroing that\n-    memory.\n+**Note that `passphrase` memory is not being zeroed after it has been\n+used**. Code that provides `passphrase` should take care of zeroing that\n+memory.\n+\n+# Fails when:\n+\n+  * `data` is empty\n+  * `passphrase` is empty\n+  * deriving key failed (can happen due to OOM)\n+\n+E.g.\n+\n+```\n+use self::tox::toxencryptsave::*;\n+\n+// empty data\n+assert_eq!(Err(EncryptionError::Null), pass_encrypt(&[], &[0]));\n+\n+// empty passphrase\n+assert_eq!(Err(EncryptionError::KeyDerivation(KeyDerivationError::Null)),\n+           pass_encrypt(&[0], &[]));\n+```\n */\n pub fn pass_encrypt(data: &[u8], passphrase: &[u8]) -> Result<Vec<u8>, EncryptionError> {\n     try!(PassKey::new(passphrase)).encrypt(data)\n }\n \n-/** Try to encrypt given **TES** data with provided passphrase.\n+/**\n+Try to encrypt given **TES** data with provided passphrase.\n \n-    **Note that `passphrase` memory is not being zeroed after it has been\n-    used**. Code that provides `passphrase` should take care of zeroing that\n-    memory.\n+**Note that `passphrase` memory is not being zeroed after it has been\n+used**. Code that provides `passphrase` should take care of zeroing that\n+memory.\n+\n+Decrypted data is smaller by [`EXTRA_LENGTH`](./constant.EXTRA_LENGTH.html)\n+than encrypted data.\n+\n+## Fails when:\n+\n+  * provided `data` is empty\n+  * size of provided `data` is less than `EXTRA_LENGTH`\n+  * format of provided `data` is wrong\n+  * decrypting `data` fails\n+    - could be due to OOM or by providing bytes that aren't encrypted after\n+      encrypted part\n+  * `passphrase` is empty\n+\n+```\n+use self::tox::toxencryptsave::*;\n+\n+// with an empty data\n+assert_eq!(Err(DecryptionError::Null), pass_decrypt(&[], &[0]));\n+\n+// when there's not enough data to decrypt\n+assert_eq!(Err(DecryptionError::InvalidLength), pass_decrypt(MAGIC_NUMBER, &[0]));\n+\n+let encrypted = pass_encrypt(&[0, 0], &[0]).expect(\"Failed to pass_encrypt!\");\n+\n+// when passphrase is empty\n+assert_eq!(Err(DecryptionError::KeyDerivation(KeyDerivationError::Null)),\n+           pass_decrypt(&encrypted, &[]));\n+\n+// when data format is wrong\n+for pos in 0..MAGIC_LENGTH {\n+    let mut enc = encrypted.clone();\n+    if enc[pos] == 0 { enc[pos] = 1; } else { enc[pos] = 0; }\n+    assert_eq!(Err(DecryptionError::BadFormat), pass_decrypt(&enc, &[0]));\n+}\n+\n+{ // there are more or less bytes than the encrypted ones\n+    let mut enc = encrypted.clone();\n+    enc.push(0);\n+    assert_eq!(Err(DecryptionError::Failed), pass_decrypt(&enc, &[0]));\n+\n+    // less\n+    drop((enc.pop(), enc.pop()));\n+    assert_eq!(Err(DecryptionError::Failed), pass_decrypt(&enc, &[0]));\n+}\n+```\n */\n pub fn pass_decrypt(data: &[u8], passphrase: &[u8]) -> Result<Vec<u8>, DecryptionError> {\n+    if data.is_empty() { return Err(DecryptionError::Null) }","path":"src/toxencryptsave/mod.rs","position":96,"original_position":96,"commit_id":"65febe6d7d569fa139ee79b443844a1d56cc9b51","original_commit_id":"65febe6d7d569fa139ee79b443844a1d56cc9b51","user":{"login":"quininer","id":6286761,"avatar_url":"https://avatars.githubusercontent.com/u/6286761?v=3","gravatar_id":"","url":"https://api.github.com/users/quininer","html_url":"https://github.com/quininer","followers_url":"https://api.github.com/users/quininer/followers","following_url":"https://api.github.com/users/quininer/following{/other_user}","gists_url":"https://api.github.com/users/quininer/gists{/gist_id}","starred_url":"https://api.github.com/users/quininer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/quininer/subscriptions","organizations_url":"https://api.github.com/users/quininer/orgs","repos_url":"https://api.github.com/users/quininer/repos","events_url":"https://api.github.com/users/quininer/events{/privacy}","received_events_url":"https://api.github.com/users/quininer/received_events","type":"User","site_admin":false},"body":"This seems to be redundant?\r\nhttps://github.com/zetok/tox/blob/master/src/toxencryptsave/mod.rs#L213\r\n","created_at":"2016-06-18T13:38:24Z","updated_at":"2016-06-18T13:38:24Z","html_url":"https://github.com/zetok/tox/pull/12#discussion_r67601168","pull_request_url":"https://api.github.com/repos/zetok/tox/pulls/12","_links":{"self":{"href":"https://api.github.com/repos/zetok/tox/pulls/comments/67601168"},"html":{"href":"https://github.com/zetok/tox/pull/12#discussion_r67601168"},"pull_request":{"href":"https://api.github.com/repos/zetok/tox/pulls/12"}}},"pull_request":{"url":"https://api.github.com/repos/zetok/tox/pulls/12","id":74333193,"html_url":"https://github.com/zetok/tox/pull/12","diff_url":"https://github.com/zetok/tox/pull/12.diff","patch_url":"https://github.com/zetok/tox/pull/12.patch","issue_url":"https://api.github.com/repos/zetok/tox/issues/12","number":12,"state":"open","locked":false,"title":"fix(TES): properly error out `pass_decrypt()`","user":{"login":"zetok","id":3148759,"avatar_url":"https://avatars.githubusercontent.com/u/3148759?v=3","gravatar_id":"","url":"https://api.github.com/users/zetok","html_url":"https://github.com/zetok","followers_url":"https://api.github.com/users/zetok/followers","following_url":"https://api.github.com/users/zetok/following{/other_user}","gists_url":"https://api.github.com/users/zetok/gists{/gist_id}","starred_url":"https://api.github.com/users/zetok/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zetok/subscriptions","organizations_url":"https://api.github.com/users/zetok/orgs","repos_url":"https://api.github.com/users/zetok/repos","events_url":"https://api.github.com/users/zetok/events{/privacy}","received_events_url":"https://api.github.com/users/zetok/received_events","type":"User","site_admin":false},"body":"cc @quininer ","created_at":"2016-06-18T09:55:55Z","updated_at":"2016-06-18T13:38:24Z","closed_at":null,"merged_at":null,"merge_commit_sha":"aacff9a6286125383befb60a4c7588bd88abd2e5","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/zetok/tox/pulls/12/commits","review_comments_url":"https://api.github.com/repos/zetok/tox/pulls/12/comments","review_comment_url":"https://api.github.com/repos/zetok/tox/pulls/comments{/number}","comments_url":"https://api.github.com/repos/zetok/tox/issues/12/comments","statuses_url":"https://api.github.com/repos/zetok/tox/statuses/65febe6d7d569fa139ee79b443844a1d56cc9b51","head":{"label":"zetok:pass","ref":"pass","sha":"65febe6d7d569fa139ee79b443844a1d56cc9b51","user":{"login":"zetok","id":3148759,"avatar_url":"https://avatars.githubusercontent.com/u/3148759?v=3","gravatar_id":"","url":"https://api.github.com/users/zetok","html_url":"https://github.com/zetok","followers_url":"https://api.github.com/users/zetok/followers","following_url":"https://api.github.com/users/zetok/following{/other_user}","gists_url":"https://api.github.com/users/zetok/gists{/gist_id}","starred_url":"https://api.github.com/users/zetok/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zetok/subscriptions","organizations_url":"https://api.github.com/users/zetok/orgs","repos_url":"https://api.github.com/users/zetok/repos","events_url":"https://api.github.com/users/zetok/events{/privacy}","received_events_url":"https://api.github.com/users/zetok/received_events","type":"User","site_admin":false},"repo":{"id":51173610,"name":"tox","full_name":"zetok/tox","owner":{"login":"zetok","id":3148759,"avatar_url":"https://avatars.githubusercontent.com/u/3148759?v=3","gravatar_id":"","url":"https://api.github.com/users/zetok","html_url":"https://github.com/zetok","followers_url":"https://api.github.com/users/zetok/followers","following_url":"https://api.github.com/users/zetok/following{/other_user}","gists_url":"https://api.github.com/users/zetok/gists{/gist_id}","starred_url":"https://api.github.com/users/zetok/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zetok/subscriptions","organizations_url":"https://api.github.com/users/zetok/orgs","repos_url":"https://api.github.com/users/zetok/repos","events_url":"https://api.github.com/users/zetok/events{/privacy}","received_events_url":"https://api.github.com/users/zetok/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/zetok/tox","description":"toxcore implementation in Rust.","fork":false,"url":"https://api.github.com/repos/zetok/tox","forks_url":"https://api.github.com/repos/zetok/tox/forks","keys_url":"https://api.github.com/repos/zetok/tox/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zetok/tox/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zetok/tox/teams","hooks_url":"https://api.github.com/repos/zetok/tox/hooks","issue_events_url":"https://api.github.com/repos/zetok/tox/issues/events{/number}","events_url":"https://api.github.com/repos/zetok/tox/events","assignees_url":"https://api.github.com/repos/zetok/tox/assignees{/user}","branches_url":"https://api.github.com/repos/zetok/tox/branches{/branch}","tags_url":"https://api.github.com/repos/zetok/tox/tags","blobs_url":"https://api.github.com/repos/zetok/tox/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zetok/tox/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zetok/tox/git/refs{/sha}","trees_url":"https://api.github.com/repos/zetok/tox/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zetok/tox/statuses/{sha}","languages_url":"https://api.github.com/repos/zetok/tox/languages","stargazers_url":"https://api.github.com/repos/zetok/tox/stargazers","contributors_url":"https://api.github.com/repos/zetok/tox/contributors","subscribers_url":"https://api.github.com/repos/zetok/tox/subscribers","subscription_url":"https://api.github.com/repos/zetok/tox/subscription","commits_url":"https://api.github.com/repos/zetok/tox/commits{/sha}","git_commits_url":"https://api.github.com/repos/zetok/tox/git/commits{/sha}","comments_url":"https://api.github.com/repos/zetok/tox/comments{/number}","issue_comment_url":"https://api.github.com/repos/zetok/tox/issues/comments{/number}","contents_url":"https://api.github.com/repos/zetok/tox/contents/{+path}","compare_url":"https://api.github.com/repos/zetok/tox/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zetok/tox/merges","archive_url":"https://api.github.com/repos/zetok/tox/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zetok/tox/downloads","issues_url":"https://api.github.com/repos/zetok/tox/issues{/number}","pulls_url":"https://api.github.com/repos/zetok/tox/pulls{/number}","milestones_url":"https://api.github.com/repos/zetok/tox/milestones{/number}","notifications_url":"https://api.github.com/repos/zetok/tox/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zetok/tox/labels{/name}","releases_url":"https://api.github.com/repos/zetok/tox/releases{/id}","deployments_url":"https://api.github.com/repos/zetok/tox/deployments","created_at":"2016-02-05T20:58:47Z","updated_at":"2016-06-16T21:22:27Z","pushed_at":"2016-06-18T09:55:56Z","git_url":"git://github.com/zetok/tox.git","ssh_url":"git@github.com:zetok/tox.git","clone_url":"https://github.com/zetok/tox.git","svn_url":"https://github.com/zetok/tox","homepage":"https://zetok.github.io/tox","size":1942,"stargazers_count":28,"watchers_count":28,"language":"Rust","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":4,"mirror_url":null,"open_issues_count":3,"forks":4,"open_issues":3,"watchers":28,"default_branch":"master"}},"base":{"label":"zetok:master","ref":"master","sha":"9b134c7031bebdd2ce959c04b154dda4a3d28698","user":{"login":"zetok","id":3148759,"avatar_url":"https://avatars.githubusercontent.com/u/3148759?v=3","gravatar_id":"","url":"https://api.github.com/users/zetok","html_url":"https://github.com/zetok","followers_url":"https://api.github.com/users/zetok/followers","following_url":"https://api.github.com/users/zetok/following{/other_user}","gists_url":"https://api.github.com/users/zetok/gists{/gist_id}","starred_url":"https://api.github.com/users/zetok/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zetok/subscriptions","organizations_url":"https://api.github.com/users/zetok/orgs","repos_url":"https://api.github.com/users/zetok/repos","events_url":"https://api.github.com/users/zetok/events{/privacy}","received_events_url":"https://api.github.com/users/zetok/received_events","type":"User","site_admin":false},"repo":{"id":51173610,"name":"tox","full_name":"zetok/tox","owner":{"login":"zetok","id":3148759,"avatar_url":"https://avatars.githubusercontent.com/u/3148759?v=3","gravatar_id":"","url":"https://api.github.com/users/zetok","html_url":"https://github.com/zetok","followers_url":"https://api.github.com/users/zetok/followers","following_url":"https://api.github.com/users/zetok/following{/other_user}","gists_url":"https://api.github.com/users/zetok/gists{/gist_id}","starred_url":"https://api.github.com/users/zetok/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zetok/subscriptions","organizations_url":"https://api.github.com/users/zetok/orgs","repos_url":"https://api.github.com/users/zetok/repos","events_url":"https://api.github.com/users/zetok/events{/privacy}","received_events_url":"https://api.github.com/users/zetok/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/zetok/tox","description":"toxcore implementation in Rust.","fork":false,"url":"https://api.github.com/repos/zetok/tox","forks_url":"https://api.github.com/repos/zetok/tox/forks","keys_url":"https://api.github.com/repos/zetok/tox/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zetok/tox/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zetok/tox/teams","hooks_url":"https://api.github.com/repos/zetok/tox/hooks","issue_events_url":"https://api.github.com/repos/zetok/tox/issues/events{/number}","events_url":"https://api.github.com/repos/zetok/tox/events","assignees_url":"https://api.github.com/repos/zetok/tox/assignees{/user}","branches_url":"https://api.github.com/repos/zetok/tox/branches{/branch}","tags_url":"https://api.github.com/repos/zetok/tox/tags","blobs_url":"https://api.github.com/repos/zetok/tox/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zetok/tox/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zetok/tox/git/refs{/sha}","trees_url":"https://api.github.com/repos/zetok/tox/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zetok/tox/statuses/{sha}","languages_url":"https://api.github.com/repos/zetok/tox/languages","stargazers_url":"https://api.github.com/repos/zetok/tox/stargazers","contributors_url":"https://api.github.com/repos/zetok/tox/contributors","subscribers_url":"https://api.github.com/repos/zetok/tox/subscribers","subscription_url":"https://api.github.com/repos/zetok/tox/subscription","commits_url":"https://api.github.com/repos/zetok/tox/commits{/sha}","git_commits_url":"https://api.github.com/repos/zetok/tox/git/commits{/sha}","comments_url":"https://api.github.com/repos/zetok/tox/comments{/number}","issue_comment_url":"https://api.github.com/repos/zetok/tox/issues/comments{/number}","contents_url":"https://api.github.com/repos/zetok/tox/contents/{+path}","compare_url":"https://api.github.com/repos/zetok/tox/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zetok/tox/merges","archive_url":"https://api.github.com/repos/zetok/tox/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zetok/tox/downloads","issues_url":"https://api.github.com/repos/zetok/tox/issues{/number}","pulls_url":"https://api.github.com/repos/zetok/tox/pulls{/number}","milestones_url":"https://api.github.com/repos/zetok/tox/milestones{/number}","notifications_url":"https://api.github.com/repos/zetok/tox/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zetok/tox/labels{/name}","releases_url":"https://api.github.com/repos/zetok/tox/releases{/id}","deployments_url":"https://api.github.com/repos/zetok/tox/deployments","created_at":"2016-02-05T20:58:47Z","updated_at":"2016-06-16T21:22:27Z","pushed_at":"2016-06-18T09:55:56Z","git_url":"git://github.com/zetok/tox.git","ssh_url":"git@github.com:zetok/tox.git","clone_url":"https://github.com/zetok/tox.git","svn_url":"https://github.com/zetok/tox","homepage":"https://zetok.github.io/tox","size":1942,"stargazers_count":28,"watchers_count":28,"language":"Rust","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":4,"mirror_url":null,"open_issues_count":3,"forks":4,"open_issues":3,"watchers":28,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/zetok/tox/pulls/12"},"html":{"href":"https://github.com/zetok/tox/pull/12"},"issue":{"href":"https://api.github.com/repos/zetok/tox/issues/12"},"comments":{"href":"https://api.github.com/repos/zetok/tox/issues/12/comments"},"review_comments":{"href":"https://api.github.com/repos/zetok/tox/pulls/12/comments"},"review_comment":{"href":"https://api.github.com/repos/zetok/tox/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/zetok/tox/pulls/12/commits"},"statuses":{"href":"https://api.github.com/repos/zetok/tox/statuses/65febe6d7d569fa139ee79b443844a1d56cc9b51"}}}}
{"actor":{"display_login":"quininer"}}