{"action":"created","comment":{"url":"https://api.github.com/repos/mirage/irmin/pulls/comments/36720909","id":36720909,"diff_hunk":"@@ -0,0 +1,113 @@\n+(*\n+ * Copyright (c) 2013-2015 Thomas Gazagnaire <thomas@gazagnaire.org>\n+ * Copyright (c) 2015 Mounir Nasr Allah <mounir@nasrallah.co>\n+ *\n+ * Permission to use, copy, modify, and distribute this software for any\n+ * purpose with or without fee is hereby granted, provided that the above\n+ * copyright notice and this permission notice appear in all copies.\n+ *\n+ * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES\n+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF\n+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR\n+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\n+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN\n+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF\n+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n+ *)\n+\n+(**\n+\n+  Krypto : Irmin Crypto Backend\n+  The kryptonite for protect your data of nasties\n+\n+  TODO :\n+  Padding into blobs, and cut blobs on a defined size block -> We don't want to guess the size of content\n+\n+*)\n+\n+open Lwt\n+open Irmin\n+\n+\n+module Log = Log.Make(struct let section = \"KRYPO\" end)\n+\n+\t\t     \n+module type CIPHER = Irmin_krypto_cipher.CIPHER\n+module Make_km = Irmin_krypto_km.Make\n+module Make_cipher = Irmin_krypto_cipher.Make_CTR\n+\n+\t\t\t\t\t    \n+module KRYPTO_AO (C: CIPHER) (S:AO_MAKER_RAW) (K:Irmin.Hash.S) (V:RAW) = struct\n+\n+    module AO = S(K)(V)\n+\n+    type key = AO.key\n+\n+    type value = AO.value\n+\n+    type t = AO.t\n+\n+    let hash_size = K.length\n+\n+    let compute_ctr v = Nocrypto.Hash.SHA1.digest v (* MUST TO BE PARAMETRABLE *)\n+\n+    let inject_ctr ~ctr blob =\n+      let len_blob = Cstruct.len blob in\n+      let res = Cstruct.create (hash_size + len_blob) in\n+      Cstruct.blit ctr 0 res 0 hash_size;\n+      Cstruct.blit blob 0 res hash_size len_blob;\n+      res\n+\n+    let extract_ctr blob =\n+      let res = Cstruct.create hash_size in\n+      Cstruct.blit blob 0 res 0 hash_size;\n+      res\n+\n+    let extract_value blob =\n+      let len_blob = Cstruct.len blob in\n+      let len = len_blob - hash_size in\n+      let res = Cstruct.create len in\n+      Cstruct.blit blob hash_size res 0 len;\n+      res\n+\n+    let create config task =\n+      AO.create config task\n+\n+    let task t =\n+      AO.task t\n+\n+\n+    let read t key =\n+      AO.read t key >>= function\n+      | None -> return_none\n+      | Some v ->\n+         let ctr = extract_ctr v in\n+         let value = extract_value v in\n+         return (Some (C.decrypt ~ctr value))\n+\n+    let read_exn t key =\n+      try\n+        AO.read_exn t key >>=\n+          function x ->\n+                   let ctr = extract_ctr x in\n+                   let value = extract_value x in\n+                   return (C.decrypt ~ctr value)\n+      with\n+      | Not_found -> fail Not_found\n+\n+    let mem t k =\n+      AO.mem t k\n+      \n+\t\t\t  \n+    let add t v =\n+      let ctr = compute_ctr v in\n+      let ctr2 = compute_ctr v in\n+      C.encrypt ~ctr v |> inject_ctr ~ctr:ctr2 |> AO.add t\n+\n+\n+    let iter _t (_fn : key -> value Lwt.t -> unit Lwt.t) =\n+      failwith \"NOT NEEDED\"","path":"lib/krypto/irmin_krypto.ml","position":109,"original_position":109,"commit_id":"acc62d8612d3d06b61ceacafe11ef4cb9498b10e","original_commit_id":"acc62d8612d3d06b61ceacafe11ef4cb9498b10e","user":{"login":"samoht","id":103693,"avatar_url":"https://avatars.githubusercontent.com/u/103693?v=3","gravatar_id":"","url":"https://api.github.com/users/samoht","html_url":"https://github.com/samoht","followers_url":"https://api.github.com/users/samoht/followers","following_url":"https://api.github.com/users/samoht/following{/other_user}","gists_url":"https://api.github.com/users/samoht/gists{/gist_id}","starred_url":"https://api.github.com/users/samoht/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samoht/subscriptions","organizations_url":"https://api.github.com/users/samoht/orgs","repos_url":"https://api.github.com/users/samoht/repos","events_url":"https://api.github.com/users/samoht/events{/privacy}","received_events_url":"https://api.github.com/users/samoht/received_events","type":"User","site_admin":false},"body":"The tests should exercice that code-path!","created_at":"2015-08-11T08:14:35Z","updated_at":"2015-08-11T08:14:35Z","html_url":"https://github.com/mirage/irmin/pull/213#discussion_r36720909","pull_request_url":"https://api.github.com/repos/mirage/irmin/pulls/213","_links":{"self":{"href":"https://api.github.com/repos/mirage/irmin/pulls/comments/36720909"},"html":{"href":"https://github.com/mirage/irmin/pull/213#discussion_r36720909"},"pull_request":{"href":"https://api.github.com/repos/mirage/irmin/pulls/213"}}},"pull_request":{"url":"https://api.github.com/repos/mirage/irmin/pulls/213","id":38891342,"html_url":"https://github.com/mirage/irmin/pull/213","diff_url":"https://github.com/mirage/irmin/pull/213.diff","patch_url":"https://github.com/mirage/irmin/pull/213.patch","issue_url":"https://api.github.com/repos/mirage/irmin/issues/213","number":213,"state":"open","locked":false,"title":"[do not merge] crypto backend","user":{"login":"samoht","id":103693,"avatar_url":"https://avatars.githubusercontent.com/u/103693?v=3","gravatar_id":"","url":"https://api.github.com/users/samoht","html_url":"https://github.com/samoht","followers_url":"https://api.github.com/users/samoht/followers","following_url":"https://api.github.com/users/samoht/following{/other_user}","gists_url":"https://api.github.com/users/samoht/gists{/gist_id}","starred_url":"https://api.github.com/users/samoht/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samoht/subscriptions","organizations_url":"https://api.github.com/users/samoht/orgs","repos_url":"https://api.github.com/users/samoht/repos","events_url":"https://api.github.com/users/samoht/events{/privacy}","received_events_url":"https://api.github.com/users/samoht/received_events","type":"User","site_admin":false},"body":"Just opening a PR to add comments more easily","created_at":"2015-06-30T15:33:11Z","updated_at":"2015-08-11T08:14:35Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ab92a0934cba9a0a53b1c0a95f2e01852a40dfcb","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mirage/irmin/pulls/213/commits","review_comments_url":"https://api.github.com/repos/mirage/irmin/pulls/213/comments","review_comment_url":"https://api.github.com/repos/mirage/irmin/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mirage/irmin/issues/213/comments","statuses_url":"https://api.github.com/repos/mirage/irmin/statuses/acc62d8612d3d06b61ceacafe11ef4cb9498b10e","head":{"label":"nasrallahmounir:master","ref":"master","sha":"acc62d8612d3d06b61ceacafe11ef4cb9498b10e","user":{"login":"nasrallahmounir","id":3886877,"avatar_url":"https://avatars.githubusercontent.com/u/3886877?v=3","gravatar_id":"","url":"https://api.github.com/users/nasrallahmounir","html_url":"https://github.com/nasrallahmounir","followers_url":"https://api.github.com/users/nasrallahmounir/followers","following_url":"https://api.github.com/users/nasrallahmounir/following{/other_user}","gists_url":"https://api.github.com/users/nasrallahmounir/gists{/gist_id}","starred_url":"https://api.github.com/users/nasrallahmounir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nasrallahmounir/subscriptions","organizations_url":"https://api.github.com/users/nasrallahmounir/orgs","repos_url":"https://api.github.com/users/nasrallahmounir/repos","events_url":"https://api.github.com/users/nasrallahmounir/events{/privacy}","received_events_url":"https://api.github.com/users/nasrallahmounir/received_events","type":"User","site_admin":false},"repo":{"id":31662220,"name":"irmin","full_name":"nasrallahmounir/irmin","owner":{"login":"nasrallahmounir","id":3886877,"avatar_url":"https://avatars.githubusercontent.com/u/3886877?v=3","gravatar_id":"","url":"https://api.github.com/users/nasrallahmounir","html_url":"https://github.com/nasrallahmounir","followers_url":"https://api.github.com/users/nasrallahmounir/followers","following_url":"https://api.github.com/users/nasrallahmounir/following{/other_user}","gists_url":"https://api.github.com/users/nasrallahmounir/gists{/gist_id}","starred_url":"https://api.github.com/users/nasrallahmounir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nasrallahmounir/subscriptions","organizations_url":"https://api.github.com/users/nasrallahmounir/orgs","repos_url":"https://api.github.com/users/nasrallahmounir/repos","events_url":"https://api.github.com/users/nasrallahmounir/events{/privacy}","received_events_url":"https://api.github.com/users/nasrallahmounir/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nasrallahmounir/irmin","description":"Irmin is a distributed database that follows the same design principles as Git","fork":true,"url":"https://api.github.com/repos/nasrallahmounir/irmin","forks_url":"https://api.github.com/repos/nasrallahmounir/irmin/forks","keys_url":"https://api.github.com/repos/nasrallahmounir/irmin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nasrallahmounir/irmin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nasrallahmounir/irmin/teams","hooks_url":"https://api.github.com/repos/nasrallahmounir/irmin/hooks","issue_events_url":"https://api.github.com/repos/nasrallahmounir/irmin/issues/events{/number}","events_url":"https://api.github.com/repos/nasrallahmounir/irmin/events","assignees_url":"https://api.github.com/repos/nasrallahmounir/irmin/assignees{/user}","branches_url":"https://api.github.com/repos/nasrallahmounir/irmin/branches{/branch}","tags_url":"https://api.github.com/repos/nasrallahmounir/irmin/tags","blobs_url":"https://api.github.com/repos/nasrallahmounir/irmin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nasrallahmounir/irmin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nasrallahmounir/irmin/git/refs{/sha}","trees_url":"https://api.github.com/repos/nasrallahmounir/irmin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nasrallahmounir/irmin/statuses/{sha}","languages_url":"https://api.github.com/repos/nasrallahmounir/irmin/languages","stargazers_url":"https://api.github.com/repos/nasrallahmounir/irmin/stargazers","contributors_url":"https://api.github.com/repos/nasrallahmounir/irmin/contributors","subscribers_url":"https://api.github.com/repos/nasrallahmounir/irmin/subscribers","subscription_url":"https://api.github.com/repos/nasrallahmounir/irmin/subscription","commits_url":"https://api.github.com/repos/nasrallahmounir/irmin/commits{/sha}","git_commits_url":"https://api.github.com/repos/nasrallahmounir/irmin/git/commits{/sha}","comments_url":"https://api.github.com/repos/nasrallahmounir/irmin/comments{/number}","issue_comment_url":"https://api.github.com/repos/nasrallahmounir/irmin/issues/comments{/number}","contents_url":"https://api.github.com/repos/nasrallahmounir/irmin/contents/{+path}","compare_url":"https://api.github.com/repos/nasrallahmounir/irmin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nasrallahmounir/irmin/merges","archive_url":"https://api.github.com/repos/nasrallahmounir/irmin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nasrallahmounir/irmin/downloads","issues_url":"https://api.github.com/repos/nasrallahmounir/irmin/issues{/number}","pulls_url":"https://api.github.com/repos/nasrallahmounir/irmin/pulls{/number}","milestones_url":"https://api.github.com/repos/nasrallahmounir/irmin/milestones{/number}","notifications_url":"https://api.github.com/repos/nasrallahmounir/irmin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nasrallahmounir/irmin/labels{/name}","releases_url":"https://api.github.com/repos/nasrallahmounir/irmin/releases{/id}","created_at":"2015-03-04T14:51:24Z","updated_at":"2015-03-04T14:51:25Z","pushed_at":"2015-08-10T18:36:40Z","git_url":"git://github.com/nasrallahmounir/irmin.git","ssh_url":"git@github.com:nasrallahmounir/irmin.git","clone_url":"https://github.com/nasrallahmounir/irmin.git","svn_url":"https://github.com/nasrallahmounir/irmin","homepage":"","size":5985,"stargazers_count":0,"watchers_count":0,"language":"OCaml","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"mirage:master","ref":"master","sha":"427173b530eb67c9eb2cee112404e2f9182d72d9","user":{"login":"mirage","id":131943,"avatar_url":"https://avatars.githubusercontent.com/u/131943?v=3","gravatar_id":"","url":"https://api.github.com/users/mirage","html_url":"https://github.com/mirage","followers_url":"https://api.github.com/users/mirage/followers","following_url":"https://api.github.com/users/mirage/following{/other_user}","gists_url":"https://api.github.com/users/mirage/gists{/gist_id}","starred_url":"https://api.github.com/users/mirage/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mirage/subscriptions","organizations_url":"https://api.github.com/users/mirage/orgs","repos_url":"https://api.github.com/users/mirage/repos","events_url":"https://api.github.com/users/mirage/events{/privacy}","received_events_url":"https://api.github.com/users/mirage/received_events","type":"Organization","site_admin":false},"repo":{"id":9595928,"name":"irmin","full_name":"mirage/irmin","owner":{"login":"mirage","id":131943,"avatar_url":"https://avatars.githubusercontent.com/u/131943?v=3","gravatar_id":"","url":"https://api.github.com/users/mirage","html_url":"https://github.com/mirage","followers_url":"https://api.github.com/users/mirage/followers","following_url":"https://api.github.com/users/mirage/following{/other_user}","gists_url":"https://api.github.com/users/mirage/gists{/gist_id}","starred_url":"https://api.github.com/users/mirage/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mirage/subscriptions","organizations_url":"https://api.github.com/users/mirage/orgs","repos_url":"https://api.github.com/users/mirage/repos","events_url":"https://api.github.com/users/mirage/events{/privacy}","received_events_url":"https://api.github.com/users/mirage/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mirage/irmin","description":"Irmin is a distributed database that follows the same design principles as Git","fork":false,"url":"https://api.github.com/repos/mirage/irmin","forks_url":"https://api.github.com/repos/mirage/irmin/forks","keys_url":"https://api.github.com/repos/mirage/irmin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mirage/irmin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mirage/irmin/teams","hooks_url":"https://api.github.com/repos/mirage/irmin/hooks","issue_events_url":"https://api.github.com/repos/mirage/irmin/issues/events{/number}","events_url":"https://api.github.com/repos/mirage/irmin/events","assignees_url":"https://api.github.com/repos/mirage/irmin/assignees{/user}","branches_url":"https://api.github.com/repos/mirage/irmin/branches{/branch}","tags_url":"https://api.github.com/repos/mirage/irmin/tags","blobs_url":"https://api.github.com/repos/mirage/irmin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mirage/irmin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mirage/irmin/git/refs{/sha}","trees_url":"https://api.github.com/repos/mirage/irmin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mirage/irmin/statuses/{sha}","languages_url":"https://api.github.com/repos/mirage/irmin/languages","stargazers_url":"https://api.github.com/repos/mirage/irmin/stargazers","contributors_url":"https://api.github.com/repos/mirage/irmin/contributors","subscribers_url":"https://api.github.com/repos/mirage/irmin/subscribers","subscription_url":"https://api.github.com/repos/mirage/irmin/subscription","commits_url":"https://api.github.com/repos/mirage/irmin/commits{/sha}","git_commits_url":"https://api.github.com/repos/mirage/irmin/git/commits{/sha}","comments_url":"https://api.github.com/repos/mirage/irmin/comments{/number}","issue_comment_url":"https://api.github.com/repos/mirage/irmin/issues/comments{/number}","contents_url":"https://api.github.com/repos/mirage/irmin/contents/{+path}","compare_url":"https://api.github.com/repos/mirage/irmin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mirage/irmin/merges","archive_url":"https://api.github.com/repos/mirage/irmin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mirage/irmin/downloads","issues_url":"https://api.github.com/repos/mirage/irmin/issues{/number}","pulls_url":"https://api.github.com/repos/mirage/irmin/pulls{/number}","milestones_url":"https://api.github.com/repos/mirage/irmin/milestones{/number}","notifications_url":"https://api.github.com/repos/mirage/irmin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mirage/irmin/labels{/name}","releases_url":"https://api.github.com/repos/mirage/irmin/releases{/id}","created_at":"2013-04-22T09:52:58Z","updated_at":"2015-08-10T14:54:23Z","pushed_at":"2015-08-10T19:50:40Z","git_url":"git://github.com/mirage/irmin.git","ssh_url":"git@github.com:mirage/irmin.git","clone_url":"https://github.com/mirage/irmin.git","svn_url":"https://github.com/mirage/irmin","homepage":"","size":7835,"stargazers_count":308,"watchers_count":308,"language":"OCaml","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":35,"mirror_url":null,"open_issues_count":53,"forks":35,"open_issues":53,"watchers":308,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mirage/irmin/pulls/213"},"html":{"href":"https://github.com/mirage/irmin/pull/213"},"issue":{"href":"https://api.github.com/repos/mirage/irmin/issues/213"},"comments":{"href":"https://api.github.com/repos/mirage/irmin/issues/213/comments"},"review_comments":{"href":"https://api.github.com/repos/mirage/irmin/pulls/213/comments"},"review_comment":{"href":"https://api.github.com/repos/mirage/irmin/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mirage/irmin/pulls/213/commits"},"statuses":{"href":"https://api.github.com/repos/mirage/irmin/statuses/acc62d8612d3d06b61ceacafe11ef4cb9498b10e"}}}}