{"action":"created","comment":{"url":"https://api.github.com/repos/square/okio/pulls/comments/82497441","pull_request_review_id":3403932,"id":82497441,"diff_hunk":"@@ -1538,16 +1541,46 @@ public ByteString sha256() {\n   private ByteString digest(String algorithm) {\n     try {\n       MessageDigest messageDigest = MessageDigest.getInstance(algorithm);\n-      messageDigest.update(head.data, head.pos, head.limit - head.pos);\n-      for (Segment s = head.next; s != head; s = s.next) {\n-        messageDigest.update(s.data, s.pos, s.limit - s.pos);\n+      if (head != null) {\n+        messageDigest.update(head.data, head.pos, head.limit - head.pos);\n+        for (Segment s = head.next; s != head; s = s.next) {\n+          messageDigest.update(s.data, s.pos, s.limit - s.pos);\n+        }\n       }\n       return ByteString.of(messageDigest.digest());\n     } catch (NoSuchAlgorithmException e) {\n       throw new AssertionError();\n     }\n   }\n \n+  /** Returns the 160-bit SHA-1 HMAC of this buffer. */\n+  public ByteString hmacSha1(ByteString key) {\n+    return hmac(\"HmacSHA1\", key);\n+  }\n+\n+  /** Returns the 256-bit SHA-256 HMAC of this buffer. */\n+  public ByteString hmacSha256(ByteString key) {\n+    return hmac(\"HmacSHA256\", key);\n+  }\n+\n+  private ByteString hmac(String algorithm, ByteString key) {","path":"okio/src/main/java/okio/Buffer.java","position":44,"original_position":44,"commit_id":"64a97741ff77319f0ef00f83d8d2837a0435c002","original_commit_id":"64a97741ff77319f0ef00f83d8d2837a0435c002","user":{"login":"cketti","id":218061,"avatar_url":"https://avatars.githubusercontent.com/u/218061?v=3","gravatar_id":"","url":"https://api.github.com/users/cketti","html_url":"https://github.com/cketti","followers_url":"https://api.github.com/users/cketti/followers","following_url":"https://api.github.com/users/cketti/following{/other_user}","gists_url":"https://api.github.com/users/cketti/gists{/gist_id}","starred_url":"https://api.github.com/users/cketti/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cketti/subscriptions","organizations_url":"https://api.github.com/users/cketti/orgs","repos_url":"https://api.github.com/users/cketti/repos","events_url":"https://api.github.com/users/cketti/events{/privacy}","received_events_url":"https://api.github.com/users/cketti/received_events","type":"User","site_admin":false},"body":"Right. I wasn't sure whether explicit checks were omitted intentionally. It's not without precedent in the codebase. But I had the impression explicit checks are the norm.\r\nIs there a code style document where preferences for things like this are spelled out?","created_at":"2016-10-08T07:03:29Z","updated_at":"2016-10-08T07:03:29Z","html_url":"https://github.com/square/okio/pull/266#discussion_r82497441","pull_request_url":"https://api.github.com/repos/square/okio/pulls/266","_links":{"self":{"href":"https://api.github.com/repos/square/okio/pulls/comments/82497441"},"html":{"href":"https://github.com/square/okio/pull/266#discussion_r82497441"},"pull_request":{"href":"https://api.github.com/repos/square/okio/pulls/266"}}},"pull_request":{"url":"https://api.github.com/repos/square/okio/pulls/266","id":88520243,"html_url":"https://github.com/square/okio/pull/266","diff_url":"https://github.com/square/okio/pull/266.diff","patch_url":"https://github.com/square/okio/pull/266.patch","issue_url":"https://api.github.com/repos/square/okio/issues/266","number":266,"state":"open","locked":false,"title":"Implement HMAC SHA-1 and HMAC-SHA-256 throughout Okio.","user":{"login":"swankjesse","id":133019,"avatar_url":"https://avatars.githubusercontent.com/u/133019?v=3","gravatar_id":"","url":"https://api.github.com/users/swankjesse","html_url":"https://github.com/swankjesse","followers_url":"https://api.github.com/users/swankjesse/followers","following_url":"https://api.github.com/users/swankjesse/following{/other_user}","gists_url":"https://api.github.com/users/swankjesse/gists{/gist_id}","starred_url":"https://api.github.com/users/swankjesse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/swankjesse/subscriptions","organizations_url":"https://api.github.com/users/swankjesse/orgs","repos_url":"https://api.github.com/users/swankjesse/repos","events_url":"https://api.github.com/users/swankjesse/events{/privacy}","received_events_url":"https://api.github.com/users/swankjesse/received_events","type":"User","site_admin":false},"body":"This adds APIs to ByteString, Buffer, HashingSource and HashingSink.\r\n\r\nI've forgone polymporphism in HashingSource and HashingSink because it\r\nadds more code than it saves. I can be convinced here.\r\n\r\nCloses: https://github.com/square/okio/issues/254","created_at":"2016-10-07T22:56:16Z","updated_at":"2016-10-08T07:03:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"af1e9e3ee4a725ae3a176f7802b8b93b0e42bfae","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/square/okio/pulls/266/commits","review_comments_url":"https://api.github.com/repos/square/okio/pulls/266/comments","review_comment_url":"https://api.github.com/repos/square/okio/pulls/comments{/number}","comments_url":"https://api.github.com/repos/square/okio/issues/266/comments","statuses_url":"https://api.github.com/repos/square/okio/statuses/64a97741ff77319f0ef00f83d8d2837a0435c002","head":{"label":"square:jwilson.1007.hmac","ref":"jwilson.1007.hmac","sha":"64a97741ff77319f0ef00f83d8d2837a0435c002","user":{"login":"square","id":82592,"avatar_url":"https://avatars.githubusercontent.com/u/82592?v=3","gravatar_id":"","url":"https://api.github.com/users/square","html_url":"https://github.com/square","followers_url":"https://api.github.com/users/square/followers","following_url":"https://api.github.com/users/square/following{/other_user}","gists_url":"https://api.github.com/users/square/gists{/gist_id}","starred_url":"https://api.github.com/users/square/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/square/subscriptions","organizations_url":"https://api.github.com/users/square/orgs","repos_url":"https://api.github.com/users/square/repos","events_url":"https://api.github.com/users/square/events{/privacy}","received_events_url":"https://api.github.com/users/square/received_events","type":"Organization","site_admin":false},"repo":{"id":17812502,"name":"okio","full_name":"square/okio","owner":{"login":"square","id":82592,"avatar_url":"https://avatars.githubusercontent.com/u/82592?v=3","gravatar_id":"","url":"https://api.github.com/users/square","html_url":"https://github.com/square","followers_url":"https://api.github.com/users/square/followers","following_url":"https://api.github.com/users/square/following{/other_user}","gists_url":"https://api.github.com/users/square/gists{/gist_id}","starred_url":"https://api.github.com/users/square/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/square/subscriptions","organizations_url":"https://api.github.com/users/square/orgs","repos_url":"https://api.github.com/users/square/repos","events_url":"https://api.github.com/users/square/events{/privacy}","received_events_url":"https://api.github.com/users/square/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/square/okio","description":"A modern I/O API for Java","fork":false,"url":"https://api.github.com/repos/square/okio","forks_url":"https://api.github.com/repos/square/okio/forks","keys_url":"https://api.github.com/repos/square/okio/keys{/key_id}","collaborators_url":"https://api.github.com/repos/square/okio/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/square/okio/teams","hooks_url":"https://api.github.com/repos/square/okio/hooks","issue_events_url":"https://api.github.com/repos/square/okio/issues/events{/number}","events_url":"https://api.github.com/repos/square/okio/events","assignees_url":"https://api.github.com/repos/square/okio/assignees{/user}","branches_url":"https://api.github.com/repos/square/okio/branches{/branch}","tags_url":"https://api.github.com/repos/square/okio/tags","blobs_url":"https://api.github.com/repos/square/okio/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/square/okio/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/square/okio/git/refs{/sha}","trees_url":"https://api.github.com/repos/square/okio/git/trees{/sha}","statuses_url":"https://api.github.com/repos/square/okio/statuses/{sha}","languages_url":"https://api.github.com/repos/square/okio/languages","stargazers_url":"https://api.github.com/repos/square/okio/stargazers","contributors_url":"https://api.github.com/repos/square/okio/contributors","subscribers_url":"https://api.github.com/repos/square/okio/subscribers","subscription_url":"https://api.github.com/repos/square/okio/subscription","commits_url":"https://api.github.com/repos/square/okio/commits{/sha}","git_commits_url":"https://api.github.com/repos/square/okio/git/commits{/sha}","comments_url":"https://api.github.com/repos/square/okio/comments{/number}","issue_comment_url":"https://api.github.com/repos/square/okio/issues/comments{/number}","contents_url":"https://api.github.com/repos/square/okio/contents/{+path}","compare_url":"https://api.github.com/repos/square/okio/compare/{base}...{head}","merges_url":"https://api.github.com/repos/square/okio/merges","archive_url":"https://api.github.com/repos/square/okio/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/square/okio/downloads","issues_url":"https://api.github.com/repos/square/okio/issues{/number}","pulls_url":"https://api.github.com/repos/square/okio/pulls{/number}","milestones_url":"https://api.github.com/repos/square/okio/milestones{/number}","notifications_url":"https://api.github.com/repos/square/okio/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/square/okio/labels{/name}","releases_url":"https://api.github.com/repos/square/okio/releases{/id}","deployments_url":"https://api.github.com/repos/square/okio/deployments","created_at":"2014-03-17T00:02:59Z","updated_at":"2016-10-07T16:59:35Z","pushed_at":"2016-10-07T22:56:16Z","git_url":"git://github.com/square/okio.git","ssh_url":"git@github.com:square/okio.git","clone_url":"https://github.com/square/okio.git","svn_url":"https://github.com/square/okio","homepage":"http://square.github.io/okio/1.x/okio","size":1848,"stargazers_count":2865,"watchers_count":2865,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":487,"mirror_url":null,"open_issues_count":20,"forks":487,"open_issues":20,"watchers":2865,"default_branch":"master"}},"base":{"label":"square:master","ref":"master","sha":"20e34113a51164904fe63402c726ef3b04fdf038","user":{"login":"square","id":82592,"avatar_url":"https://avatars.githubusercontent.com/u/82592?v=3","gravatar_id":"","url":"https://api.github.com/users/square","html_url":"https://github.com/square","followers_url":"https://api.github.com/users/square/followers","following_url":"https://api.github.com/users/square/following{/other_user}","gists_url":"https://api.github.com/users/square/gists{/gist_id}","starred_url":"https://api.github.com/users/square/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/square/subscriptions","organizations_url":"https://api.github.com/users/square/orgs","repos_url":"https://api.github.com/users/square/repos","events_url":"https://api.github.com/users/square/events{/privacy}","received_events_url":"https://api.github.com/users/square/received_events","type":"Organization","site_admin":false},"repo":{"id":17812502,"name":"okio","full_name":"square/okio","owner":{"login":"square","id":82592,"avatar_url":"https://avatars.githubusercontent.com/u/82592?v=3","gravatar_id":"","url":"https://api.github.com/users/square","html_url":"https://github.com/square","followers_url":"https://api.github.com/users/square/followers","following_url":"https://api.github.com/users/square/following{/other_user}","gists_url":"https://api.github.com/users/square/gists{/gist_id}","starred_url":"https://api.github.com/users/square/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/square/subscriptions","organizations_url":"https://api.github.com/users/square/orgs","repos_url":"https://api.github.com/users/square/repos","events_url":"https://api.github.com/users/square/events{/privacy}","received_events_url":"https://api.github.com/users/square/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/square/okio","description":"A modern I/O API for Java","fork":false,"url":"https://api.github.com/repos/square/okio","forks_url":"https://api.github.com/repos/square/okio/forks","keys_url":"https://api.github.com/repos/square/okio/keys{/key_id}","collaborators_url":"https://api.github.com/repos/square/okio/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/square/okio/teams","hooks_url":"https://api.github.com/repos/square/okio/hooks","issue_events_url":"https://api.github.com/repos/square/okio/issues/events{/number}","events_url":"https://api.github.com/repos/square/okio/events","assignees_url":"https://api.github.com/repos/square/okio/assignees{/user}","branches_url":"https://api.github.com/repos/square/okio/branches{/branch}","tags_url":"https://api.github.com/repos/square/okio/tags","blobs_url":"https://api.github.com/repos/square/okio/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/square/okio/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/square/okio/git/refs{/sha}","trees_url":"https://api.github.com/repos/square/okio/git/trees{/sha}","statuses_url":"https://api.github.com/repos/square/okio/statuses/{sha}","languages_url":"https://api.github.com/repos/square/okio/languages","stargazers_url":"https://api.github.com/repos/square/okio/stargazers","contributors_url":"https://api.github.com/repos/square/okio/contributors","subscribers_url":"https://api.github.com/repos/square/okio/subscribers","subscription_url":"https://api.github.com/repos/square/okio/subscription","commits_url":"https://api.github.com/repos/square/okio/commits{/sha}","git_commits_url":"https://api.github.com/repos/square/okio/git/commits{/sha}","comments_url":"https://api.github.com/repos/square/okio/comments{/number}","issue_comment_url":"https://api.github.com/repos/square/okio/issues/comments{/number}","contents_url":"https://api.github.com/repos/square/okio/contents/{+path}","compare_url":"https://api.github.com/repos/square/okio/compare/{base}...{head}","merges_url":"https://api.github.com/repos/square/okio/merges","archive_url":"https://api.github.com/repos/square/okio/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/square/okio/downloads","issues_url":"https://api.github.com/repos/square/okio/issues{/number}","pulls_url":"https://api.github.com/repos/square/okio/pulls{/number}","milestones_url":"https://api.github.com/repos/square/okio/milestones{/number}","notifications_url":"https://api.github.com/repos/square/okio/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/square/okio/labels{/name}","releases_url":"https://api.github.com/repos/square/okio/releases{/id}","deployments_url":"https://api.github.com/repos/square/okio/deployments","created_at":"2014-03-17T00:02:59Z","updated_at":"2016-10-07T16:59:35Z","pushed_at":"2016-10-07T22:56:16Z","git_url":"git://github.com/square/okio.git","ssh_url":"git@github.com:square/okio.git","clone_url":"https://github.com/square/okio.git","svn_url":"https://github.com/square/okio","homepage":"http://square.github.io/okio/1.x/okio","size":1848,"stargazers_count":2865,"watchers_count":2865,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":487,"mirror_url":null,"open_issues_count":20,"forks":487,"open_issues":20,"watchers":2865,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/square/okio/pulls/266"},"html":{"href":"https://github.com/square/okio/pull/266"},"issue":{"href":"https://api.github.com/repos/square/okio/issues/266"},"comments":{"href":"https://api.github.com/repos/square/okio/issues/266/comments"},"review_comments":{"href":"https://api.github.com/repos/square/okio/pulls/266/comments"},"review_comment":{"href":"https://api.github.com/repos/square/okio/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/square/okio/pulls/266/commits"},"statuses":{"href":"https://api.github.com/repos/square/okio/statuses/64a97741ff77319f0ef00f83d8d2837a0435c002"}}}}
{"actor":{"display_login":"cketti"}}